fw4spl
UndoRedoManager.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWCOMMAND_UNDOREDOMANAGER_HPP__
8 #define __FWCOMMAND_UNDOREDOMANAGER_HPP__
9 
10 #include "fwCommand/config.hpp"
11 #include "fwCommand/ICommand.hpp"
12 
13 #include <deque>
14 #include <limits>
15 
16 namespace fwCommand
17 {
18 
22 class FWCOMMAND_CLASS_API UndoRedoManager
23 {
24 public:
25 
32  FWCOMMAND_API UndoRedoManager(size_t maxMemory = std::numeric_limits<size_t>::max(),
33  size_t maxCommands = std::numeric_limits<size_t>::max());
34 
42  FWCOMMAND_API bool enqueue( ICommand::sptr cmd );
43 
49  FWCOMMAND_API bool redo();
50 
56  FWCOMMAND_API bool undo();
57 
59  FWCOMMAND_API bool canUndo() const;
60 
62  FWCOMMAND_API bool canRedo() const;
63 
65  FWCOMMAND_API void clear();
66 
68  FWCOMMAND_API size_t getCommandCount() const;
69 
71  FWCOMMAND_API void setCommandCount(size_t cmdCount);
72 
74  FWCOMMAND_API size_t getHistorySize() const;
75 
77  FWCOMMAND_API void setHistorySize(size_t histSize);
78 
79 private:
80 
81  typedef std::deque<ICommand::sptr> CommandHistoryType;
82 
84  size_t m_maxMemory;
85 
87  size_t m_maxCommands;
88 
90  size_t m_usedMemory;
91 
93  CommandHistoryType m_commandQueue;
94 
96  std::int64_t m_commandIndex;
97 
99  void popFront();
100 
101 };
102 
103 } // namespace fwCommand
104 
105 #endif // __FWCOMMAND_UNDOREDOMANAGER_HPP__
Keep track of commands, undo/redo them.
The namespace fwCommand contains classes describing and managing commands.
Definition: ICommand.hpp:15