1 //===-- History.h -----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef lldb_History_h_
11 #define lldb_History_h_
13 #include "lldb/lldb-defines.h" // for DISALLOW_COPY_AND_ASSIGN
20 #include <stddef.h> // for size_t
23 namespace lldb_private {
27 namespace lldb_private {
29 //----------------------------------------------------------------------
30 /// @class HistorySource History.h "lldb/Core/History.h"
31 /// @brief A class that defines history events.
32 //----------------------------------------------------------------------
36 typedef const void *HistoryEvent;
38 HistorySource() : m_mutex(), m_events() {}
40 virtual ~HistorySource() {}
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.
46 virtual HistoryEvent CreateHistoryEvent() = 0;
48 virtual void DeleteHistoryEvent(HistoryEvent event) = 0;
50 virtual void DumpHistoryEvent(Stream &strm, HistoryEvent event) = 0;
52 virtual size_t GetHistoryEventCount() = 0;
54 virtual HistoryEvent GetHistoryEventAtIndex(uint32_t idx) = 0;
56 virtual HistoryEvent GetCurrentHistoryEvent() = 0;
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;
62 virtual bool IsCurrentHistoryEvent(const HistoryEvent event) = 0;
65 typedef std::stack<HistoryEvent> collection;
67 std::recursive_mutex m_mutex;
70 DISALLOW_COPY_AND_ASSIGN(HistorySource);
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.
78 /// Any history event that is defined by a unique monotonically
79 /// increasing unsigned integer
80 //----------------------------------------------------------------------
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) {}
86 ~HistorySourceUInt() override {}
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.
92 HistoryEvent CreateHistoryEvent() override {
94 return (HistoryEvent)m_curr_id;
97 void DeleteHistoryEvent(HistoryEvent event) override {
98 // Nothing to delete, the event contains the integer
101 void DumpHistoryEvent(Stream &strm, HistoryEvent event) override;
103 size_t GetHistoryEventCount() override { return m_curr_id; }
105 HistoryEvent GetHistoryEventAtIndex(uint32_t idx) override {
106 return (HistoryEvent)((uintptr_t)idx);
109 HistoryEvent GetCurrentHistoryEvent() override {
110 return (HistoryEvent)m_curr_id;
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)
120 if (lhs_uint > rhs_uint)
125 bool IsCurrentHistoryEvent(const HistoryEvent event) override {
126 return (uintptr_t)event == m_curr_id;
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
134 } // namespace lldb_private
136 #endif // lldb_History_h_