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