]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Utility/History.h
MFC r343918: Teach /etc/rc.d/growfs how to handle systems running ZFS.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Utility / 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 #include "lldb/lldb-defines.h" // for DISALLOW_COPY_AND_ASSIGN
14
15 // C++ Includes
16 #include <mutex>
17 #include <stack>
18 #include <string>
19
20 #include <stddef.h> // for size_t
21 #include <stdint.h>
22
23 namespace lldb_private {
24 class Stream;
25 }
26
27 namespace lldb_private {
28
29 //----------------------------------------------------------------------
30 /// @class HistorySource History.h "lldb/Core/History.h"
31 /// @brief A class that defines history events.
32 //----------------------------------------------------------------------
33
34 class HistorySource {
35 public:
36   typedef const void *HistoryEvent;
37
38   HistorySource() : m_mutex(), m_events() {}
39
40   virtual ~HistorySource() {}
41
42   // Create a new history event. Subclasses should use any data or members
43   // in the subclass of this class to produce a history event and push it
44   // onto the end of the history stack.
45
46   virtual HistoryEvent CreateHistoryEvent() = 0;
47
48   virtual void DeleteHistoryEvent(HistoryEvent event) = 0;
49
50   virtual void DumpHistoryEvent(Stream &strm, HistoryEvent event) = 0;
51
52   virtual size_t GetHistoryEventCount() = 0;
53
54   virtual HistoryEvent GetHistoryEventAtIndex(uint32_t idx) = 0;
55
56   virtual HistoryEvent GetCurrentHistoryEvent() = 0;
57
58   // Return 0 when lhs == rhs, 1 if lhs > rhs, or -1 if lhs < rhs.
59   virtual int CompareHistoryEvents(const HistoryEvent lhs,
60                                    const HistoryEvent rhs) = 0;
61
62   virtual bool IsCurrentHistoryEvent(const HistoryEvent event) = 0;
63
64 private:
65   typedef std::stack<HistoryEvent> collection;
66
67   std::recursive_mutex m_mutex;
68   collection m_events;
69
70   DISALLOW_COPY_AND_ASSIGN(HistorySource);
71 };
72
73 //----------------------------------------------------------------------
74 /// @class HistorySourceUInt History.h "lldb/Core/History.h"
75 /// @brief A class that defines history events that are represented by
76 /// unsigned integers.
77 ///
78 /// Any history event that is defined by a unique monotonically
79 /// increasing unsigned integer
80 //----------------------------------------------------------------------
81
82 class HistorySourceUInt : public HistorySource {
83   HistorySourceUInt(const char *id_name, uintptr_t start_value = 0u)
84       : HistorySource(), m_name(id_name), m_curr_id(start_value) {}
85
86   ~HistorySourceUInt() override {}
87
88   // Create a new history event. Subclasses should use any data or members
89   // in the subclass of this class to produce a history event and push it
90   // onto the end of the history stack.
91
92   HistoryEvent CreateHistoryEvent() override {
93     ++m_curr_id;
94     return (HistoryEvent)m_curr_id;
95   }
96
97   void DeleteHistoryEvent(HistoryEvent event) override {
98     // Nothing to delete, the event contains the integer
99   }
100
101   void DumpHistoryEvent(Stream &strm, HistoryEvent event) override;
102
103   size_t GetHistoryEventCount() override { return m_curr_id; }
104
105   HistoryEvent GetHistoryEventAtIndex(uint32_t idx) override {
106     return (HistoryEvent)((uintptr_t)idx);
107   }
108
109   HistoryEvent GetCurrentHistoryEvent() override {
110     return (HistoryEvent)m_curr_id;
111   }
112
113   // Return 0 when lhs == rhs, 1 if lhs > rhs, or -1 if lhs < rhs.
114   int CompareHistoryEvents(const HistoryEvent lhs,
115                            const HistoryEvent rhs) override {
116     uintptr_t lhs_uint = (uintptr_t)lhs;
117     uintptr_t rhs_uint = (uintptr_t)rhs;
118     if (lhs_uint < rhs_uint)
119       return -1;
120     if (lhs_uint > rhs_uint)
121       return +1;
122     return 0;
123   }
124
125   bool IsCurrentHistoryEvent(const HistoryEvent event) override {
126     return (uintptr_t)event == m_curr_id;
127   }
128
129 protected:
130   std::string m_name;  // The name of the history unsigned integer
131   uintptr_t m_curr_id; // The current value of the history unsigned unteger
132 };
133
134 } // namespace lldb_private
135
136 #endif // lldb_History_h_