xref: /openbsd-src/gnu/llvm/lldb/bindings/interface/SBTypeEnumMember.i (revision be691f3bb6417f04a68938fadbcaee2d5795e764)
1 //===-- SWIG Interface for SBTypeEnumMember ---------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 namespace lldb {
10 
11 %feature(
12     "docstring",
13     "Represents a member of an enum in lldb."
14 ) SBTypeEnumMember;
15 
16 class SBTypeEnumMember
17 {
18 public:
19     SBTypeEnumMember ();
20 
21     SBTypeEnumMember (const SBTypeEnumMember& rhs);
22 
23     ~SBTypeEnumMember();
24 
25     bool
26     IsValid() const;
27 
28     explicit operator bool() const;
29 
30     int64_t
31     GetValueAsSigned();
32 
33     uint64_t
34     GetValueAsUnsigned();
35 
36     const char *
37     GetName ();
38 
39     lldb::SBType
40     GetType ();
41 
42     bool
43     GetDescription (lldb::SBStream &description,
44                     lldb::DescriptionLevel description_level);
45 
46     STRING_EXTENSION_LEVEL(SBTypeEnumMember, lldb::eDescriptionLevelBrief)
47 #ifdef SWIGPYTHON
48     %pythoncode %{
49         name = property(GetName, None, doc='''A read only property that returns the name for this enum member as a string.''')
50         type = property(GetType, None, doc='''A read only property that returns an lldb object that represents the type (lldb.SBType) for this enum member.''')
51         signed = property(GetValueAsSigned, None, doc='''A read only property that returns the value of this enum member as a signed integer.''')
52         unsigned = property(GetValueAsUnsigned, None, doc='''A read only property that returns the value of this enum member as a unsigned integer.''')
53     %}
54 #endif
55 
56 protected:
57     friend class SBType;
58     friend class SBTypeEnumMemberList;
59 
60     void
61     reset (lldb_private::TypeEnumMemberImpl *);
62 
63     lldb_private::TypeEnumMemberImpl &
64     ref ();
65 
66     const lldb_private::TypeEnumMemberImpl &
67     ref () const;
68 
69     lldb::TypeEnumMemberImplSP m_opaque_sp;
70 
71     SBTypeEnumMember (const lldb::TypeEnumMemberImplSP &);
72 };
73 
74 %feature("docstring",
75 "Represents a list of SBTypeEnumMembers.
76 
77 SBTypeEnumMemberList supports SBTypeEnumMember iteration.
78 It also supports [] access either by index, or by enum
79 element name by doing: ::
80 
81   myType = target.FindFirstType('MyEnumWithElementA')
82   members = myType.GetEnumMembers()
83   first_elem = members[0]
84   elem_A = members['A']
85 
86 ") SBTypeEnumMemberList;
87 
88 class SBTypeEnumMemberList
89 {
90 public:
91     SBTypeEnumMemberList();
92 
93     SBTypeEnumMemberList(const SBTypeEnumMemberList& rhs);
94 
95     ~SBTypeEnumMemberList();
96 
97     bool
98     IsValid();
99 
100     explicit operator bool() const;
101 
102     void
103     Append (SBTypeEnumMember entry);
104 
105     SBTypeEnumMember
106     GetTypeEnumMemberAtIndex (uint32_t index);
107 
108     uint32_t
109     GetSize();
110 
111 #ifdef SWIGPYTHON
112     %pythoncode %{
113         def __iter__(self):
114             '''Iterate over all members in a lldb.SBTypeEnumMemberList object.'''
115             return lldb_iter(self, 'GetSize', 'GetTypeEnumMemberAtIndex')
116 
117         def __len__(self):
118             '''Return the number of members in a lldb.SBTypeEnumMemberList object.'''
119             return self.GetSize()
120 
121         def __getitem__(self, key):
122           num_elements = self.GetSize()
123           if type(key) is int:
124               if key < num_elements:
125                   return self.GetTypeEnumMemberAtIndex(key)
126           elif type(key) is str:
127               for idx in range(num_elements):
128                   item = self.GetTypeEnumMemberAtIndex(idx)
129                   if item.name == key:
130                       return item
131           return None
132     %}
133 #endif
134 
135 private:
136     std::unique_ptr<lldb_private::TypeEnumMemberListImpl> m_opaque_ap;
137 };
138 
139 } // namespace lldb
140