1 STRING_EXTENSION_LEVEL_OUTSIDE(SBTypeCategory, lldb::eDescriptionLevelBrief)
2 
3 %extend lldb::SBTypeCategory {
4 #ifdef SWIGPYTHON
5         %pythoncode %{
6             # operator== is a free function, which swig does not handle, so we inject
7             # our own equality operator here
8             def __eq__(self, other):
9                 return not self.__ne__(other)
10 
11 
12             class formatters_access_class(object):
13                 '''A helper object that will lazily hand out formatters for a specific category.'''
14                 def __init__(self, sbcategory, get_count_function, get_at_index_function, get_by_name_function):
15                     self.sbcategory = sbcategory
16                     self.get_count_function = get_count_function
17                     self.get_at_index_function = get_at_index_function
18                     self.get_by_name_function = get_by_name_function
19                     self.regex_type = type(re.compile('.'))
20 
21 
22                 def __len__(self):
23                     if self.sbcategory and self.get_count_function:
24                         return int(self.get_count_function(self.sbcategory))
25                     return 0
26 
27                 def __getitem__(self, key):
28                     num_items = len(self)
29                     if type(key) is int:
30                         if -num_items <= key < num_items:
31                             key %= num_items
32                             return self.get_at_index_function(self.sbcategory,key)
33                     elif type(key) is str:
34                         return self.get_by_name_function(self.sbcategory,SBTypeNameSpecifier(key))
35                     elif isinstance(key,self.regex_type):
36                         return self.get_by_name_function(self.sbcategory,SBTypeNameSpecifier(key.pattern,True))
37                     else:
38                         print("error: unsupported item type: %s" % type(key))
39                     return None
40 
41             def get_formats_access_object(self):
42                 '''An accessor function that returns an accessor object which allows lazy format access from a lldb.SBTypeCategory object.'''
43                 return self.formatters_access_class (self,self.__class__.GetNumFormats,self.__class__.GetFormatAtIndex,self.__class__.GetFormatForType)
44 
45             def get_formats_array(self):
46                 '''An accessor function that returns a list() that contains all formats in a lldb.SBCategory object.'''
47                 formats = []
48                 for idx in range(self.GetNumFormats()):
49                     formats.append(self.GetFormatAtIndex(idx))
50                 return formats
51 
52             def get_summaries_access_object(self):
53                 '''An accessor function that returns an accessor object which allows lazy summary access from a lldb.SBTypeCategory object.'''
54                 return self.formatters_access_class (self,self.__class__.GetNumSummaries,self.__class__.GetSummaryAtIndex,self.__class__.GetSummaryForType)
55 
56             def get_summaries_array(self):
57                 '''An accessor function that returns a list() that contains all summaries in a lldb.SBCategory object.'''
58                 summaries = []
59                 for idx in range(self.GetNumSummaries()):
60                     summaries.append(self.GetSummaryAtIndex(idx))
61                 return summaries
62 
63             def get_synthetics_access_object(self):
64                 '''An accessor function that returns an accessor object which allows lazy synthetic children provider access from a lldb.SBTypeCategory object.'''
65                 return self.formatters_access_class (self,self.__class__.GetNumSynthetics,self.__class__.GetSyntheticAtIndex,self.__class__.GetSyntheticForType)
66 
67             def get_synthetics_array(self):
68                 '''An accessor function that returns a list() that contains all synthetic children providers in a lldb.SBCategory object.'''
69                 synthetics = []
70                 for idx in range(self.GetNumSynthetics()):
71                     synthetics.append(self.GetSyntheticAtIndex(idx))
72                 return synthetics
73 
74             def get_filters_access_object(self):
75                 '''An accessor function that returns an accessor object which allows lazy filter access from a lldb.SBTypeCategory object.'''
76                 return self.formatters_access_class (self,self.__class__.GetNumFilters,self.__class__.GetFilterAtIndex,self.__class__.GetFilterForType)
77 
78             def get_filters_array(self):
79                 '''An accessor function that returns a list() that contains all filters in a lldb.SBCategory object.'''
80                 filters = []
81                 for idx in range(self.GetNumFilters()):
82                     filters.append(self.GetFilterAtIndex(idx))
83                 return filters
84 
85             formats = property(get_formats_array, None, doc='''A read only property that returns a list() of lldb.SBTypeFormat objects contained in this category''')
86             format = property(get_formats_access_object, None, doc=r'''A read only property that returns an object that you can use to look for formats by index or type name.''')
87             summaries = property(get_summaries_array, None, doc='''A read only property that returns a list() of lldb.SBTypeSummary objects contained in this category''')
88             summary = property(get_summaries_access_object, None, doc=r'''A read only property that returns an object that you can use to look for summaries by index or type name or regular expression.''')
89             filters = property(get_filters_array, None, doc='''A read only property that returns a list() of lldb.SBTypeFilter objects contained in this category''')
90             filter = property(get_filters_access_object, None, doc=r'''A read only property that returns an object that you can use to look for filters by index or type name or regular expression.''')
91             synthetics = property(get_synthetics_array, None, doc='''A read only property that returns a list() of lldb.SBTypeSynthetic objects contained in this category''')
92             synthetic = property(get_synthetics_access_object, None, doc=r'''A read only property that returns an object that you can use to look for synthetic children provider by index or type name or regular expression.''')
93             num_formats = property(GetNumFormats, None)
94             num_summaries = property(GetNumSummaries, None)
95             num_filters = property(GetNumFilters, None)
96             num_synthetics = property(GetNumSynthetics, None)
97             name = property(GetName, None)
98             enabled = property(GetEnabled, SetEnabled)
99         %}
100 #endif
101 }
102