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