1 //===-- FormatCache.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_FormatCache_h_ 11 #define lldb_FormatCache_h_ 12 13 // C Includes 14 // C++ Includes 15 #include <map> 16 17 // Other libraries and framework includes 18 // Project includes 19 #include "lldb/lldb-public.h" 20 #include "lldb/Core/ConstString.h" 21 #include "lldb/Host/Mutex.h" 22 #include "lldb/DataFormatters/FormatClasses.h" 23 24 namespace lldb_private { 25 class FormatCache 26 { 27 private: 28 struct Entry 29 { 30 private: 31 bool m_format_cached : 1; 32 bool m_summary_cached : 1; 33 bool m_synthetic_cached : 1; 34 bool m_validator_cached : 1; 35 36 lldb::TypeFormatImplSP m_format_sp; 37 lldb::TypeSummaryImplSP m_summary_sp; 38 lldb::SyntheticChildrenSP m_synthetic_sp; 39 lldb::TypeValidatorImplSP m_validator_sp; 40 public: 41 Entry (); 42 Entry (lldb::TypeFormatImplSP); 43 Entry (lldb::TypeSummaryImplSP); 44 Entry (lldb::SyntheticChildrenSP); 45 Entry (lldb::TypeValidatorImplSP); 46 Entry (lldb::TypeFormatImplSP,lldb::TypeSummaryImplSP,lldb::SyntheticChildrenSP,lldb::TypeValidatorImplSP); 47 48 bool 49 IsFormatCached (); 50 51 bool 52 IsSummaryCached (); 53 54 bool 55 IsSyntheticCached (); 56 57 bool 58 IsValidatorCached (); 59 60 lldb::TypeFormatImplSP 61 GetFormat (); 62 63 lldb::TypeSummaryImplSP 64 GetSummary (); 65 66 lldb::SyntheticChildrenSP 67 GetSynthetic (); 68 69 lldb::TypeValidatorImplSP 70 GetValidator (); 71 72 void 73 SetFormat (lldb::TypeFormatImplSP); 74 75 void 76 SetSummary (lldb::TypeSummaryImplSP); 77 78 void 79 SetSynthetic (lldb::SyntheticChildrenSP); 80 81 void 82 SetValidator (lldb::TypeValidatorImplSP); 83 }; 84 typedef std::map<ConstString,Entry> CacheMap; 85 CacheMap m_map; 86 Mutex m_mutex; 87 88 uint64_t m_cache_hits; 89 uint64_t m_cache_misses; 90 91 Entry& 92 GetEntry (const ConstString& type); 93 94 public: 95 FormatCache (); 96 97 bool 98 GetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp); 99 100 bool 101 GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp); 102 103 bool 104 GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp); 105 106 bool 107 GetValidator (const ConstString& type,lldb::TypeValidatorImplSP& summary_sp); 108 109 void 110 SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp); 111 112 void 113 SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp); 114 115 void 116 SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp); 117 118 void 119 SetValidator (const ConstString& type,lldb::TypeValidatorImplSP& synthetic_sp); 120 121 void 122 Clear (); 123 124 uint64_t GetCacheHits()125 GetCacheHits () 126 { 127 return m_cache_hits; 128 } 129 130 uint64_t GetCacheMisses()131 GetCacheMisses () 132 { 133 return m_cache_misses; 134 } 135 }; 136 } // namespace lldb_private 137 138 #endif // lldb_FormatCache_h_ 139