#ifndef lldb_History_h_
#define lldb_History_h_
#include <stdint.h>
#include <stack>
#include <string>
#include "lldb/lldb-public.h"
#include "lldb/Host/Mutex.h"
namespace lldb_private {
class HistorySource
{
public:
typedef const void * HistoryEvent;
HistorySource () :
m_mutex (Mutex::eMutexTypeRecursive),
m_events ()
{
}
virtual
~HistorySource()
{
}
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;
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 : public HistorySource
{
HistorySourceUInt (const char *id_name, uintptr_t start_value = 0u) :
HistorySource(),
m_name (id_name),
m_curr_id (start_value)
{
}
virtual
~HistorySourceUInt()
{
}
virtual HistoryEvent
CreateHistoryEvent ()
{
++m_curr_id;
return (HistoryEvent)m_curr_id;
}
virtual void
DeleteHistoryEvent (HistoryEvent event)
{
}
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;
}
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; uintptr_t m_curr_id; };
}
#endif // lldb_History_h_