blob: 884200b1b192d2cf906a414626691fd23853b7aa [file] [log] [blame]
Enrico Granataf509c5e2013-01-28 23:47:25 +00001//===-- 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_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 ();
Todd Fiala8aaa5232013-11-05 11:17:04 -080037 Entry (const Entry& rhs);
Enrico Granataf509c5e2013-01-28 23:47:25 +000038 Entry (lldb::TypeSummaryImplSP);
39 Entry (lldb::SyntheticChildrenSP);
40 Entry (lldb::TypeSummaryImplSP,lldb::SyntheticChildrenSP);
41
Todd Fiala8aaa5232013-11-05 11:17:04 -080042 Entry& operator= (const Entry& rhs);
43
Enrico Granataf509c5e2013-01-28 23:47:25 +000044 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
Enrico Granataf509c5e2013-01-28 23:47:25 +000066 uint64_t m_cache_hits;
67 uint64_t m_cache_misses;
Enrico Granataf509c5e2013-01-28 23:47:25 +000068
69 Entry&
70 GetEntry (const ConstString& type);
71
72public:
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
Enrico Granataf509c5e2013-01-28 23:47:25 +000090 uint64_t
91 GetCacheHits ()
92 {
93 return m_cache_hits;
94 }
95
96 uint64_t
97 GetCacheMisses ()
98 {
99 return m_cache_misses;
100 }
Enrico Granataf509c5e2013-01-28 23:47:25 +0000101};
102} // namespace lldb_private
103
104#endif // lldb_FormatCache_h_