]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/History.h
Merge ^/head r293036 through r293174.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / History.h
1 //===-- History.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_History_h_
11 #define lldb_History_h_
12
13 // C Includes
14 #include <stdint.h>
15
16 // C++ Includes
17 #include <stack>
18 #include <string>
19
20 // Other libraries and framework includes
21 // Project includes
22 #include "lldb/lldb-public.h"
23 #include "lldb/Host/Mutex.h"
24
25 namespace lldb_private {
26
27 //----------------------------------------------------------------------
28 /// @class HistorySource History.h "lldb/Core/History.h"
29 /// @brief A class that defines history events.
30 //----------------------------------------------------------------------
31     
32 class HistorySource
33 {
34 public:
35     typedef const void * HistoryEvent;
36
37     HistorySource () :
38         m_mutex (Mutex::eMutexTypeRecursive),
39         m_events ()
40     {
41     }
42
43     virtual 
44     ~HistorySource()
45     {
46     }
47
48     // Create a new history event. Subclasses should use any data or members
49     // in the subclass of this class to produce a history event and push it
50     // onto the end of the history stack.
51
52     virtual HistoryEvent
53     CreateHistoryEvent () = 0; 
54     
55     virtual void
56     DeleteHistoryEvent (HistoryEvent event) = 0;
57     
58     virtual void
59     DumpHistoryEvent (Stream &strm, HistoryEvent event) = 0;
60
61     virtual size_t
62     GetHistoryEventCount() = 0;
63     
64     virtual HistoryEvent
65     GetHistoryEventAtIndex (uint32_t idx) = 0;
66     
67     virtual HistoryEvent
68     GetCurrentHistoryEvent () = 0;
69
70     // Return 0 when lhs == rhs, 1 if lhs > rhs, or -1 if lhs < rhs.
71     virtual int
72     CompareHistoryEvents (const HistoryEvent lhs, 
73                           const HistoryEvent rhs) = 0;
74     
75     virtual bool
76     IsCurrentHistoryEvent (const HistoryEvent event) = 0;
77
78 private:
79     typedef std::stack<HistoryEvent> collection;
80
81     Mutex m_mutex;
82     collection m_events;
83     
84     DISALLOW_COPY_AND_ASSIGN (HistorySource);
85 };
86     
87 //----------------------------------------------------------------------
88 /// @class HistorySourceUInt History.h "lldb/Core/History.h"
89 /// @brief A class that defines history events that are represented by
90 /// unsigned integers.
91 ///
92 /// Any history event that is defined by a unique monotonically 
93 /// increasing unsigned integer
94 //----------------------------------------------------------------------
95
96 class HistorySourceUInt : public HistorySource
97 {
98     HistorySourceUInt (const char *id_name, uintptr_t start_value = 0u) :
99         HistorySource(),
100         m_name (id_name),
101         m_curr_id (start_value)
102     {
103     }
104     
105     ~HistorySourceUInt() override
106     {
107     }
108     
109     // Create a new history event. Subclasses should use any data or members
110     // in the subclass of this class to produce a history event and push it
111     // onto the end of the history stack.
112     
113     HistoryEvent
114     CreateHistoryEvent () override
115     {
116         ++m_curr_id;
117         return (HistoryEvent)m_curr_id;
118     }
119     
120     void
121     DeleteHistoryEvent (HistoryEvent event) override
122     {
123         // Nothing to delete, the event contains the integer
124     }
125     
126     void
127     DumpHistoryEvent (Stream &strm, HistoryEvent event) override;
128     
129     size_t
130     GetHistoryEventCount() override
131     {
132         return m_curr_id;
133     }
134     
135     HistoryEvent
136     GetHistoryEventAtIndex (uint32_t idx) override
137     {
138         return (HistoryEvent)((uintptr_t)idx);
139     }
140     
141     HistoryEvent
142     GetCurrentHistoryEvent () override
143     {
144         return (HistoryEvent)m_curr_id;
145     }
146     
147     // Return 0 when lhs == rhs, 1 if lhs > rhs, or -1 if lhs < rhs.
148     int
149     CompareHistoryEvents (const HistoryEvent lhs, 
150                           const HistoryEvent rhs) override
151     {
152         uintptr_t lhs_uint = (uintptr_t)lhs;
153         uintptr_t rhs_uint = (uintptr_t)rhs;
154         if (lhs_uint < rhs_uint)
155             return -1;
156         if (lhs_uint > rhs_uint)
157             return +1;
158         return 0;
159     }
160     
161     bool
162     IsCurrentHistoryEvent (const HistoryEvent event) override
163     {
164         return (uintptr_t)event == m_curr_id;
165     }
166
167 protected:
168     std::string m_name; // The name of the history unsigned integer
169     uintptr_t m_curr_id; // The current value of the history unsigned unteger
170 };
171
172 } // namespace lldb_private
173
174 #endif // lldb_History_h_