Permalink
Cannot retrieve contributors at this time
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?
3150_project/ECCommand.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
45 lines (35 sloc)
1.05 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// 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 |