Changeset 5b0b98


Ignore:
Timestamp:
Mar 25, 2010, 10:06:49 AM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
d56640
Parents:
67e2b3
Message:

Switched type of pointer used for ActionStates

Location:
src
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/Action.cpp

    r67e2b3 r5b0b98  
    1313using namespace std;
    1414
    15 // this object is only ever used as indicator.
    16 ActionState success_val;
    17 
    18 ActionState *Action::success = &success_val;
     15// An empty state to indicate success
     16Action::state_ptr Action::success = Action::state_ptr(new ActionState());
     17Action::state_ptr Action::failure = Action::state_ptr(new ActionState());
    1918
    2019Action::Action(std::string _name,bool _doRegister) :
     
    3736  performCall();
    3837}
    39 ActionState* Action::undo(ActionState* _state) {
     38Action::state_ptr Action::undo(state_ptr _state) {
    4039  // forward to private virtual
    4140  return performUndo(_state);
    4241}
    43 ActionState* Action::redo(ActionState* _state) {
     42Action::state_ptr Action::redo(state_ptr _state) {
    4443  // forward to private virtual
    4544  return performRedo(_state);
  • src/Actions/Action.hpp

    r67e2b3 r5b0b98  
    1010
    1111#include <string>
     12#include <boost/shared_ptr.hpp>
    1213
    1314// forward declaration
     
    2829friend class ActionSequence;
    2930public:
     31
     32  typedef boost::shared_ptr<ActionState> state_ptr;
     33
    3034  Action(std::string _name,bool _doRegister=true);
    3135  virtual ~Action();
     
    3438  // actuall action is passed on to a private virtual
    3539  void call();
    36   ActionState* undo(ActionState*);
    37   ActionState* redo(ActionState*);
     40  state_ptr undo(state_ptr);
     41  state_ptr redo(state_ptr);
    3842
    3943  virtual bool canUndo()=0;
     
    4347
    4448protected:
    45   static ActionState* success;
     49  static state_ptr success;
     50  static state_ptr failure;
    4651
    4752private:
    48   virtual ActionState* performCall()=0;
    49   virtual ActionState* performUndo(ActionState*)=0;
    50   virtual ActionState* performRedo(ActionState*)=0;
     53  virtual state_ptr performCall()=0;
     54  virtual state_ptr performUndo(state_ptr)=0;
     55  virtual state_ptr performRedo(state_ptr)=0;
    5156
    5257  std::string name;
  • src/Actions/ActionSequence.cpp

    r67e2b3 r5b0b98  
    4141    // we want to have a global bookkeeping for all actions in the sequence, so
    4242    // we bypass the normal call
    43     ActionState *state = (*it)->performCall();
     43    Action::state_ptr state = (*it)->performCall();
    4444    states.push_back(state);
    4545  }
     
    4747}
    4848
    49 ActionSequence::stateSet ActionSequence::undoAll(deque<ActionState*> states){
     49ActionSequence::stateSet ActionSequence::undoAll(stateSet states){
    5050  ASSERT(canUndo(),"Trying to undo a sequence that contains methods that can't be undone");
    5151  stateSet res;
     
    5555    ASSERT(stateRit!=states.rend(),"End of states prematurely reached.");
    5656    if((*actionRit)->shouldUndo()){
    57       ActionState *newState = (*actionRit)->performUndo(*stateRit);
     57      Action::state_ptr newState = (*actionRit)->performUndo(*stateRit);
    5858      // The order of the states has to correspond to the order of the actions
    5959      // this is why we have to add at the beginning
     
    6767}
    6868
    69 ActionSequence::stateSet ActionSequence::redoAll(deque<ActionState*> states){
     69ActionSequence::stateSet ActionSequence::redoAll(stateSet states){
    7070  stateSet res;
    7171  actionSet::iterator actionIt = actions.begin();
     
    7474    ASSERT(stateIt!=states.end(),"End of states prematurely reached.");
    7575    if((*actionIt)->shouldUndo()){
    76       ActionState *newState =(*actionIt)->performRedo(*stateIt);
     76      Action::state_ptr newState =(*actionIt)->performRedo(*stateIt);
    7777      res.push_back(newState);
    7878    }
  • src/Actions/ActionSequence.hpp

    r67e2b3 r5b0b98  
    99#define ACTIONSEQUENZE_HPP_
    1010
     11#include "Actions/Action.hpp"
     12
    1113#include <deque>
    12 
    13 class Action;
    14 class ActionState;
    1514
    1615/**
     
    2120public:
    2221  typedef std::deque<Action*> actionSet;
    23   typedef std::deque<ActionState*> stateSet;
     22  typedef std::deque<Action::state_ptr> stateSet;
    2423
    2524  ActionSequence();
  • src/Actions/Calculation.hpp

    r67e2b3 r5b0b98  
    6464  virtual T* doCalc()=0;
    6565private:
    66   virtual ActionState* performCall();
    67   virtual ActionState* performUndo(ActionState*);
    68   virtual ActionState* performRedo(ActionState*);
     66  virtual Action::state_ptr performCall();
     67  virtual Action::state_ptr performUndo(Action::state_ptr);
     68  virtual Action::state_ptr performRedo(Action::state_ptr);
    6969
    7070  bool done;
  • src/Actions/Calculation_impl.hpp

    r67e2b3 r5b0b98  
    2929
    3030template<typename T>
    31 ActionState* Calculation<T>::performCall(){
     31Action::state_ptr Calculation<T>::performCall(){
    3232  reset();
    3333  (*this)();
     
    3636
    3737template<typename T>
    38 ActionState* Calculation<T>::performUndo(ActionState*){
     38Action::state_ptr Calculation<T>::performUndo(Action::state_ptr){
    3939  ASSERT(0,"Cannot undo a calculation");
    4040  return Action::success;
    4141}
    4242template<typename T>
    43 ActionState* Calculation<T>::performRedo(ActionState*){
     43Action::state_ptr Calculation<T>::performRedo(Action::state_ptr){
    4444  ASSERT(0,"Cannot redo a calculation");
    4545  return Action::success;
  • src/Actions/ErrorAction.cpp

    r67e2b3 r5b0b98  
    2525}
    2626
    27 ActionState* ErrorAction::performCall() {
     27Action::state_ptr ErrorAction::performCall() {
    2828  Log() << Verbose(0) << errorMsg << endl;
    2929  return Action::success;
    3030}
    31 ActionState* ErrorAction::performUndo(ActionState*) {
     31Action::state_ptr ErrorAction::performUndo(Action::state_ptr) {
    3232  ASSERT(0,"Undo called for an ErrorAction");
    3333  return Action::success;
    3434}
    3535
    36 ActionState* ErrorAction::performRedo(ActionState*) {
     36Action::state_ptr ErrorAction::performRedo(Action::state_ptr) {
    3737  ASSERT(0,"Redo called for an ErrorAction");
    3838  return Action::success;
  • src/Actions/ErrorAction.hpp

    r67e2b3 r5b0b98  
    2323private:
    2424
    25   virtual ActionState* performCall();
    26   virtual ActionState* performUndo(ActionState*);
    27   virtual ActionState* performRedo(ActionState*);
     25  virtual Action::state_ptr performCall();
     26  virtual Action::state_ptr performUndo(Action::state_ptr);
     27  virtual Action::state_ptr performRedo(Action::state_ptr);
    2828
    2929  std::string errorMsg;
  • src/Actions/MakroAction.cpp

    r67e2b3 r5b0b98  
    2121  {}
    2222  virtual ~MakroActionState(){
    23     for(ActionSequence::stateSet::iterator iter=states.begin();
    24         iter!=states.end();++iter){
    25       delete *iter;
    26     }
     23    // All contained states are destroyed by the shared ptrs
    2724  }
    2825
     
    4643
    4744
    48 ActionState* MakroAction::performCall(){
     45Action::state_ptr MakroAction::performCall(){
    4946  ActionSequence::stateSet states = actions->callAll();
    50   return new MakroActionState(states);
     47  return Action::state_ptr(new MakroActionState(states));
    5148}
    5249
    53 ActionState* MakroAction::performUndo(ActionState* _state) {
    54   MakroActionState *state = dynamic_cast<MakroActionState*>(_state);
     50Action::state_ptr MakroAction::performUndo(Action::state_ptr _state) {
     51  MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get());
    5552  ASSERT(state,"Type mismatch for the state of the MakroAction");
    5653  ActionSequence::stateSet states = actions->undoAll(state->states);
    57   return new MakroActionState(states);
     54  return Action::state_ptr(new MakroActionState(states));
     55}
     56
     57Action::state_ptr MakroAction::performRedo(Action::state_ptr _state){
     58  MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get());
     59  ASSERT(state,"Type mismatch for the state of the MakroAction");
     60  ActionSequence::stateSet states = actions->redoAll(state->states);
     61  return Action::state_ptr(new MakroActionState(states));
    5862}
    5963
  • src/Actions/MakroAction.hpp

    r67e2b3 r5b0b98  
    3030
    3131private:
    32   virtual ActionState* performCall();
    33   virtual ActionState* performUndo(ActionState*);
    34   virtual ActionState* performRedo(ActionState*);
     32  virtual Action::state_ptr performCall();
     33  virtual Action::state_ptr performUndo(Action::state_ptr);
     34  virtual Action::state_ptr performRedo(Action::state_ptr);
    3535
    3636  ActionSequence *actions;
  • src/Actions/ManipulateAtomsProcess.cpp

    r67e2b3 r5b0b98  
    2525{}
    2626
    27 ActionState* ManipulateAtomsProcess::performCall(){
     27Action::state_ptr ManipulateAtomsProcess::performCall(){
    2828  World::getInstance().doManipulate(this);
    2929  return Action::success;
    3030}
    3131
    32 ActionState* ManipulateAtomsProcess::performUndo(ActionState*){
     32Action::state_ptr ManipulateAtomsProcess::performUndo(Action::state_ptr){
    3333  ASSERT(0,"Undo called for a ManipulateAtomsProcess");
    3434  return Action::success;
    3535}
    3636
    37 ActionState* ManipulateAtomsProcess::performRedo(ActionState*){
     37Action::state_ptr ManipulateAtomsProcess::performRedo(Action::state_ptr){
    3838  ASSERT(0,"Redo called for a ManipulateAtomsProcess");
    3939  return Action::success;
  • src/Actions/ManipulateAtomsProcess.hpp

    r67e2b3 r5b0b98  
    2929private:
    3030
    31   virtual ActionState* performCall();
    32   virtual ActionState* performUndo(ActionState*);
    33   virtual ActionState* performRedo(ActionState*);
     31  virtual Action::state_ptr performCall();
     32  virtual Action::state_ptr performUndo(Action::state_ptr);
     33  virtual Action::state_ptr performRedo(Action::state_ptr);
    3434
    3535  AtomDescriptor descr;
  • src/Actions/MethodAction.cpp

    r67e2b3 r5b0b98  
    2525
    2626
    27 ActionState* MethodAction::performCall() {
     27Action::state_ptr MethodAction::performCall() {
    2828  executeMethod();
    2929  // we don't have a state to save so we return Action::success
     
    3131}
    3232
    33 ActionState* MethodAction::performUndo(ActionState*) {
     33Action::state_ptr MethodAction::performUndo(Action::state_ptr) {
    3434  ASSERT(0,"Cannot undo a MethodAction");
    3535  return Action::success;
    3636}
    3737
    38 ActionState* MethodAction::performRedo(ActionState*){
     38Action::state_ptr MethodAction::performRedo(Action::state_ptr){
    3939  ASSERT(0,"Cannot redo a MethodAction");
    4040  return Action::success;
  • src/Actions/MethodAction.hpp

    r67e2b3 r5b0b98  
    2626
    2727private:
    28   virtual ActionState* performCall();
    29   virtual ActionState* performUndo(ActionState*);
    30   virtual ActionState* performRedo(ActionState*);
     28  virtual Action::state_ptr performCall();
     29  virtual Action::state_ptr performUndo(Action::state_ptr);
     30  virtual Action::state_ptr performRedo(Action::state_ptr);
    3131
    3232
  • src/Actions/small_actions.cpp

    r67e2b3 r5b0b98  
    3636{}
    3737
    38 ActionState* ChangeMoleculeNameAction::performCall() {
     38Action::state_ptr ChangeMoleculeNameAction::performCall() {
    3939  string filename;
    4040  molecule *mol = NULL;
     
    4848    mol->setName(filename);
    4949    delete dialog;
    50     return new ChangeMoleculeNameState(mol,oldName);
     50    return Action::state_ptr(new ChangeMoleculeNameState(mol,oldName));
    5151  }
    52   return 0;
     52  delete dialog;
     53  return Action::failure;
    5354}
    5455
    55 ActionState* ChangeMoleculeNameAction::performUndo(ActionState* _state) {
    56   ChangeMoleculeNameState *state = dynamic_cast<ChangeMoleculeNameState*>(_state);
     56Action::state_ptr ChangeMoleculeNameAction::performUndo(Action::state_ptr _state) {
     57  ChangeMoleculeNameState *state = dynamic_cast<ChangeMoleculeNameState*>(_state.get());
    5758  ASSERT(state,"State passed to ChangeMoleculeNameAction::performUndo did not have correct type");
    5859
     
    6061  state->mol->setName(state->lastName);
    6162
    62   return new ChangeMoleculeNameState(state->mol,newName);
     63  return Action::state_ptr(new ChangeMoleculeNameState(state->mol,newName));
    6364}
    6465
    65 ActionState* ChangeMoleculeNameAction::performRedo(ActionState *_state){
     66Action::state_ptr ChangeMoleculeNameAction::performRedo(Action::state_ptr _state){
    6667  // Undo and redo have to do the same for this action
    6768  return performUndo(_state);
  • src/Actions/small_actions.hpp

    r67e2b3 r5b0b98  
    1919  virtual const std::string getName();
    2020private:
    21   virtual ActionState* performCall();
    22   virtual ActionState* performUndo(ActionState*);
    23   virtual ActionState* performRedo(ActionState*);
     21  virtual Action::state_ptr performCall();
     22  virtual Action::state_ptr performUndo(Action::state_ptr);
     23  virtual Action::state_ptr performRedo(Action::state_ptr);
    2424
    2525  MoleculeListClass *molecules;
  • src/UIElements/TextDialog.cpp

    r67e2b3 r5b0b98  
    6868
    6969bool TextDialog::StringTextQuery::handle() {
    70   Log() << Verbose(0) << getTitle();
     70  //Log() << Verbose(0) << getTitle();
    7171  cin >> tmp;
    7272  return true;
  • src/unittests/ActionSequenceTest.cpp

    r67e2b3 r5b0b98  
    3535  virtual ~canUndoActionStub(){}
    3636
    37   virtual ActionState* performCall(){
    38     return Action::success;
    39   }
    40   virtual ActionState* performUndo(ActionState*){
    41     return Action::success;
    42   }
    43   virtual ActionState* performRedo(ActionState*){
     37  virtual Action::state_ptr performCall(){
     38    return Action::success;
     39  }
     40  virtual Action::state_ptr performUndo(Action::state_ptr){
     41    return Action::success;
     42  }
     43  virtual Action::state_ptr performRedo(Action::state_ptr){
    4444    return Action::success;
    4545  }
     
    5858  virtual ~cannotUndoActionStub(){}
    5959
    60   virtual ActionState* performCall(){
    61     return Action::success;
    62   }
    63   virtual ActionState* performUndo(ActionState*){
    64     return Action::success;
    65   }
    66   virtual ActionState* performRedo(ActionState*){
     60  virtual Action::state_ptr performCall(){
     61    return Action::success;
     62  }
     63  virtual Action::state_ptr performUndo(Action::state_ptr){
     64    return Action::success;
     65  }
     66  virtual Action::state_ptr performRedo(Action::state_ptr){
    6767    return Action::success;
    6868  }
     
    8484  virtual ~wasCalledActionStub(){}
    8585
    86   virtual ActionState* performCall(){
     86  virtual Action::state_ptr performCall(){
    8787    called = true;
    8888    return Action::success;
    8989  }
    90   virtual ActionState* performUndo(ActionState*){
     90  virtual Action::state_ptr performUndo(Action::state_ptr){
    9191    called = false;
    9292    return Action::success;
    9393  }
    94   virtual ActionState* performRedo(ActionState*){
     94  virtual Action::state_ptr performRedo(Action::state_ptr){
    9595    called = true;
    9696    return Action::success;
Note: See TracChangeset for help on using the changeset viewer.