Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
Olympe::UndoRedoStack Class Reference

Bounded stack of reversible editor commands. More...

#include <UndoRedoStack.h>

Public Member Functions

 UndoRedoStack ()
 
void PushCommand (std::unique_ptr< ICommand > cmd, TaskGraphTemplate &graph)
 Executes the command on graph, then pushes it onto the undo stack.
 
void Undo (TaskGraphTemplate &graph)
 Undoes the last command, moving it to the redo stack.
 
void Redo (TaskGraphTemplate &graph)
 Re-applies the last undone command, moving it back to the undo stack.
 
void Clear ()
 Clears both undo and redo stacks (e.g.
 
bool CanUndo () const
 Returns true if there is at least one command to undo.
 
bool CanRedo () const
 Returns true if there is at least one command to redo.
 
std::size_t UndoSize () const
 Returns the number of commands currently on the undo stack.
 
std::size_t RedoSize () const
 Returns the number of commands currently on the redo stack.
 
std::string PeekUndoDescription () const
 Returns the description of the top undo command, or "" if empty.
 
std::string PeekRedoDescription () const
 Returns the description of the top redo command, or "" if empty.
 

Static Public Attributes

static const std::size_t MAX_STACK_SIZE = 100u
 Maximum number of undo entries kept in memory.
 

Private Attributes

std::vector< std::unique_ptr< ICommand > > m_undoStack
 
std::vector< std::unique_ptr< ICommand > > m_redoStack
 

Detailed Description

Bounded stack of reversible editor commands.

Usage:

stack.PushCommand(std::unique_ptr<ICommand>(new AddNodeCommand(def)));
if (stack.CanUndo()) stack.Undo(graph);
if (stack.CanRedo()) stack.Redo(graph);
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Command to add a node to the tree.
Bounded stack of reversible editor commands.
void PushCommand(std::unique_ptr< ICommand > cmd, TaskGraphTemplate &graph)
Executes the command on graph, then pushes it onto the undo stack.

When more than MAX_STACK_SIZE commands are pushed, the oldest undo entry is dropped (FIFO eviction). Pushing any new command clears the redo stack.

Definition at line 395 of file UndoRedoStack.h.

Constructor & Destructor Documentation

◆ UndoRedoStack()

Olympe::UndoRedoStack::UndoRedoStack ( )

Definition at line 513 of file UndoRedoStack.cpp.

Member Function Documentation

◆ CanRedo()

bool Olympe::UndoRedoStack::CanRedo ( ) const

Returns true if there is at least one command to redo.

Definition at line 572 of file UndoRedoStack.cpp.

References m_redoStack.

◆ CanUndo()

bool Olympe::UndoRedoStack::CanUndo ( ) const

Returns true if there is at least one command to undo.

Definition at line 567 of file UndoRedoStack.cpp.

References m_undoStack.

◆ Clear()

void Olympe::UndoRedoStack::Clear ( )

Clears both undo and redo stacks (e.g.

after save).

Definition at line 561 of file UndoRedoStack.cpp.

References m_redoStack, and m_undoStack.

◆ PeekRedoDescription()

std::string Olympe::UndoRedoStack::PeekRedoDescription ( ) const

Returns the description of the top redo command, or "" if empty.

Definition at line 593 of file UndoRedoStack.cpp.

References m_redoStack.

◆ PeekUndoDescription()

std::string Olympe::UndoRedoStack::PeekUndoDescription ( ) const

Returns the description of the top undo command, or "" if empty.

Definition at line 587 of file UndoRedoStack.cpp.

References m_undoStack.

◆ PushCommand()

void Olympe::UndoRedoStack::PushCommand ( std::unique_ptr< ICommand cmd,
TaskGraphTemplate graph 
)

Executes the command on graph, then pushes it onto the undo stack.

Clears the redo stack.

Parameters
cmdOwning pointer to the command. Must not be null.
graphTarget graph on which Execute() is called immediately.

Definition at line 517 of file UndoRedoStack.cpp.

References GetComponentTypeID_Static(), m_redoStack, m_undoStack, and MAX_STACK_SIZE.

Referenced by Olympe::VisualScriptEditorPanel::AddNode(), Olympe::VisualScriptEditorPanel::ConnectData(), Olympe::VisualScriptEditorPanel::ConnectExec(), Olympe::VisualScriptEditorPanel::RemoveLink(), Olympe::VisualScriptEditorPanel::RemoveNode(), Olympe::VisualScriptEditorPanel::RenderNodePropertiesPanelContent(), and Olympe::VisualScriptEditorPanel::RenderSwitchNodeProperties().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Redo()

void Olympe::UndoRedoStack::Redo ( TaskGraphTemplate graph)

Re-applies the last undone command, moving it back to the undo stack.

Precondition
CanRedo() == true

Definition at line 549 of file UndoRedoStack.cpp.

References GetComponentTypeID_Static(), m_redoStack, and m_undoStack.

+ Here is the call graph for this function:

◆ RedoSize()

std::size_t Olympe::UndoRedoStack::RedoSize ( ) const

Returns the number of commands currently on the redo stack.

Definition at line 582 of file UndoRedoStack.cpp.

References m_redoStack.

◆ Undo()

void Olympe::UndoRedoStack::Undo ( TaskGraphTemplate graph)

Undoes the last command, moving it to the redo stack.

Precondition
CanUndo() == true

Definition at line 537 of file UndoRedoStack.cpp.

References GetComponentTypeID_Static(), m_redoStack, and m_undoStack.

+ Here is the call graph for this function:

◆ UndoSize()

std::size_t Olympe::UndoRedoStack::UndoSize ( ) const

Returns the number of commands currently on the undo stack.

Definition at line 577 of file UndoRedoStack.cpp.

References m_undoStack.

Member Data Documentation

◆ m_redoStack

std::vector<std::unique_ptr<ICommand> > Olympe::UndoRedoStack::m_redoStack
private

Definition at line 456 of file UndoRedoStack.h.

Referenced by CanRedo(), Clear(), PeekRedoDescription(), PushCommand(), Redo(), RedoSize(), and Undo().

◆ m_undoStack

std::vector<std::unique_ptr<ICommand> > Olympe::UndoRedoStack::m_undoStack
private

Definition at line 455 of file UndoRedoStack.h.

Referenced by CanUndo(), Clear(), PeekUndoDescription(), PushCommand(), Redo(), Undo(), and UndoSize().

◆ MAX_STACK_SIZE

const std::size_t Olympe::UndoRedoStack::MAX_STACK_SIZE = 100u
static

Maximum number of undo entries kept in memory.

Definition at line 399 of file UndoRedoStack.h.

Referenced by PushCommand().


The documentation for this class was generated from the following files: