]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/History.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.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 //----------------------------------------------------------------------
89 /// @class HistorySourceUInt History.h "lldb/Core/History.h"
90 /// @brief A class that defines history events that are represented by
91 /// unsigned integers.
92 ///
93 /// Any history event that is defined by a unique monotonically 
94 /// increasing unsigned integer
95 //----------------------------------------------------------------------
96
97 class HistorySourceUInt : public HistorySource
98 {
99     HistorySourceUInt (const char *id_name, uintptr_t start_value = 0u) :
100         HistorySource(),
101         m_name (id_name),
102         m_curr_id (start_value)
103     {
104     }
105     
106     virtual 
107     ~HistorySourceUInt()
108     {
109     }
110     
111     // Create a new history event. Subclasses should use any data or members
112     // in the subclass of this class to produce a history event and push it
113     // onto the end of the history stack.
114     
115     virtual HistoryEvent
116     CreateHistoryEvent ()
117     {
118         ++m_curr_id;
119         return (HistoryEvent)m_curr_id;
120     }
121     
122     virtual void
123     DeleteHistoryEvent (HistoryEvent event)
124     {
125         // Nothing to delete, the event contains the integer
126     }
127     
128     virtual void
129     DumpHistoryEvent (Stream &strm, HistoryEvent event);
130     
131     virtual size_t
132     GetHistoryEventCount()
133     {
134         return m_curr_id;
135     }
136     
137     virtual HistoryEvent
138     GetHistoryEventAtIndex (uint32_t idx)
139     {
140         return (HistoryEvent)((uintptr_t)idx);
141     }
142     
143     virtual HistoryEvent
144     GetCurrentHistoryEvent ()
145     {
146         return (HistoryEvent)m_curr_id;
147     }
148     
149     // Return 0 when lhs == rhs, 1 if lhs > rhs, or -1 if lhs < rhs.
150     virtual int
151     CompareHistoryEvents (const HistoryEvent lhs, 
152                           const HistoryEvent rhs)
153     {
154         uintptr_t lhs_uint = (uintptr_t)lhs;
155         uintptr_t rhs_uint = (uintptr_t)rhs;
156         if (lhs_uint < rhs_uint)
157             return -1;
158         if (lhs_uint > rhs_uint)
159             return +1;
160         return 0;
161     }
162     
163     virtual bool
164     IsCurrentHistoryEvent (const HistoryEvent event)
165     {
166         return (uintptr_t)event == m_curr_id;
167     }
168
169 protected:
170     std::string m_name; // The name of the history unsigned integer
171     uintptr_t m_curr_id; // The current value of the history unsigned unteger
172 };
173
174
175 } // namespace lldb_private
176
177 #endif  // lldb_History_h_