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 35 lldb::TypeFormatImplSP m_format_sp; 36 lldb::TypeSummaryImplSP m_summary_sp; 37 lldb::SyntheticChildrenSP m_synthetic_sp; 38 public: 39 Entry (); 40 Entry (lldb::TypeFormatImplSP); 41 Entry (lldb::TypeSummaryImplSP); 42 Entry (lldb::SyntheticChildrenSP); 43 Entry (lldb::TypeFormatImplSP,lldb::TypeSummaryImplSP,lldb::SyntheticChildrenSP); 44 45 bool 46 IsFormatCached (); 47 48 bool 49 IsSummaryCached (); 50 51 bool 52 IsSyntheticCached (); 53 54 lldb::TypeFormatImplSP 55 GetFormat (); 56 57 lldb::TypeSummaryImplSP 58 GetSummary (); 59 60 lldb::SyntheticChildrenSP 61 GetSynthetic (); 62 63 void 64 SetFormat (lldb::TypeFormatImplSP); 65 66 void 67 SetSummary (lldb::TypeSummaryImplSP); 68 69 void 70 SetSynthetic (lldb::SyntheticChildrenSP); 71 }; 72 typedef std::map<ConstString,Entry> CacheMap; 73 CacheMap m_map; 74 Mutex m_mutex; 75 76 uint64_t m_cache_hits; 77 uint64_t m_cache_misses; 78 79 Entry& 80 GetEntry (const ConstString& type); 81 82 public: 83 FormatCache (); 84 85 bool 86 GetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp); 87 88 bool 89 GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp); 90 91 bool 92 GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp); 93 94 void 95 SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp); 96 97 void 98 SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp); 99 100 void 101 SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp); 102 103 void 104 Clear (); 105 106 uint64_t GetCacheHits()107 GetCacheHits () 108 { 109 return m_cache_hits; 110 } 111 112 uint64_t GetCacheMisses()113 GetCacheMisses () 114 { 115 return m_cache_misses; 116 } 117 }; 118 } // namespace lldb_private 119 120 #endif // lldb_FormatCache_h_ 121