FormatCache.h revision 50be3f72e5531d024ed07fd05a8352c8459f46cd
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_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 (lldb::TypeSummaryImplSP);
38        Entry (lldb::SyntheticChildrenSP);
39        Entry (lldb::TypeSummaryImplSP,lldb::SyntheticChildrenSP);
40
41        bool
42        IsSummaryCached ();
43
44        bool
45        IsSyntheticCached ();
46
47        lldb::TypeSummaryImplSP
48        GetSummary ();
49
50        lldb::SyntheticChildrenSP
51        GetSynthetic ();
52
53        void
54        SetSummary (lldb::TypeSummaryImplSP);
55
56        void
57        SetSynthetic (lldb::SyntheticChildrenSP);
58    };
59    typedef std::map<ConstString,Entry> CacheMap;
60    CacheMap m_map;
61    Mutex m_mutex;
62
63    uint64_t m_cache_hits;
64    uint64_t m_cache_misses;
65
66    Entry&
67    GetEntry (const ConstString& type);
68
69public:
70    FormatCache ();
71
72    bool
73    GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp);
74
75    bool
76    GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp);
77
78    void
79    SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp);
80
81    void
82    SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp);
83
84    void
85    Clear ();
86
87    uint64_t
88    GetCacheHits ()
89    {
90        return m_cache_hits;
91    }
92
93    uint64_t
94    GetCacheMisses ()
95    {
96        return m_cache_misses;
97    }
98};
99} // namespace lldb_private
100
101#endif	// lldb_FormatCache_h_
102