class Command{
public:
virtual bool execute() = 0;
virtual bool Unexecute() = 0;
};
class operator1 : public Command{
public:
bool execute(){
std::cout << "Operator1" << std::endl;
return true;
}
bool Unexecute(){
std::cout << "Unexecute Operator2" << std::endl;
return true;
}
};
class operator2 : public Command{
public:
bool execute(){
std::cout << "Operator2" << std::endl;
return true;
}
bool Unexecute(){
std::cout << "Unexecute Operator2" << std::endl;
return true;
}
};
class CommandManager
{
public:
static CommandManager* instance(){
static CommandManager ins;
return &ins;
}
void callCommand(Command* pCommand){
if (pCommand != NULL)
{
if (pCommand->execute())
{
PushUndoCommand(pCommand);
clearRedoCommand();
}
else
{
delete pCommand;
}
}
}
void PushUndoCommand(Command* pCommand){
C++实现Undo和Redo框架(命令模式)
最新推荐文章于 2024-10-12 22:59:08 发布