Changeset 5b0b98
- Timestamp:
- Mar 25, 2010, 10:06:49 AM (15 years ago)
- 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
- Location:
- src
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/Action.cpp
r67e2b3 r5b0b98 13 13 using namespace std; 14 14 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 16 Action::state_ptr Action::success = Action::state_ptr(new ActionState()); 17 Action::state_ptr Action::failure = Action::state_ptr(new ActionState()); 19 18 20 19 Action::Action(std::string _name,bool _doRegister) : … … 37 36 performCall(); 38 37 } 39 Action State* Action::undo(ActionState*_state) {38 Action::state_ptr Action::undo(state_ptr _state) { 40 39 // forward to private virtual 41 40 return performUndo(_state); 42 41 } 43 Action State* Action::redo(ActionState*_state) {42 Action::state_ptr Action::redo(state_ptr _state) { 44 43 // forward to private virtual 45 44 return performRedo(_state); -
src/Actions/Action.hpp
r67e2b3 r5b0b98 10 10 11 11 #include <string> 12 #include <boost/shared_ptr.hpp> 12 13 13 14 // forward declaration … … 28 29 friend class ActionSequence; 29 30 public: 31 32 typedef boost::shared_ptr<ActionState> state_ptr; 33 30 34 Action(std::string _name,bool _doRegister=true); 31 35 virtual ~Action(); … … 34 38 // actuall action is passed on to a private virtual 35 39 void call(); 36 ActionState* undo(ActionState*);37 ActionState* redo(ActionState*);40 state_ptr undo(state_ptr); 41 state_ptr redo(state_ptr); 38 42 39 43 virtual bool canUndo()=0; … … 43 47 44 48 protected: 45 static ActionState* success; 49 static state_ptr success; 50 static state_ptr failure; 46 51 47 52 private: 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; 51 56 52 57 std::string name; -
src/Actions/ActionSequence.cpp
r67e2b3 r5b0b98 41 41 // we want to have a global bookkeeping for all actions in the sequence, so 42 42 // we bypass the normal call 43 Action State *state = (*it)->performCall();43 Action::state_ptr state = (*it)->performCall(); 44 44 states.push_back(state); 45 45 } … … 47 47 } 48 48 49 ActionSequence::stateSet ActionSequence::undoAll( deque<ActionState*>states){49 ActionSequence::stateSet ActionSequence::undoAll(stateSet states){ 50 50 ASSERT(canUndo(),"Trying to undo a sequence that contains methods that can't be undone"); 51 51 stateSet res; … … 55 55 ASSERT(stateRit!=states.rend(),"End of states prematurely reached."); 56 56 if((*actionRit)->shouldUndo()){ 57 Action State *newState = (*actionRit)->performUndo(*stateRit);57 Action::state_ptr newState = (*actionRit)->performUndo(*stateRit); 58 58 // The order of the states has to correspond to the order of the actions 59 59 // this is why we have to add at the beginning … … 67 67 } 68 68 69 ActionSequence::stateSet ActionSequence::redoAll( deque<ActionState*>states){69 ActionSequence::stateSet ActionSequence::redoAll(stateSet states){ 70 70 stateSet res; 71 71 actionSet::iterator actionIt = actions.begin(); … … 74 74 ASSERT(stateIt!=states.end(),"End of states prematurely reached."); 75 75 if((*actionIt)->shouldUndo()){ 76 Action State *newState =(*actionIt)->performRedo(*stateIt);76 Action::state_ptr newState =(*actionIt)->performRedo(*stateIt); 77 77 res.push_back(newState); 78 78 } -
src/Actions/ActionSequence.hpp
r67e2b3 r5b0b98 9 9 #define ACTIONSEQUENZE_HPP_ 10 10 11 #include "Actions/Action.hpp" 12 11 13 #include <deque> 12 13 class Action;14 class ActionState;15 14 16 15 /** … … 21 20 public: 22 21 typedef std::deque<Action*> actionSet; 23 typedef std::deque<Action State*> stateSet;22 typedef std::deque<Action::state_ptr> stateSet; 24 23 25 24 ActionSequence(); -
src/Actions/Calculation.hpp
r67e2b3 r5b0b98 64 64 virtual T* doCalc()=0; 65 65 private: 66 virtual Action State*performCall();67 virtual Action State* performUndo(ActionState*);68 virtual Action State* 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); 69 69 70 70 bool done; -
src/Actions/Calculation_impl.hpp
r67e2b3 r5b0b98 29 29 30 30 template<typename T> 31 Action State*Calculation<T>::performCall(){31 Action::state_ptr Calculation<T>::performCall(){ 32 32 reset(); 33 33 (*this)(); … … 36 36 37 37 template<typename T> 38 Action State* Calculation<T>::performUndo(ActionState*){38 Action::state_ptr Calculation<T>::performUndo(Action::state_ptr){ 39 39 ASSERT(0,"Cannot undo a calculation"); 40 40 return Action::success; 41 41 } 42 42 template<typename T> 43 Action State* Calculation<T>::performRedo(ActionState*){43 Action::state_ptr Calculation<T>::performRedo(Action::state_ptr){ 44 44 ASSERT(0,"Cannot redo a calculation"); 45 45 return Action::success; -
src/Actions/ErrorAction.cpp
r67e2b3 r5b0b98 25 25 } 26 26 27 Action State*ErrorAction::performCall() {27 Action::state_ptr ErrorAction::performCall() { 28 28 Log() << Verbose(0) << errorMsg << endl; 29 29 return Action::success; 30 30 } 31 Action State* ErrorAction::performUndo(ActionState*) {31 Action::state_ptr ErrorAction::performUndo(Action::state_ptr) { 32 32 ASSERT(0,"Undo called for an ErrorAction"); 33 33 return Action::success; 34 34 } 35 35 36 Action State* ErrorAction::performRedo(ActionState*) {36 Action::state_ptr ErrorAction::performRedo(Action::state_ptr) { 37 37 ASSERT(0,"Redo called for an ErrorAction"); 38 38 return Action::success; -
src/Actions/ErrorAction.hpp
r67e2b3 r5b0b98 23 23 private: 24 24 25 virtual Action State*performCall();26 virtual Action State* performUndo(ActionState*);27 virtual Action State* 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); 28 28 29 29 std::string errorMsg; -
src/Actions/MakroAction.cpp
r67e2b3 r5b0b98 21 21 {} 22 22 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 27 24 } 28 25 … … 46 43 47 44 48 Action State*MakroAction::performCall(){45 Action::state_ptr MakroAction::performCall(){ 49 46 ActionSequence::stateSet states = actions->callAll(); 50 return new MakroActionState(states);47 return Action::state_ptr(new MakroActionState(states)); 51 48 } 52 49 53 Action State* MakroAction::performUndo(ActionState*_state) {54 MakroActionState *state = dynamic_cast<MakroActionState*>(_state );50 Action::state_ptr MakroAction::performUndo(Action::state_ptr _state) { 51 MakroActionState *state = dynamic_cast<MakroActionState*>(_state.get()); 55 52 ASSERT(state,"Type mismatch for the state of the MakroAction"); 56 53 ActionSequence::stateSet states = actions->undoAll(state->states); 57 return new MakroActionState(states); 54 return Action::state_ptr(new MakroActionState(states)); 55 } 56 57 Action::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)); 58 62 } 59 63 -
src/Actions/MakroAction.hpp
r67e2b3 r5b0b98 30 30 31 31 private: 32 virtual Action State*performCall();33 virtual Action State* performUndo(ActionState*);34 virtual Action State* 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); 35 35 36 36 ActionSequence *actions; -
src/Actions/ManipulateAtomsProcess.cpp
r67e2b3 r5b0b98 25 25 {} 26 26 27 Action State*ManipulateAtomsProcess::performCall(){27 Action::state_ptr ManipulateAtomsProcess::performCall(){ 28 28 World::getInstance().doManipulate(this); 29 29 return Action::success; 30 30 } 31 31 32 Action State* ManipulateAtomsProcess::performUndo(ActionState*){32 Action::state_ptr ManipulateAtomsProcess::performUndo(Action::state_ptr){ 33 33 ASSERT(0,"Undo called for a ManipulateAtomsProcess"); 34 34 return Action::success; 35 35 } 36 36 37 Action State* ManipulateAtomsProcess::performRedo(ActionState*){37 Action::state_ptr ManipulateAtomsProcess::performRedo(Action::state_ptr){ 38 38 ASSERT(0,"Redo called for a ManipulateAtomsProcess"); 39 39 return Action::success; -
src/Actions/ManipulateAtomsProcess.hpp
r67e2b3 r5b0b98 29 29 private: 30 30 31 virtual Action State*performCall();32 virtual Action State* performUndo(ActionState*);33 virtual Action State* 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); 34 34 35 35 AtomDescriptor descr; -
src/Actions/MethodAction.cpp
r67e2b3 r5b0b98 25 25 26 26 27 Action State*MethodAction::performCall() {27 Action::state_ptr MethodAction::performCall() { 28 28 executeMethod(); 29 29 // we don't have a state to save so we return Action::success … … 31 31 } 32 32 33 Action State* MethodAction::performUndo(ActionState*) {33 Action::state_ptr MethodAction::performUndo(Action::state_ptr) { 34 34 ASSERT(0,"Cannot undo a MethodAction"); 35 35 return Action::success; 36 36 } 37 37 38 Action State* MethodAction::performRedo(ActionState*){38 Action::state_ptr MethodAction::performRedo(Action::state_ptr){ 39 39 ASSERT(0,"Cannot redo a MethodAction"); 40 40 return Action::success; -
src/Actions/MethodAction.hpp
r67e2b3 r5b0b98 26 26 27 27 private: 28 virtual Action State*performCall();29 virtual Action State* performUndo(ActionState*);30 virtual Action State* 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); 31 31 32 32 -
src/Actions/small_actions.cpp
r67e2b3 r5b0b98 36 36 {} 37 37 38 Action State*ChangeMoleculeNameAction::performCall() {38 Action::state_ptr ChangeMoleculeNameAction::performCall() { 39 39 string filename; 40 40 molecule *mol = NULL; … … 48 48 mol->setName(filename); 49 49 delete dialog; 50 return new ChangeMoleculeNameState(mol,oldName);50 return Action::state_ptr(new ChangeMoleculeNameState(mol,oldName)); 51 51 } 52 return 0; 52 delete dialog; 53 return Action::failure; 53 54 } 54 55 55 Action State* ChangeMoleculeNameAction::performUndo(ActionState*_state) {56 ChangeMoleculeNameState *state = dynamic_cast<ChangeMoleculeNameState*>(_state );56 Action::state_ptr ChangeMoleculeNameAction::performUndo(Action::state_ptr _state) { 57 ChangeMoleculeNameState *state = dynamic_cast<ChangeMoleculeNameState*>(_state.get()); 57 58 ASSERT(state,"State passed to ChangeMoleculeNameAction::performUndo did not have correct type"); 58 59 … … 60 61 state->mol->setName(state->lastName); 61 62 62 return new ChangeMoleculeNameState(state->mol,newName);63 return Action::state_ptr(new ChangeMoleculeNameState(state->mol,newName)); 63 64 } 64 65 65 Action State* ChangeMoleculeNameAction::performRedo(ActionState *_state){66 Action::state_ptr ChangeMoleculeNameAction::performRedo(Action::state_ptr _state){ 66 67 // Undo and redo have to do the same for this action 67 68 return performUndo(_state); -
src/Actions/small_actions.hpp
r67e2b3 r5b0b98 19 19 virtual const std::string getName(); 20 20 private: 21 virtual Action State*performCall();22 virtual Action State* performUndo(ActionState*);23 virtual Action State* 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); 24 24 25 25 MoleculeListClass *molecules; -
src/UIElements/TextDialog.cpp
r67e2b3 r5b0b98 68 68 69 69 bool TextDialog::StringTextQuery::handle() { 70 Log() << Verbose(0) << getTitle();70 //Log() << Verbose(0) << getTitle(); 71 71 cin >> tmp; 72 72 return true; -
src/unittests/ActionSequenceTest.cpp
r67e2b3 r5b0b98 35 35 virtual ~canUndoActionStub(){} 36 36 37 virtual Action State*performCall(){38 return Action::success; 39 } 40 virtual Action State* performUndo(ActionState*){41 return Action::success; 42 } 43 virtual Action State* 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){ 44 44 return Action::success; 45 45 } … … 58 58 virtual ~cannotUndoActionStub(){} 59 59 60 virtual Action State*performCall(){61 return Action::success; 62 } 63 virtual Action State* performUndo(ActionState*){64 return Action::success; 65 } 66 virtual Action State* 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){ 67 67 return Action::success; 68 68 } … … 84 84 virtual ~wasCalledActionStub(){} 85 85 86 virtual Action State*performCall(){86 virtual Action::state_ptr performCall(){ 87 87 called = true; 88 88 return Action::success; 89 89 } 90 virtual Action State* performUndo(ActionState*){90 virtual Action::state_ptr performUndo(Action::state_ptr){ 91 91 called = false; 92 92 return Action::success; 93 93 } 94 virtual Action State* performRedo(ActionState*){94 virtual Action::state_ptr performRedo(Action::state_ptr){ 95 95 called = true; 96 96 return Action::success;
Note:
See TracChangeset
for help on using the changeset viewer.