]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/TypeCategoryMap.h
Bring lld (release_39 branch, r279477) to contrib
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / DataFormatters / TypeCategoryMap.h
1 //===-- TypeCategoryMap.h ---------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef lldb_TypeCategoryMap_h_
11 #define lldb_TypeCategoryMap_h_
12
13 // C Includes
14 // C++ Includes
15 #include <functional>
16 #include <list>
17 #include <map>
18 #include <mutex>
19
20 // Other libraries and framework includes
21 // Project includes
22 #include "lldb/lldb-public.h"
23 #include "lldb/lldb-enumerations.h"
24
25 #include "lldb/DataFormatters/FormattersContainer.h"
26 #include "lldb/DataFormatters/TypeCategory.h"
27
28 namespace lldb_private {
29     class TypeCategoryMap
30     {
31     private:
32         typedef ConstString KeyType;
33         typedef TypeCategoryImpl ValueType;
34         typedef ValueType::SharedPointer ValueSP;
35         typedef std::list<lldb::TypeCategoryImplSP> ActiveCategoriesList;
36         typedef ActiveCategoriesList::iterator ActiveCategoriesIterator;
37         
38     public:
39         typedef std::map<KeyType, ValueSP> MapType;
40         typedef MapType::iterator MapIterator;
41         typedef std::function<bool(const ValueSP&)> ForEachCallback;
42         
43         typedef uint32_t Position;
44         
45         static const Position First = 0;
46         static const Position Default = 1;
47         static const Position Last = UINT32_MAX;
48         
49         TypeCategoryMap (IFormatChangeListener* lst);
50         
51         void
52         Add (KeyType name,
53              const ValueSP& entry);
54         
55         bool
56         Delete (KeyType name);
57         
58         bool
59         Enable (KeyType category_name,
60                 Position pos = Default);
61         
62         bool
63         Disable (KeyType category_name);
64         
65         bool
66         Enable (ValueSP category,
67                 Position pos = Default);
68         
69         bool
70         Disable (ValueSP category);
71
72         void
73         EnableAllCategories ();
74         
75         void
76         DisableAllCategories ();
77         
78         void
79         Clear ();
80         
81         bool
82         Get (KeyType name,
83              ValueSP& entry);
84         
85         bool
86         Get (uint32_t pos,
87              ValueSP& entry);
88         
89         void
90         ForEach (ForEachCallback callback);
91         
92         lldb::TypeCategoryImplSP
93         GetAtIndex (uint32_t);
94         
95         bool
96         AnyMatches(ConstString type_name,
97                    TypeCategoryImpl::FormatCategoryItems items = TypeCategoryImpl::ALL_ITEM_TYPES,
98                    bool only_enabled = true,
99                    const char** matching_category = nullptr,
100                    TypeCategoryImpl::FormatCategoryItems* matching_type = nullptr);
101         
102         uint32_t
103         GetCount ()
104         {
105             return m_map.size();
106         }
107
108         lldb::TypeFormatImplSP
109         GetFormat (FormattersMatchData& match_data);
110         
111         lldb::TypeSummaryImplSP
112         GetSummaryFormat (FormattersMatchData& match_data);
113         
114 #ifndef LLDB_DISABLE_PYTHON
115         lldb::SyntheticChildrenSP
116         GetSyntheticChildren (FormattersMatchData& match_data);
117 #endif
118         
119         lldb::TypeValidatorImplSP
120         GetValidator(FormattersMatchData& match_data);
121         
122     private:
123         class delete_matching_categories
124         {
125             lldb::TypeCategoryImplSP ptr;
126         public:
127             delete_matching_categories(lldb::TypeCategoryImplSP p) : ptr(p)
128             {}
129             
130             bool operator()(const lldb::TypeCategoryImplSP& other)
131             {
132                 return ptr.get() == other.get();
133             }
134         };
135
136         std::recursive_mutex m_map_mutex;
137         IFormatChangeListener* listener;
138         
139         MapType m_map;
140         ActiveCategoriesList m_active_categories;
141         
142         MapType& map ()
143         {
144             return m_map;
145         }
146         
147         ActiveCategoriesList& active_list ()
148         {
149             return m_active_categories;
150         }
151
152         std::recursive_mutex &
153         mutex()
154         {
155             return m_map_mutex;
156         }
157
158         friend class FormattersContainer<KeyType, ValueType>;
159         friend class FormatManager;
160     };
161 } // namespace lldb_private
162
163 #endif // lldb_TypeCategoryMap_h_