Elevate Engine 1
Loading...
Searching...
No Matches
Elevate::CommandManager Class Reference

#include <Command.h>

Public Member Functions

void PushCommand (std::unique_ptr< Command > command)
 

Protected Member Functions

void ExecuteStack ()
 
void Execute (std::unique_ptr< Command > command)
 
void Undo ()
 
void Redo ()
 

Detailed Description

Definition at line 39 of file Command.h.

Member Function Documentation

◆ Execute()

void Elevate::CommandManager::Execute ( std::unique_ptr< Command command)
protected

Definition at line 16 of file Command.cpp.

17{
18 EE_CORE_TRACE("Execute");
19 command->Execute();
20
21 if (command->IsUndoable())
22 {
23 m_undoStack.push(std::move(command));
24
25 // Clear the redo stack with a swap trick (more safe with unique ptrs)
26 std::stack<std::unique_ptr<Command>> empty;
27 m_redoStack.swap(empty);
28 }
29}

◆ ExecuteStack()

void Elevate::CommandManager::ExecuteStack ( )
protected

Definition at line 5 of file Command.cpp.

6{
7 while (!m_executeStack.empty())
8 {
9 EE_CORE_TRACE("ExecuteStack while loop iteration");
10 auto command = std::move(m_executeStack.top());
11 m_executeStack.pop();
12 Execute(std::move(command));
13 }
14}
void Execute(std::unique_ptr< Command > command)
Definition Command.cpp:16

◆ PushCommand()

void Elevate::CommandManager::PushCommand ( std::unique_ptr< Command command)
inline

Definition at line 42 of file Command.h.

43 {
44 m_executeStack.push(std::move(command));
45 }

◆ Redo()

void Elevate::CommandManager::Redo ( )
protected

Definition at line 50 of file Command.cpp.

51{
52 if (!m_redoStack.empty())
53 {
54 auto cmd = std::move(m_redoStack.top());
55 m_redoStack.pop();
56 PushCommand(std::move(cmd));
57 }
58}
void PushCommand(std::unique_ptr< Command > command)
Definition Command.h:42

◆ Undo()

void Elevate::CommandManager::Undo ( )
protected

Definition at line 31 of file Command.cpp.

32{
33 if (!m_undoStack.empty())
34 {
35 while (!m_undoStack.empty() && !m_undoStack.top()->IsUndoable())
36 {
37 m_undoStack.pop();
38 }
39
40 if (!m_undoStack.empty())
41 {
42 auto cmd = std::move(m_undoStack.top());
43 m_undoStack.pop();
44 cmd->Undo();
45 m_redoStack.push(std::move(cmd));
46 }
47 }
48}

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