![]() |
Shadowrun: Awakened 29 September 2011 - Build 871
|
00001 #ifndef __COMMAND_H 00002 #define __COMMAND_H 00003 00004 #include "CodeGenMacros.h" 00005 #include <list> 00006 00007 //forward declaration for the sake of ICommand 00008 class CommandInvoker; 00009 00021 class ICommand 00022 { 00023 public: 00031 virtual bool isCumulative(ICommand* command) { return false; } 00032 00040 virtual void executeCumulative(ICommand* command) {} 00041 00045 virtual void execute() = 0; 00046 00050 virtual void undo() = 0; 00051 }; 00052 00058 class CompositeCommand : ICommand 00059 { 00060 protected: 00064 std::list<ICommand*> _commands; 00065 00066 public: 00067 virtual ~CompositeCommand(); 00068 00069 void addCommand(ICommand* command); 00070 00071 virtual bool isCumulative(ICommand* command); 00072 virtual void executeCumulative(ICommand* command); 00073 virtual void execute(); 00074 virtual void undo(); 00075 }; 00076 00082 class CommandInvoker 00083 { 00084 protected: 00088 std::list<ICommand*> _redoCommands; 00089 00093 std::list<ICommand*> _undoCommands; 00094 00095 bool _undoEnabled; 00096 bool _redoEnabled; 00097 00098 void clearUndo(); 00099 void clearRedo(); 00100 00101 void addCommandToUndo(ICommand* command); 00102 00103 public: 00104 CommandInvoker(); 00105 virtual ~CommandInvoker(); 00106 00111 template<class T> 00112 T* getLastCommand() 00113 { 00114 ICommand* command = getLastCommand(); 00115 return dynamic_cast<T*>(command); 00116 } 00117 00121 virtual ICommand* getLastCommand(); 00122 00127 template<class T> 00128 T* getInvoker() 00129 { 00130 return dynamic_cast<T*>(this); 00131 } 00132 00137 virtual void submitCommand(ICommand* command); 00138 00142 virtual void undo(); 00143 00147 virtual void redo(); 00148 00152 bool isUndoAvailable(); 00153 00157 bool isRedoAvailable(); 00158 00159 //This controls whether undo is able to do work 00160 SET_DECL(setUndoEnabled, bool) 00161 INLINE GET(getUndoEnabled, bool, _undoEnabled) 00162 00163 //This controls whether redo is able to do work 00164 SET_DECL(setRedoEnabled, bool) 00165 INLINE GET(getRedoEnabled, bool, _redoEnabled) 00166 }; 00167 00168 #endif
Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.