Cafu Engine
CommandHistory.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 #ifndef CAFU_COMMAND_HISTORY_HPP_INCLUDED
8 #define CAFU_COMMAND_HISTORY_HPP_INCLUDED
9 
10 #include "CommandPattern.hpp"
11 
12 
14 {
15  public:
16 
18  ~CommandHistoryT();
19 
20  bool SubmitCommand(CommandT* Command);
21 
22  void Undo();
23  void Redo();
24 
25  const CommandT* GetUndoCommand() const; ///< Returns the next command in the history that can be undone, or NULL if there is none. Only commands that are shown in history are taken into account.
26  const CommandT* GetRedoCommand() const; ///< Returns the next command in the history that can be redone, or NULL if there is none. Only commands that are shown in history are taken into account.
27 
28  unsigned long GetLastSaveSuggestedCommandID() const;
29 
30 
31  private:
32 
33  ArrayT<CommandT*> m_Commands;
34  ArrayT<CommandT*> m_InvisCommands; ///< Stores all commands not visible in the history until a visible command is added to the history (then they are moved into the normal history).
35  int m_CurrentIndex; ///< The index of the last done command: all commands in <code>m_Commands[0 ... m_CurrentIndex]</code> are "done" (available for undo), any commands following them are "undone" (available for redo). If m_CurrentIndex is -1, there are no "done" commands at all.
36  bool m_IsRecursiveCall; ///< In order to facilitate debugging, this member helps with detecting recursive calls to our functions. For example, when we call a commands CommandT::Undo() method, does it erroneously cause a "recursive" call back to SubmitCommand()?
37 
38  /// The command id returned when there is no current command (when the current index is -1).
39  /// On creation this value is 0. It becomes the command ID of the last command removed from the history due to
40  /// size limitations as set in the CaWE options by the user.
41  unsigned long m_InvalidCommandID;
42 };
43 
44 #endif
This file provides the classes for the Command pattern as described in the book by the GoF...
const CommandT * GetUndoCommand() const
Returns the next command in the history that can be undone, or NULL if there is none. Only commands that are shown in history are taken into account.
Definition: CommandHistory.cpp:46
Definition: CommandHistory.hpp:13
const CommandT * GetRedoCommand() const
Returns the next command in the history that can be redone, or NULL if there is none. Only commands that are shown in history are taken into account.
Definition: CommandHistory.cpp:56
This class represents a general command for implementing modifications to the applications document...
Definition: CommandPattern.hpp:30