Candidate_v1.7.0
        stable
      
      
        
          | Last change
 on this file since 7df863 was             7d2ee1, checked in by Frederik Heber <frederik.heber@…>, 5 years ago | 
        
          | 
ActionHistory's marked states is now a stack.
 i.e. multiple marks can be set and are removed when the history
passes over them or when they are undone till that mark.
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1.4 KB | 
      
      
| Line |  | 
|---|
| 1 | /* | 
|---|
| 2 | * ActionHistory.hpp | 
|---|
| 3 | * | 
|---|
| 4 | *  Created on: Mar 25, 2010 | 
|---|
| 5 | *      Author: crueger | 
|---|
| 6 | */ | 
|---|
| 7 |  | 
|---|
| 8 | #ifndef ACTIONHISTORY_HPP_ | 
|---|
| 9 | #define ACTIONHISTORY_HPP_ | 
|---|
| 10 |  | 
|---|
| 11 | // include config.h | 
|---|
| 12 | #ifdef HAVE_CONFIG_H | 
|---|
| 13 | #include <config.h> | 
|---|
| 14 | #endif | 
|---|
| 15 |  | 
|---|
| 16 | #include <deque> | 
|---|
| 17 | #include <stack> | 
|---|
| 18 |  | 
|---|
| 19 | #include "Actions/Action.hpp" | 
|---|
| 20 | #include "Actions/RedoAction.hpp" | 
|---|
| 21 | #include "Actions/UndoAction.hpp" | 
|---|
| 22 |  | 
|---|
| 23 | namespace MoleCuilder { | 
|---|
| 24 |  | 
|---|
| 25 | class ActionHistory | 
|---|
| 26 | { | 
|---|
| 27 | struct HistoryElement { | 
|---|
| 28 | HistoryElement(Action *_action, ActionState::ptr _state) : | 
|---|
| 29 | action(_action), | 
|---|
| 30 | state(_state) | 
|---|
| 31 | {} | 
|---|
| 32 | Action *action; | 
|---|
| 33 | ActionState::ptr state; | 
|---|
| 34 | }; | 
|---|
| 35 |  | 
|---|
| 36 | public: | 
|---|
| 37 | ActionHistory(); | 
|---|
| 38 | ~ActionHistory(); | 
|---|
| 39 |  | 
|---|
| 40 | void undoLast(); | 
|---|
| 41 | void redoLast(); | 
|---|
| 42 |  | 
|---|
| 43 | bool hasUndo(); | 
|---|
| 44 | bool hasRedo(); | 
|---|
| 45 |  | 
|---|
| 46 | void setMark(); | 
|---|
| 47 | void unsetMark(); | 
|---|
| 48 | void undoTillMark(); | 
|---|
| 49 |  | 
|---|
| 50 | void addElement(Action*,ActionState::ptr); | 
|---|
| 51 | void clear(); | 
|---|
| 52 |  | 
|---|
| 53 | private: | 
|---|
| 54 | std::deque<HistoryElement> history; | 
|---|
| 55 | std::deque<HistoryElement> yrotsih; | 
|---|
| 56 |  | 
|---|
| 57 | //!> marks a specific state in the history to allow undoing directly till that | 
|---|
| 58 | std::stack<HistoryElement *> marked; | 
|---|
| 59 |  | 
|---|
| 60 | public: | 
|---|
| 61 | // when constructing the actions we need the Actionregistry Singleton | 
|---|
| 62 | // Singletons need static variables to work, but we cannot access statics | 
|---|
| 63 | // inside a static initialization, so we have this init function that | 
|---|
| 64 | // needs to be called at a non-static point at the start of the program | 
|---|
| 65 | //  static void init(); | 
|---|
| 66 | }; | 
|---|
| 67 |  | 
|---|
| 68 | } | 
|---|
| 69 |  | 
|---|
| 70 | #endif /* ACTIONHISTORY_HPP_ */ | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.