xref: /freebsd/contrib/llvm-project/lldb/include/lldb/DataFormatters/TypeCategoryMap.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 //===-- TypeCategoryMap.h ---------------------------------------*- 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 #ifndef LLDB_DATAFORMATTERS_TYPECATEGORYMAP_H
10 #define LLDB_DATAFORMATTERS_TYPECATEGORYMAP_H
11 
12 #include <functional>
13 #include <list>
14 #include <map>
15 #include <mutex>
16 
17 #include "lldb/lldb-enumerations.h"
18 #include "lldb/lldb-public.h"
19 
20 #include "lldb/DataFormatters/FormatClasses.h"
21 #include "lldb/DataFormatters/FormattersContainer.h"
22 #include "lldb/DataFormatters/TypeCategory.h"
23 
24 namespace lldb_private {
25 class TypeCategoryMap {
26 private:
27   typedef std::list<lldb::TypeCategoryImplSP> ActiveCategoriesList;
28   typedef ActiveCategoriesList::iterator ActiveCategoriesIterator;
29 
30 public:
31   typedef ConstString KeyType;
32   typedef std::map<KeyType, lldb::TypeCategoryImplSP> MapType;
33   typedef MapType::iterator MapIterator;
34   typedef std::function<bool(const lldb::TypeCategoryImplSP &)> ForEachCallback;
35 
36   typedef uint32_t Position;
37 
38   static const Position First = 0;
39   static const Position Default = 1;
40   static const Position Last = UINT32_MAX;
41 
42   TypeCategoryMap(IFormatChangeListener *lst);
43 
44   void Add(KeyType name, const lldb::TypeCategoryImplSP &entry);
45 
46   bool Delete(KeyType name);
47 
48   bool Enable(KeyType category_name, Position pos = Default);
49 
50   bool Disable(KeyType category_name);
51 
52   bool Enable(lldb::TypeCategoryImplSP category, Position pos = Default);
53 
54   bool Disable(lldb::TypeCategoryImplSP category);
55 
56   void EnableAllCategories();
57 
58   void DisableAllCategories();
59 
60   void Clear();
61 
62   bool Get(KeyType name, lldb::TypeCategoryImplSP &entry);
63 
64   void ForEach(ForEachCallback callback);
65 
66   lldb::TypeCategoryImplSP GetAtIndex(uint32_t);
67 
68   bool
69   AnyMatches(const FormattersMatchCandidate &candidate_type,
70              TypeCategoryImpl::FormatCategoryItems items =
71                  TypeCategoryImpl::ALL_ITEM_TYPES,
72              bool only_enabled = true, const char **matching_category = nullptr,
73              TypeCategoryImpl::FormatCategoryItems *matching_type = nullptr);
74 
GetCount()75   uint32_t GetCount() { return m_map.size(); }
76 
77   template <typename ImplSP> void Get(FormattersMatchData &, ImplSP &);
78 
79 private:
80   class delete_matching_categories {
81     lldb::TypeCategoryImplSP ptr;
82 
83   public:
delete_matching_categories(lldb::TypeCategoryImplSP p)84     delete_matching_categories(lldb::TypeCategoryImplSP p)
85         : ptr(std::move(p)) {}
86 
operator()87     bool operator()(const lldb::TypeCategoryImplSP &other) {
88       return ptr.get() == other.get();
89     }
90   };
91 
92   std::recursive_mutex m_map_mutex;
93   IFormatChangeListener *listener;
94 
95   MapType m_map;
96   ActiveCategoriesList m_active_categories;
97 };
98 } // namespace lldb_private
99 
100 #endif // LLDB_DATAFORMATTERS_TYPECATEGORYMAP_H
101