Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
CommandSystem.h
Go to the documentation of this file.
1/**
2 * @file CommandSystem.h
3 * @brief Command pattern for undo/redo operations
4 * @author Olympe Engine
5 * @date 2026-02-18
6 *
7 * @details
8 * Implements Command pattern for all graph operations to enable undo/redo.
9 */
10
11#pragma once
12
13#include <string>
14#include <vector>
15#include <memory>
16
17namespace Olympe {
18namespace NodeGraph {
19
20/**
21 * @class ICommand
22 * @brief Base interface for all commands
23 */
24class ICommand {
25public:
26 virtual ~ICommand() = default;
27
28 /**
29 * @brief Execute the command
30 */
31 virtual void Execute() = 0;
32
33 /**
34 * @brief Undo the command
35 */
36 virtual void Undo() = 0;
37
38 /**
39 * @brief Get description of the command
40 */
41 virtual std::string GetDescription() const = 0;
42};
43
44/**
45 * @class CommandStack
46 * @brief Manages undo/redo stacks for commands
47 */
49public:
50 /**
51 * @brief Execute a command and add to undo stack
52 * @param cmd Command to execute
53 */
54 void ExecuteCommand(std::unique_ptr<ICommand> cmd);
55
56 /**
57 * @brief Undo the last command
58 */
59 void Undo();
60
61 /**
62 * @brief Redo the last undone command
63 */
64 void Redo();
65
66 /**
67 * @brief Check if undo is available
68 */
69 bool CanUndo() const;
70
71 /**
72 * @brief Check if redo is available
73 */
74 bool CanRedo() const;
75
76 /**
77 * @brief Get description of next undo command
78 */
79 std::string GetUndoDescription() const;
80
81 /**
82 * @brief Get description of next redo command
83 */
84 std::string GetRedoDescription() const;
85
86 /**
87 * @brief Clear all commands
88 */
89 void Clear();
90
91private:
92 std::vector<std::unique_ptr<ICommand>> m_undoStack;
93 std::vector<std::unique_ptr<ICommand>> m_redoStack;
94 static const size_t MAX_STACK_SIZE = 100;
95};
96
97} // namespace NodeGraph
98} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Manages undo/redo stacks for commands.
void Undo()
Undo the last command.
static const size_t MAX_STACK_SIZE
bool CanUndo() const
Check if undo is available.
void Clear()
Clear all commands.
std::vector< std::unique_ptr< ICommand > > m_redoStack
std::string GetUndoDescription() const
Get description of next undo command.
std::string GetRedoDescription() const
Get description of next redo command.
void Redo()
Redo the last undone command.
bool CanRedo() const
Check if redo is available.
void ExecuteCommand(std::unique_ptr< ICommand > cmd)
Execute a command and add to undo stack.
std::vector< std::unique_ptr< ICommand > > m_undoStack
Base interface for all commands.
virtual ~ICommand()=default
virtual std::string GetDescription() const =0
Get description of the command.
virtual void Execute()=0
Execute the command.
virtual void Undo()=0
Undo the command.
< Provides AssetID and INVALID_ASSET_ID