aboutsummaryrefslogtreecommitdiff
path: root/include/lldb/Core/History.h
blob: b3626882f84321f7cad43e2bc1f5428381e5d2cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//===-- History.h -----------------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef lldb_History_h_
#define lldb_History_h_

// C Includes
#include <stdint.h>

// C++ Includes
#include <stack>
#include <string>

// Other libraries and framework includes
// Project includes
#include "lldb/lldb-public.h"
#include "lldb/Host/Mutex.h"

namespace lldb_private {

//----------------------------------------------------------------------
/// @class HistorySource History.h "lldb/Core/History.h"
/// @brief A class that defines history events.
//----------------------------------------------------------------------
    
class HistorySource
{
public:
    typedef const void * HistoryEvent;

    HistorySource () :
        m_mutex (Mutex::eMutexTypeRecursive),
        m_events ()
    {
    }

    virtual 
    ~HistorySource()
    {
    }

    // Create a new history event. Subclasses should use any data or members
    // in the subclass of this class to produce a history event and push it
    // onto the end of the history stack.

    virtual HistoryEvent
    CreateHistoryEvent () = 0; 
    
    virtual void
    DeleteHistoryEvent (HistoryEvent event) = 0;
    
    virtual void
    DumpHistoryEvent (Stream &strm, HistoryEvent event) = 0;

    virtual size_t
    GetHistoryEventCount() = 0;
    
    virtual HistoryEvent
    GetHistoryEventAtIndex (uint32_t idx) = 0;
    
    virtual HistoryEvent
    GetCurrentHistoryEvent () = 0;

    // Return 0 when lhs == rhs, 1 if lhs > rhs, or -1 if lhs < rhs.
    virtual int
    CompareHistoryEvents (const HistoryEvent lhs, 
                          const HistoryEvent rhs) = 0;
    
    virtual bool
    IsCurrentHistoryEvent (const HistoryEvent event) = 0;

private:
    typedef std::stack<HistoryEvent> collection;

    Mutex m_mutex;
    collection m_events;
    
    DISALLOW_COPY_AND_ASSIGN (HistorySource);

};
    
//----------------------------------------------------------------------
/// @class HistorySourceUInt History.h "lldb/Core/History.h"
/// @brief A class that defines history events that are represented by
/// unsigned integers.
///
/// Any history event that is defined by a unique monotonically 
/// increasing unsigned integer
//----------------------------------------------------------------------

class HistorySourceUInt : public HistorySource
{
    HistorySourceUInt (const char *id_name, uintptr_t start_value = 0u) :
        HistorySource(),
        m_name (id_name),
        m_curr_id (start_value)
    {
    }
    
    virtual 
    ~HistorySourceUInt()
    {
    }
    
    // Create a new history event. Subclasses should use any data or members
    // in the subclass of this class to produce a history event and push it
    // onto the end of the history stack.
    
    virtual HistoryEvent
    CreateHistoryEvent ()
    {
        ++m_curr_id;
        return (HistoryEvent)m_curr_id;
    }
    
    virtual void
    DeleteHistoryEvent (HistoryEvent event)
    {
        // Nothing to delete, the event contains the integer
    }
    
    virtual void
    DumpHistoryEvent (Stream &strm, HistoryEvent event);
    
    virtual size_t
    GetHistoryEventCount()
    {
        return m_curr_id;
    }
    
    virtual HistoryEvent
    GetHistoryEventAtIndex (uint32_t idx)
    {
        return (HistoryEvent)((uintptr_t)idx);
    }
    
    virtual HistoryEvent
    GetCurrentHistoryEvent ()
    {
        return (HistoryEvent)m_curr_id;
    }
    
    // Return 0 when lhs == rhs, 1 if lhs > rhs, or -1 if lhs < rhs.
    virtual int
    CompareHistoryEvents (const HistoryEvent lhs, 
                          const HistoryEvent rhs)
    {
        uintptr_t lhs_uint = (uintptr_t)lhs;
        uintptr_t rhs_uint = (uintptr_t)rhs;
        if (lhs_uint < rhs_uint)
            return -1;
        if (lhs_uint > rhs_uint)
            return +1;
        return 0;
    }
    
    virtual bool
    IsCurrentHistoryEvent (const HistoryEvent event)
    {
        return (uintptr_t)event == m_curr_id;
    }

protected:
    std::string m_name; // The name of the history unsigned integer
    uintptr_t m_curr_id; // The current value of the history unsigned unteger
};


} // namespace lldb_private

#endif	// lldb_History_h_