Ignore:
Timestamp:
Mar 24, 2010, 4:26:21 PM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Children:
521e29
Parents:
91379c
Message:

Added methods that allow bookkeeping of actions for undo/redo methods

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/Actions/Action.hpp

    r91379c r0012e6  
    1111#include <string>
    1212
     13// forward declaration
     14
     15class ActionState;
     16class ActionSequence;
     17
    1318/**
    1419 * Base class for all actions.
     
    2126class Action
    2227{
    23 protected:
     28friend class ActionSequence;
    2429public:
    2530  Action(std::string _name,bool _doRegister=true);
    2631  virtual ~Action();
    2732
    28   virtual void call()=0;
    29   virtual void undo()=0;
     33  // this method only handles the infrastructure
     34  // actuall action is passed on to a private virtual
     35  void call();
     36  ActionState* undo(ActionState*);
     37  ActionState* redo(ActionState*);
     38
    3039  virtual bool canUndo()=0;
    31   //virtual bool shouldUndo()=0;
     40  virtual bool shouldUndo()=0;
    3241
    3342  virtual const std::string getName();
    3443
     44protected:
     45  static ActionState* success;
     46
    3547private:
     48  virtual ActionState* performCall()=0;
     49  virtual ActionState* performUndo(ActionState*)=0;
     50  virtual ActionState* performRedo(ActionState*)=0;
     51
    3652  std::string name;
    3753};
    3854
     55/**
     56 * This class can be used by actions to save the state.
     57 *
     58 * It is implementing a memento pattern. The base class is completely empty,
     59 * since no general state internals can be given. The Action performing
     60 * the Undo should downcast to the apropriate type.
     61 */
     62class ActionState{
     63public:
     64  ActionState(){}
     65  virtual ~ActionState(){}
     66};
     67
    3968#endif /* ACTION_H_ */
Note: See TracChangeset for help on using the changeset viewer.