Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Command Design Pattern for Undo/Redo
// Daniel Backal
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#ifndef ECCOMMAND_H
#define ECCOMMAND_H
#include <vector>
// ******************************************************
// Implementing command design pattern
class ECCommand
{
public:
virtual ~ECCommand() {}
virtual void Execute() = 0;
virtual void UnExecute() = 0;
};
// ******************************************************
// Implementing command history
class ECCommandHistory
{
public:
ECCommandHistory();
virtual ~ECCommandHistory();
bool Undo();
bool Redo();
void ExecuteCmd( ECCommand *pCmd );
void EmptyRedo();
private:
// Need to keep track of commands ran
// Should use vector, and undo pops back (puts it in redo vector)
// But also, if a new command is called after an undo, clear the redo vector.
std::vector<ECCommand *> undoList;
std::vector<ECCommand *> redoList;
};
#endif