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_
21 // Other libraries and framework includes
23 #include "lldb/lldb-public.h"
25 namespace lldb_private {
27 //----------------------------------------------------------------------
28 /// @class HistorySource History.h "lldb/Core/History.h"
29 /// @brief A class that defines history events.
30 //----------------------------------------------------------------------
34 typedef const void *HistoryEvent;
36 HistorySource() : m_mutex(), m_events() {}
38 virtual ~HistorySource() {}
40 // Create a new history event. Subclasses should use any data or members
41 // in the subclass of this class to produce a history event and push it
42 // onto the end of the history stack.
44 virtual HistoryEvent CreateHistoryEvent() = 0;
46 virtual void DeleteHistoryEvent(HistoryEvent event) = 0;
48 virtual void DumpHistoryEvent(Stream &strm, HistoryEvent event) = 0;
50 virtual size_t GetHistoryEventCount() = 0;
52 virtual HistoryEvent GetHistoryEventAtIndex(uint32_t idx) = 0;
54 virtual HistoryEvent GetCurrentHistoryEvent() = 0;
56 // Return 0 when lhs == rhs, 1 if lhs > rhs, or -1 if lhs < rhs.
57 virtual int CompareHistoryEvents(const HistoryEvent lhs,
58 const HistoryEvent rhs) = 0;
60 virtual bool IsCurrentHistoryEvent(const HistoryEvent event) = 0;
63 typedef std::stack<HistoryEvent> collection;
65 std::recursive_mutex m_mutex;
68 DISALLOW_COPY_AND_ASSIGN(HistorySource);
71 //----------------------------------------------------------------------
72 /// @class HistorySourceUInt History.h "lldb/Core/History.h"
73 /// @brief A class that defines history events that are represented by
74 /// unsigned integers.
76 /// Any history event that is defined by a unique monotonically
77 /// increasing unsigned integer
78 //----------------------------------------------------------------------
80 class HistorySourceUInt : public HistorySource {
81 HistorySourceUInt(const char *id_name, uintptr_t start_value = 0u)
82 : HistorySource(), m_name(id_name), m_curr_id(start_value) {}
84 ~HistorySourceUInt() override {}
86 // Create a new history event. Subclasses should use any data or members
87 // in the subclass of this class to produce a history event and push it
88 // onto the end of the history stack.
90 HistoryEvent CreateHistoryEvent() override {
92 return (HistoryEvent)m_curr_id;
95 void DeleteHistoryEvent(HistoryEvent event) override {
96 // Nothing to delete, the event contains the integer
99 void DumpHistoryEvent(Stream &strm, HistoryEvent event) override;
101 size_t GetHistoryEventCount() override { return m_curr_id; }
103 HistoryEvent GetHistoryEventAtIndex(uint32_t idx) override {
104 return (HistoryEvent)((uintptr_t)idx);
107 HistoryEvent GetCurrentHistoryEvent() override {
108 return (HistoryEvent)m_curr_id;
111 // Return 0 when lhs == rhs, 1 if lhs > rhs, or -1 if lhs < rhs.
112 int CompareHistoryEvents(const HistoryEvent lhs,
113 const HistoryEvent rhs) override {
114 uintptr_t lhs_uint = (uintptr_t)lhs;
115 uintptr_t rhs_uint = (uintptr_t)rhs;
116 if (lhs_uint < rhs_uint)
118 if (lhs_uint > rhs_uint)
123 bool IsCurrentHistoryEvent(const HistoryEvent event) override {
124 return (uintptr_t)event == m_curr_id;
128 std::string m_name; // The name of the history unsigned integer
129 uintptr_t m_curr_id; // The current value of the history unsigned unteger
132 } // namespace lldb_private
134 #endif // lldb_History_h_