1 //===-- TypeCategoryMap.h ---------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef lldb_TypeCategoryMap_h_
10 #define lldb_TypeCategoryMap_h_
17 #include "lldb/lldb-enumerations.h"
18 #include "lldb/lldb-public.h"
20 #include "lldb/DataFormatters/FormattersContainer.h"
21 #include "lldb/DataFormatters/TypeCategory.h"
23 namespace lldb_private {
24 class TypeCategoryMap {
26 typedef ConstString KeyType;
27 typedef TypeCategoryImpl ValueType;
28 typedef ValueType::SharedPointer ValueSP;
29 typedef std::list<lldb::TypeCategoryImplSP> ActiveCategoriesList;
30 typedef ActiveCategoriesList::iterator ActiveCategoriesIterator;
33 typedef std::map<KeyType, ValueSP> MapType;
34 typedef MapType::iterator MapIterator;
35 typedef std::function<bool(const ValueSP &)> ForEachCallback;
37 typedef uint32_t Position;
39 static const Position First = 0;
40 static const Position Default = 1;
41 static const Position Last = UINT32_MAX;
43 TypeCategoryMap(IFormatChangeListener *lst);
45 void Add(KeyType name, const ValueSP &entry);
47 bool Delete(KeyType name);
49 bool Enable(KeyType category_name, Position pos = Default);
51 bool Disable(KeyType category_name);
53 bool Enable(ValueSP category, Position pos = Default);
55 bool Disable(ValueSP category);
57 void EnableAllCategories();
59 void DisableAllCategories();
63 bool Get(KeyType name, ValueSP &entry);
65 bool Get(uint32_t pos, ValueSP &entry);
67 void ForEach(ForEachCallback callback);
69 lldb::TypeCategoryImplSP GetAtIndex(uint32_t);
72 AnyMatches(ConstString type_name,
73 TypeCategoryImpl::FormatCategoryItems items =
74 TypeCategoryImpl::ALL_ITEM_TYPES,
75 bool only_enabled = true, const char **matching_category = nullptr,
76 TypeCategoryImpl::FormatCategoryItems *matching_type = nullptr);
78 uint32_t GetCount() { return m_map.size(); }
80 lldb::TypeFormatImplSP GetFormat(FormattersMatchData &match_data);
82 lldb::TypeSummaryImplSP GetSummaryFormat(FormattersMatchData &match_data);
84 lldb::SyntheticChildrenSP
85 GetSyntheticChildren(FormattersMatchData &match_data);
87 lldb::TypeValidatorImplSP GetValidator(FormattersMatchData &match_data);
90 class delete_matching_categories {
91 lldb::TypeCategoryImplSP ptr;
94 delete_matching_categories(lldb::TypeCategoryImplSP p) : ptr(p) {}
96 bool operator()(const lldb::TypeCategoryImplSP &other) {
97 return ptr.get() == other.get();
101 std::recursive_mutex m_map_mutex;
102 IFormatChangeListener *listener;
105 ActiveCategoriesList m_active_categories;
107 MapType &map() { return m_map; }
109 ActiveCategoriesList &active_list() { return m_active_categories; }
111 std::recursive_mutex &mutex() { return m_map_mutex; }
113 friend class FormattersContainer<KeyType, ValueType>;
114 friend class FormatManager;
116 } // namespace lldb_private
118 #endif // lldb_TypeCategoryMap_h_