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/DataFormatters/FormatClasses.h" 22 23 namespace lldb_private { 24 class FormatCache 25 { 26 private: 27 struct Entry 28 { 29 private: 30 bool m_summary_cached : 1; 31 bool m_synthetic_cached : 1; 32 33 lldb::TypeSummaryImplSP m_summary_sp; 34 lldb::SyntheticChildrenSP m_synthetic_sp; 35 public: 36 Entry (); 37 Entry (const Entry& rhs); 38 Entry (lldb::TypeSummaryImplSP); 39 Entry (lldb::SyntheticChildrenSP); 40 Entry (lldb::TypeSummaryImplSP,lldb::SyntheticChildrenSP); 41 42 Entry& operator= (const Entry& rhs); 43 44 bool 45 IsSummaryCached (); 46 47 bool 48 IsSyntheticCached (); 49 50 lldb::TypeSummaryImplSP 51 GetSummary (); 52 53 lldb::SyntheticChildrenSP 54 GetSynthetic (); 55 56 void 57 SetSummary (lldb::TypeSummaryImplSP); 58 59 void 60 SetSynthetic (lldb::SyntheticChildrenSP); 61 }; 62 typedef std::map<ConstString,Entry> CacheMap; 63 CacheMap m_map; 64 Mutex m_mutex; 65 66 uint64_t m_cache_hits; 67 uint64_t m_cache_misses; 68 69 Entry& 70 GetEntry (const ConstString& type); 71 72 public: 73 FormatCache (); 74 75 bool 76 GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp); 77 78 bool 79 GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp); 80 81 void 82 SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp); 83 84 void 85 SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp); 86 87 void 88 Clear (); 89 90 uint64_t 91 GetCacheHits () 92 { 93 return m_cache_hits; 94 } 95 96 uint64_t 97 GetCacheMisses () 98 { 99 return m_cache_misses; 100 } 101 }; 102 } // namespace lldb_private 103 104 #endif // lldb_FormatCache_h_ 105