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