source: molecuilder/src/Actions/Action.cpp@ 0d111b

Last change on this file since 0d111b was 90c4460, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Added a small memory tracker to the programm.

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[d20ed5]1/*
2 * Action.cpp
3 *
4 * Created on: Dec 8, 2009
5 * Author: crueger
6 */
7
[3e8325]8#include <string>
[d20ed5]9
[3e8325]10#include "Actions/Action.hpp"
11#include "Actions/ActionRegistry.hpp"
[8d9984]12#include "Actions/ActionHistory.hpp"
[90c4460]13#include "Helpers/MemDebug.hpp"
[3e8325]14
15using namespace std;
16
[521e29]17// An empty state to indicate success
[90c4460]18Action::state_ptr Action::success = Action::state_ptr(Memory::ignore(new ActionState()));
19Action::state_ptr Action::failure = Action::state_ptr(Memory::ignore(new ActionState()));
[0012e6]20
[3e8325]21Action::Action(std::string _name,bool _doRegister) :
22name(_name)
23{
24 if(_doRegister){
[8a4f12]25 ActionRegistry::getInstance().registerAction(this);
[3e8325]26 }
27}
[d20ed5]28
29Action::~Action()
[da09909]30{}
[3e8325]31
32const string Action::getName(){
33 return name;
34}
[0012e6]35
36void Action::call(){
[abd4a1]37 if(!isActive()){
38 return;
39 }
[0012e6]40 // forward to private virtual
[8d9984]41 state_ptr state = performCall();
42 if(shouldUndo() && state != failure){
43 if(canUndo()){
44 ActionHistory::getInstance().addElement(this,state);
45 }
46 else{
47 ActionHistory::getInstance().clear();
48 }
49 }
[0012e6]50}
[521e29]51Action::state_ptr Action::undo(state_ptr _state) {
[0012e6]52 // forward to private virtual
53 return performUndo(_state);
54}
[521e29]55Action::state_ptr Action::redo(state_ptr _state) {
[0012e6]56 // forward to private virtual
57 return performRedo(_state);
58}
[770138]59
60
61bool Action::isActive(){
62 return true;
63}
Note: See TracBrowser for help on using the repository browser.