Files
panopainter/engine/action.h

36 lines
746 B
C++

#pragma once
class Action
{
public:
virtual void run() = 0;
virtual void undo() = 0;
virtual size_t memory() = 0;
virtual ~Action(){};
};
class ActionManager
{
public:
static ActionManager I;
std::stack<std::unique_ptr<Action>> m_actions;
size_t m_memory = 0;
static void add(Action* action)
{
I.m_actions.emplace(action);
I.m_memory += action->memory();
LOG("History: %.2f KB", I.m_memory / 1024.f);
}
static void undo()
{
I.m_actions.top()->undo();
I.m_memory -= I.m_actions.top()->memory();
I.m_actions.pop();
LOG("History: %.2f KB", I.m_memory / 1024.f);
}
static bool empty()
{
return I.m_actions.empty();
}
};