Changeset 10aee4 for src


Ignore:
Timestamp:
Aug 5, 2015, 7:12:24 AM (10 years ago)
Author:
Frederik Heber <heber@…>
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:
c307ba
Parents:
94232b
git-author:
Frederik Heber <heber@…> (08/03/15 09:25:02)
git-committer:
Frederik Heber <heber@…> (08/05/15 07:12:24)
Message:

Cleaned up ActionQueue's interface: Actions are always cloned.

  • Action's dstor needs to be public as we have a clone() function.
  • ActionRegistrys' (and AQ's) getActionByName now returns const ref. We must not return a ptr as it may not get deleted elsewhere. We are handing out prototypes.
  • queueAction(action*,...) is private to prevent leakage, queueAction(string, ...) is the public interface.
  • some other small functions are now private, too.
  • MakroActions now need to clone() the prototype on prepare() and delete them on unprepare().
  • ActionSequence deletes contained actions.
  • FIX: ActionSequenceUnitTest cannot check on not-called property of removed actions anymore as these are gone now (they are deleted on removal and they are cloned on insertion).
  • DOCU: Updated documentation on Actions.
Location:
src
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/Action.hpp

    r94232b r10aee4  
    111111  enum QueryOptions {Interactive, NonInteractive};
    112112
     113  /** Destructor for class Action.
     114   *
     115   * Needs to be public as clone() is a public function.
     116   *
     117   */
     118  virtual ~Action();
     119
    113120protected:
    114121  /**
     
    125132   */
    126133  Action(const ActionTrait &_Traits);
    127   virtual ~Action();
    128134
    129135  /**
  • src/Actions/ActionQueue.cpp

    r94232b r10aee4  
    9494void ActionQueue::queueAction(const std::string &name, enum Action::QueryOptions state)
    9595{
    96   const Action * const registryaction = AR->getActionByName(name);
    97   queueAction(registryaction, state);
     96  const Action & registryaction = AR->getActionByName(name);
     97  queueAction(&registryaction, state);
    9898}
    9999
     
    263263#endif
    264264
    265 Action* ActionQueue::getActionByName(const std::string &name)
     265const Action& ActionQueue::getActionByName(const std::string &name)
    266266{
    267267  return AR->getActionByName(name);
     
    313313{
    314314  // this const_cast is just required as long as we have a non-const getActionByName
    315   const Action * const action = const_cast<ActionQueue *>(this)->getActionByName(name);
    316   return action->Traits;
     315  const Action & action = const_cast<ActionQueue *>(this)->getActionByName(name);
     316  return action.Traits;
    317317}
    318318
  • src/Actions/ActionQueue.hpp

    r94232b r10aee4  
    7979  void queueAction(const std::string &name, enum Action::QueryOptions state = Action::Interactive);
    8080
    81   /** Queues the Action with \a name to be called.
    82    *
    83    * \param _action action to add
    84    * \param state whether Actions needs to be filled via a Dialog or not
    85    */
    86   void queueAction(const Action * const _action, enum Action::QueryOptions state = Action::Interactive);
    87 
    8881  /** Returns the spawned action by token \a name.
    8982   *
    9083   * Action is checked into internal actionqueue.
    9184   *
    92    * \return pointer to newly spawned action
    93    */
    94   Action* getActionByName(const std::string &name);
     85   * \return ref to newly spawned action
     86   */
     87  const Action& getActionByName(const std::string &name);
    9588
    9689  /** Checks whether the Action is known by the given \a name.
     
    164157  bool getLastActionOk() const
    165158  {  return lastActionOk; }
    166 
    167 #ifdef HAVE_ACTION_THREAD
    168   boost::thread &getRunThread()
    169   { return run_thread; }
    170 #endif
    171159
    172160  /** Getter to ref to list of status messages.
     
    200188  friend class DryRunAdvocate;
    201189
     190  /** Queues the Action with \a name to be called.
     191   *
     192   * \param _action action to add
     193   * \param state whether Actions needs to be filled via a Dialog or not
     194   */
     195  void queueAction(const Action * const _action, enum Action::QueryOptions state = Action::Interactive);
     196
    202197  /** Wrapper function to add state to ActionHistory.
    203198   *
     
    225220
    226221#ifdef HAVE_ACTION_THREAD
     222  boost::thread &getRunThread()
     223  { return run_thread; }
    227224
    228225  /** Clears the temporary queue.
  • src/Actions/ActionRegistry.cpp

    r94232b r10aee4  
    6262  //std::cout << "ActionRegistry::ActionRegistry() called, instance is " << this << "." << std::endl;
    6363  fillRegistry();
     64  prepareAllMakroActions();
    6465  fillOptionRegistry();
    6566  completely_instatiated = true;
     
    7576  // add all MakroActions: PLEASE adhere to the alphabetical ordering
    7677  {
    77     MakroAction * presentAction =
    78         dynamic_cast<MakroAction *>(getActionByName("molecular-dynamics"));
    79     ASSERT( presentAction != NULL,
    80         "ActionRegistry::fillRegistry() - makro action has not been registered.");
    81     presentAction->unprepare(*this);
    82   }
    83   {
    84     MakroAction * presentAction =
    85         dynamic_cast<MakroAction *>(getActionByName("optimize-structure"));
    86     ASSERT( presentAction != NULL,
    87         "ActionRegistry::fillRegistry() - makro action has not been registered.");
    88     presentAction->unprepare(*this);
    89   }
    90   {
    91     MakroAction * presentAction =
    92         dynamic_cast<MakroAction *>(getActionByName("subgraph-dissection"));
    93     ASSERT( presentAction != NULL,
    94         "ActionRegistry::fillRegistry() - makro action has not been registered.");
    95     presentAction->unprepare(*this);
    96   }
    97   {
    98     MakroAction * presentAction =
    99         dynamic_cast<MakroAction *>(getActionByName("translate-molecules"));
    100     ASSERT( presentAction != NULL,
    101         "ActionRegistry::fillRegistry() - makro action has not been registered.");
    102     presentAction->unprepare(*this);
     78    MakroAction & presentAction =
     79        const_cast<MakroAction &>(
     80        dynamic_cast<const MakroAction &>(getActionByName("molecular-dynamics")));
     81    presentAction.unprepare(*this);
     82  }
     83  {
     84    MakroAction & presentAction =
     85        const_cast<MakroAction &>(
     86        dynamic_cast<const MakroAction &>(getActionByName("optimize-structure")));
     87    presentAction.unprepare(*this);
     88  }
     89  {
     90    MakroAction & presentAction =
     91        const_cast<MakroAction &>(
     92        dynamic_cast<const MakroAction &>(getActionByName("subgraph-dissection")));
     93    presentAction.unprepare(*this);
     94  }
     95  {
     96    MakroAction & presentAction =
     97        const_cast<MakroAction &>(
     98        dynamic_cast<const MakroAction &>(getActionByName("translate-molecules")));
     99    presentAction.unprepare(*this);
    103100  }
    104101
     
    124121#include BOOST_PP_LOCAL_ITERATE()
    125122#undef instance_print 
    126 
     123}
     124
     125void ActionRegistry::prepareAllMakroActions()
     126{
    127127  // now prepare each macro action that require presence of all primitive ones
    128128  {
    129     MakroAction * presentAction =
    130         dynamic_cast<MakroAction *>(getActionByName("subgraph-dissection"));
    131     ASSERT( presentAction != NULL,
    132         "ActionRegistry::fillRegistry() - makro action has not been registered.");
    133     presentAction->prepare(*this);
    134   }
    135   {
    136     MakroAction * presentAction =
    137         dynamic_cast<MakroAction *>(getActionByName("molecular-dynamics"));
    138     ASSERT( presentAction != NULL,
    139         "ActionRegistry::fillRegistry() - makro action has not been registered.");
    140     presentAction->prepare(*this);
    141   }
    142   {
    143     MakroAction * presentAction =
    144         dynamic_cast<MakroAction *>(getActionByName("optimize-structure"));
    145     ASSERT( presentAction != NULL,
    146         "ActionRegistry::fillRegistry() - makro action has not been registered.");
    147     presentAction->prepare(*this);
    148   }
    149   {
    150     MakroAction * presentAction =
    151         dynamic_cast<MakroAction *>(getActionByName("translate-molecules"));
    152     ASSERT( presentAction != NULL,
    153         "ActionRegistry::fillRegistry() - makro action has not been registered.");
    154     presentAction->prepare(*this);
     129    MakroAction & presentAction =
     130        const_cast<MakroAction &>(
     131        dynamic_cast<const MakroAction &>(getActionByName("subgraph-dissection")));
     132    presentAction.prepare(*this);
     133  }
     134  {
     135    MakroAction & presentAction =
     136        const_cast<MakroAction &>(
     137        dynamic_cast<const MakroAction &>(getActionByName("molecular-dynamics")));
     138    presentAction.prepare(*this);
     139  }
     140  {
     141    MakroAction & presentAction =
     142        const_cast<MakroAction &>(
     143        dynamic_cast<const MakroAction &>(getActionByName("optimize-structure")));
     144    presentAction.prepare(*this);
     145  }
     146  {
     147    MakroAction & presentAction =
     148        const_cast<MakroAction &>(
     149        dynamic_cast<const MakroAction &>(getActionByName("translate-molecules")));
     150    presentAction.prepare(*this);
    155151  }
    156152}
     
    227223/** Just passes on call to Registry<Action>::getByName().
    228224 * \param name name of Action
    229  * \return pointer to Action
    230  */
    231 Action* ActionRegistry::getActionByName(const std::string &name)
    232 {
    233   return getByName(name);
     225 * \return const ref to Action
     226 */
     227const Action& ActionRegistry::getActionByName(const std::string &name)
     228{
     229  Action * const action = getByName(name);
     230  ASSERT( action != NULL,
     231      "ActionRegistry::getActionByName() - action "+name+" not present!");
     232  return *action;
    234233}
    235234
  • src/Actions/ActionRegistry.hpp

    r94232b r10aee4  
    4242
    4343public:
    44   Action* getActionByName(const std::string &name);
     44  const Action& getActionByName(const std::string &name);
    4545  bool isActionPresentByName(const std::string &name) const;
    4646
     
    5959  void fillOptionRegistry() const;
    6060  void clearOptionRegistry() const;
     61  void prepareAllMakroActions();
    6162
    6263  //!> this tells whether ActionRegistry has been completed instantiated.
  • src/Actions/ActionSequence.cpp

    r94232b r10aee4  
    2222
    2323/*
    24  * ActionSequenze.cpp
     24 * ActionSequence.cpp
    2525 *
    2626 *  Created on: Dec 17, 2009
     
    6060
    6161ActionSequence::~ActionSequence()
    62 {}
    63 
    64 
    65 void ActionSequence::addAction(Action* _action){
     62{
     63  for (actionSet::iterator iter = actions.begin(); !actions.empty(); iter = actions.begin()) {
     64    delete *iter;
     65    actions.erase(iter);
     66  }
     67}
     68
     69
     70void ActionSequence::addAction(Action* _action)
     71{
     72  // actions are already clone on push as ActionRegistry hands out const refs only
    6673  actions.push_back(_action);
    6774}
    6875
    69 bool ActionSequence::removeAction(const std::string &name){
     76bool ActionSequence::removeAction(const std::string &name)
     77{
    7078  actionSet::iterator it=actions.begin();
    7179  for(; it!=actions.end(); it++){
    7280    if ((*it)->getName() == name) {
     81      delete *it;
    7382      actions.erase(it);
    7483      break;
     
    7887}
    7988
    80 Action* ActionSequence::removeLastAction(){
     89Action* ActionSequence::removeLastAction()
     90{
    8191  if(actions.empty()) {
    8292    return 0;
     
    92102// this method is used outside the ActionModule
    93103// Each action registers itself with the history
    94 Dialog* ActionSequence::fillAllDialogs(Dialog *dialog){
     104Dialog* ActionSequence::fillAllDialogs(Dialog *dialog)
     105{
    95106  for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
    96107    dialog = (*it)->fillDialog(dialog);
     
    101112// this method is used outside the ActionModule
    102113// Each action registers itself with the history
    103 void ActionSequence::callAll(){
     114void ActionSequence::callAll()
     115{
    104116  for (size_t i=0;i<loop;++i)
    105117    for(actionSet::iterator it=actions.begin(); it!=actions.end(); it++){
     
    113125// In this case only the makro Action should be registered and
    114126// handle the states
    115 ActionSequence::stateSet ActionSequence::callAll(bool){
     127ActionSequence::stateSet ActionSequence::callAll(bool)
     128{
    116129  stateSet states;
    117130  for (size_t i=0;i<loop;++i)
     
    127140}
    128141
    129 ActionSequence::stateSet ActionSequence::undoAll(stateSet states){
     142ActionSequence::stateSet ActionSequence::undoAll(stateSet states)
     143{
    130144  ASSERT(canUndo(),"Trying to undo a sequence that contains methods that can't be undone");
    131145  stateSet res;
     
    147161}
    148162
    149 ActionSequence::stateSet ActionSequence::redoAll(stateSet states){
     163ActionSequence::stateSet ActionSequence::redoAll(stateSet states)
     164{
    150165  stateSet res;
    151166  actionSet::iterator actionIt = actions.begin();
     
    164179}
    165180
    166 bool ActionSequence::canUndo(){
     181bool ActionSequence::canUndo()
     182{
    167183  bool canUndo=true;
    168184  for(std::deque<Action*>::iterator it=actions.begin(); it!=actions.end(); ++it){
     
    174190}
    175191
    176 bool ActionSequence::shouldUndo(){
     192bool ActionSequence::shouldUndo()
     193{
    177194  bool shouldUndo = false;
    178195  for(std::deque<Action*>::iterator it=actions.begin();it!=actions.end();++it){
  • src/Actions/ActionSequence.hpp

    r94232b r10aee4  
    11/*
    2  * ActionSequenze.hpp
     2 * ActionSequence.hpp
    33 *
    44 *  Created on: Dec 17, 2009
  • src/Actions/Action_impl_pre.hpp

    r94232b r10aee4  
    394394)
    395395{
    396   ACTION *ToCall = dynamic_cast<ACTION*>(ActionQueue::getInstance().getActionByName( TOKEN )); //->clone(params);
     396  ACTION * const ToCall = dynamic_cast<ACTION*>(ActionQueue::getInstance().getActionByName( TOKEN ).clone());
    397397  //ACTION::PARAMS params;
    398398#if defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
     
    411411#endif
    412412        ) {
    413   ACTION *ToCall = dynamic_cast<ACTION*>(ActionQueue::getInstance().getActionByName( TOKEN )); //->clone(params);
     413  ACTION * const ToCall = dynamic_cast<ACTION*>(ActionQueue::getInstance().getActionByName( TOKEN ).clone());
    414414  //ACTION::PARAMS params;
    415415#if defined paramtypes && defined paramtypes && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
  • src/Actions/CommandAction/HelpAction.cpp

    r94232b r10aee4  
    9292    // retrieve command from Registry and print its help
    9393    if (AQ.isActionKnownByName(params.actionname.get())) {
    94       const Action *instance = AQ.getActionByName(params.actionname.get());
     94      const Action &instance = AQ.getActionByName(params.actionname.get());
    9595      // else give description of Action and its option value if present
    96       std::cout << instance->help();
     96      std::cout << instance.help();
    9797      std::cout << std::endl;
    9898      std::cout << std::endl;
  • src/Actions/FragmentationAction/MolecularDynamicsAction.cpp

    r94232b r10aee4  
    6262  // present. If not, we still copy the position cleanly into a new step where then
    6363  // forces are set according to summed fragmentary contributions. This is much cleaner.
    64   prototype_actions.addAction(AR.getActionByName(std::string("verlet-integration")));
    65   prototype_actions.addAction(AR.getActionByName(std::string("output")));
    66   prototype_actions.addAction(AR.getActionByName(std::string("clear-fragment-results")));
    67   prototype_actions.addAction(AR.getActionByName(std::string("destroy-adjacency")));
    68   prototype_actions.addAction(AR.getActionByName(std::string("create-adjacency")));
    69   prototype_actions.addAction(AR.getActionByName(std::string("correct-bonddegree")));
    70   prototype_actions.addAction(AR.getActionByName(std::string("update-molecules")));
    71   prototype_actions.addAction(AR.getActionByName(std::string("fragment-molecule")));
    72   prototype_actions.addAction(AR.getActionByName(std::string("fragment-automation")));
    73   prototype_actions.addAction(AR.getActionByName(std::string("analyse-fragment-results")));
     64  prototype_actions.addAction(AR.getActionByName(std::string("verlet-integration")).clone());
     65  prototype_actions.addAction(AR.getActionByName(std::string("output")).clone());
     66  prototype_actions.addAction(AR.getActionByName(std::string("clear-fragment-results")).clone());
     67  prototype_actions.addAction(AR.getActionByName(std::string("destroy-adjacency")).clone());
     68  prototype_actions.addAction(AR.getActionByName(std::string("create-adjacency")).clone());
     69  prototype_actions.addAction(AR.getActionByName(std::string("correct-bonddegree")).clone());
     70  prototype_actions.addAction(AR.getActionByName(std::string("update-molecules")).clone());
     71  prototype_actions.addAction(AR.getActionByName(std::string("fragment-molecule")).clone());
     72  prototype_actions.addAction(AR.getActionByName(std::string("fragment-automation")).clone());
     73  prototype_actions.addAction(AR.getActionByName(std::string("analyse-fragment-results")).clone());
    7474  isPrepared = true;
    7575}
     
    7878{
    7979  // empty sequence
    80   while (prototype_actions.removeLastAction() != NULL);
     80  Action *actionremove = NULL;
     81  while ((actionremove = prototype_actions.removeLastAction()) != NULL)
     82    delete actionremove;
    8183  isPrepared = false;
    8284}
  • src/Actions/FragmentationAction/StructuralOptimizationAction.cpp

    r94232b r10aee4  
    6262  // present. If not, we still copy the position cleanly into a new step where then
    6363  // forces are set according to summed fragmentary contributions. This is much cleaner.
    64   prototype_actions.addAction(AR.getActionByName(std::string("destroy-adjacency")));
    65   prototype_actions.addAction(AR.getActionByName(std::string("create-adjacency")));
    66   prototype_actions.addAction(AR.getActionByName(std::string("correct-bonddegree")));
    67   prototype_actions.addAction(AR.getActionByName(std::string("update-molecules")));
    68   prototype_actions.addAction(AR.getActionByName(std::string("fragment-molecule")));
    69   prototype_actions.addAction(AR.getActionByName(std::string("fragment-automation")));
    70   prototype_actions.addAction(AR.getActionByName(std::string("analyse-fragment-results")));
    71   prototype_actions.addAction(AR.getActionByName(std::string("force-annealing")));
    72   prototype_actions.addAction(AR.getActionByName(std::string("output")));
    73   prototype_actions.addAction(AR.getActionByName(std::string("clear-fragment-results")));
     64  prototype_actions.addAction(AR.getActionByName(std::string("destroy-adjacency")).clone());
     65  prototype_actions.addAction(AR.getActionByName(std::string("create-adjacency")).clone());
     66  prototype_actions.addAction(AR.getActionByName(std::string("correct-bonddegree")).clone());
     67  prototype_actions.addAction(AR.getActionByName(std::string("update-molecules")).clone());
     68  prototype_actions.addAction(AR.getActionByName(std::string("fragment-molecule")).clone());
     69  prototype_actions.addAction(AR.getActionByName(std::string("fragment-automation")).clone());
     70  prototype_actions.addAction(AR.getActionByName(std::string("analyse-fragment-results")).clone());
     71  prototype_actions.addAction(AR.getActionByName(std::string("force-annealing")).clone());
     72  prototype_actions.addAction(AR.getActionByName(std::string("output")).clone());
     73  prototype_actions.addAction(AR.getActionByName(std::string("clear-fragment-results")).clone());
    7474  isPrepared = true;
    7575}
     
    7878{
    7979  // empty sequence
    80   while (prototype_actions.removeLastAction() != NULL);
     80  Action *actionremove = NULL;
     81  while ((actionremove = prototype_actions.removeLastAction()) != NULL)
     82    delete actionremove;
    8183  isPrepared = false;
    8284}
  • src/Actions/GraphAction/SubgraphDissectionAction.cpp

    r94232b r10aee4  
    6363void GraphSubgraphDissectionAction::prepare(ActionRegistry &AR)
    6464{
    65   prototype_actions.addAction(AR.getActionByName(std::string("push-atom-selection")));
    66   prototype_actions.addAction(AR.getActionByName(std::string("select-all-atoms")));
    67   prototype_actions.addAction(AR.getActionByName(std::string("destroy-adjacency")));
    68   prototype_actions.addAction(AR.getActionByName(std::string("create-adjacency")));
    69   prototype_actions.addAction(AR.getActionByName(std::string("update-molecules")));
    70   prototype_actions.addAction(AR.getActionByName(std::string("pop-atom-selection")));
     65  prototype_actions.addAction(AR.getActionByName(std::string("push-atom-selection")).clone());
     66  prototype_actions.addAction(AR.getActionByName(std::string("select-all-atoms")).clone());
     67  prototype_actions.addAction(AR.getActionByName(std::string("destroy-adjacency")).clone());
     68  prototype_actions.addAction(AR.getActionByName(std::string("create-adjacency")).clone());
     69  prototype_actions.addAction(AR.getActionByName(std::string("update-molecules")).clone());
     70  prototype_actions.addAction(AR.getActionByName(std::string("pop-atom-selection")).clone());
    7171  isPrepared = true;
    7272}
     
    7575{
    7676  // empty sequence
    77   while (prototype_actions.removeLastAction() != NULL);
     77  Action *actionremove = NULL;
     78  while ((actionremove = prototype_actions.removeLastAction()) != NULL)
     79    delete actionremove;
    7880  isPrepared = false;
    7981}
  • src/Actions/MakroAction.cpp

    r94232b r10aee4  
    7474MakroAction::~MakroAction()
    7575{
    76   // emptying the sequence is someone else responsibility
    77 //  Action* action;
    78 //  while((action=actions.removeLastAction())){
    79 //    delete action;
    80 //  }
     76  // emptying the sequence is done in ActionSequence
    8177}
    8278
  • src/Actions/MakroAction.hpp

    r94232b r10aee4  
    3737  MakroAction(const MakroAction &_instance);
    3838  MakroAction(const ActionTrait &_trait,ActionSequence& _actions);
    39   virtual ~MakroAction();
    4039
    4140  bool canUndo();
     
    5655
    5756protected:
     57  virtual ~MakroAction();
     58
    5859  /**
    5960   * MakroAction requires an own dialog for global options such as number of loop
  • src/Actions/MakroAction_impl_pre.hpp

    r94232b r10aee4  
    362362)
    363363{
    364   ACTION *ToCall = dynamic_cast<ACTION*>(ActionQueue::getInstance().getActionByName( TOKEN )); //->clone(params);
     364  ACTION * const ToCall = dynamic_cast<ACTION*>(ActionQueue::getInstance().getActionByName( TOKEN ).clone());
    365365  //ACTION::PARAMS params;
    366366#if defined paramreferences && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
     
    379379#endif
    380380        ) {
    381   ACTION *ToCall = dynamic_cast<ACTION*>(ActionQueue::getInstance().getActionByName( TOKEN )); //->clone(params);
     381  ACTION * const ToCall = dynamic_cast<ACTION*>(ActionQueue::getInstance().getActionByName( TOKEN ).clone());
    382382  //ACTION::PARAMS params;
    383383#if defined paramtypes && defined paramtypes && BOOST_PP_NOT_EQUAL(MAXPARAMTYPES,0)
  • src/Actions/MoleculeAction/TranslateAction.cpp

    r94232b r10aee4  
    6363  // we simply have to select all the molecule's atoms and use the respective
    6464  // translate Action
    65   prototype_actions.addAction(AR.getActionByName(std::string("push-atom-selection")));
    66   prototype_actions.addAction(AR.getActionByName(std::string("select-molecules-atoms")));
    67   prototype_actions.addAction(AR.getActionByName(std::string("translate-atoms")));
    68   prototype_actions.addAction(AR.getActionByName(std::string("pop-atom-selection")));
     65  prototype_actions.addAction(AR.getActionByName(std::string("push-atom-selection")).clone());
     66  prototype_actions.addAction(AR.getActionByName(std::string("select-molecules-atoms")).clone());
     67  prototype_actions.addAction(AR.getActionByName(std::string("translate-atoms")).clone());
     68  prototype_actions.addAction(AR.getActionByName(std::string("pop-atom-selection")).clone());
    6969  isPrepared = true;
    7070}
     
    7373{
    7474  // empty sequence
    75   while (prototype_actions.removeLastAction() != NULL);
     75  Action *actionremove = NULL;
     76  while ((actionremove = prototype_actions.removeLastAction()) != NULL)
     77    delete actionremove;
    7678  isPrepared = false;
    7779}
  • src/Actions/unittests/ActionSequenceUnitTest.cpp

    r94232b r10aee4  
    239239    {
    240240      ActionSequence *sequence = new ActionSequence();
    241       sequence->addAction(positive1);
    242       sequence->addAction(positive2);
     241      sequence->addAction(positive1->clone());
     242      sequence->addAction(positive2->clone());
    243243      CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
    244244      delete sequence;
     
    246246    {
    247247      ActionSequence *sequence = new ActionSequence();
    248       sequence->addAction(positive1);
    249       sequence->addAction(negative2);
     248      sequence->addAction(positive1->clone());
     249      sequence->addAction(negative2->clone());
    250250      CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
    251251      delete sequence;
     
    253253    {
    254254      ActionSequence *sequence = new ActionSequence();
    255       sequence->addAction(negative1);
    256       sequence->addAction(positive2);
     255      sequence->addAction(negative1->clone());
     256      sequence->addAction(positive2->clone());
    257257      CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
    258258      delete sequence;
     
    260260    {
    261261      ActionSequence *sequence = new ActionSequence();
    262       sequence->addAction(negative1);
    263       sequence->addAction(negative2);
     262      sequence->addAction(negative1->clone());
     263      sequence->addAction(negative2->clone());
    264264      CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
    265265      delete sequence;
     
    273273    CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
    274274    // if only a positive action is contained it can be undone
    275     sequence->addAction(positive1);
     275    sequence->addAction(positive1->clone());
    276276    CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
    277277    // the single negative action should block the process
    278     sequence->addAction(negative1);
     278    sequence->addAction(negative1->clone());
    279279    CPPUNIT_ASSERT_EQUAL( false, sequence->canUndo() );
    280280    // after removing the negative action all is well again
    281     sequence->removeLastAction();
     281    delete sequence->removeLastAction();
    282282    CPPUNIT_ASSERT_EQUAL( true, sequence->canUndo() );
    283283    delete sequence;
     
    287287void ActionSequenceTest::doesCallTest(){
    288288  ActionSequence *sequence = new ActionSequence();
    289   sequence->addAction(shouldCall1);
    290   sequence->addAction(shouldCall2);
    291   sequence->addAction(shouldNotCall1);
    292   sequence->addAction(shouldNotCall2);
    293   sequence->removeLastAction();
    294   sequence->removeLastAction();
     289  sequence->addAction(shouldCall1->clone());
     290  sequence->addAction(shouldCall2->clone());
     291  sequence->addAction(shouldNotCall1->clone());
     292  sequence->addAction(shouldNotCall2->clone());
     293  delete sequence->removeLastAction();
     294  delete sequence->removeLastAction();
    295295
    296296  sequence->callAll();
    297297
    298   CPPUNIT_ASSERT_EQUAL(true,shouldCall1->wasCalled());
    299   CPPUNIT_ASSERT_EQUAL(true,shouldCall2->wasCalled());
    300   CPPUNIT_ASSERT_EQUAL(false,shouldNotCall1->wasCalled());
    301   CPPUNIT_ASSERT_EQUAL(false,shouldNotCall2->wasCalled());
     298  ActionSequence::actionSet::const_iterator iter = sequence->actions.begin();
     299  CPPUNIT_ASSERT_EQUAL(true,dynamic_cast<wasCalledActionStub *>(*iter++)->wasCalled());
     300  CPPUNIT_ASSERT_EQUAL(true,dynamic_cast<wasCalledActionStub *>(*iter++)->wasCalled());
     301  CPPUNIT_ASSERT( iter == sequence->actions.end() );
    302302
    303303  delete sequence;
  • src/UIElements/Menu/TextMenu/ActionMenuItem.cpp

    r94232b r10aee4  
    5757
    5858bool ActionMenuItem::isActive() const {
    59   Action* action = ActionQueue::getInstance().getActionByName(ActionName);
    60   return action->isActive();
     59  const Action& action = ActionQueue::getInstance().getActionByName(ActionName);
     60  return action.isActive();
    6161}
  • src/UIElements/TextUI/TextWindow.cpp

    r94232b r10aee4  
    8686
    8787  // save has reserved key 's'
    88 //  Action *saveConfigAction = ActionQueue::getInstance().getActionByName("output");
     88//  const Action &saveConfigAction = ActionQueue::getInstance().getActionByName("output");
    8989  new ActionMenuItem('s',"save current setup to config files",main_menu->getMenuInstance(),"output");
    9090
  • src/documentation/constructs/actions.dox

    r94232b r10aee4  
    3434 *  If an Action is requested via its known token from the ActionQueue
    3535 *  (that contains the ActionRegistry), this prototype is cloned and added to the
    36  *  queue.
     36 *  queue. Action::clone() is a public function but only certain classes are
     37 *  allowed to directly add Action instances to the ActionQueue. Normally, an
     38 *  Action first has to be registered with the ActionRegistry and afterwards it
     39 *  may be added to the queue via its specific and unique token.
    3740 *
    3841 *  Each Action can contain multiple \ref parameters in its specific
     
    5659 *    such that the ActionRegistry knows about it and can instantiate a
    5760 *    prototype.
     61 *
     62 *  Most of the magic that fills in the remaining gaps of the Action's
     63 *  declaration and definition is done by boost::preprocessor magic in the
     64 *  files Action_impl_pre.hpp and Action_impl_header.hpp. There is a pendant
     65 *  for MakroActions.
     66 *
     67 * \section actions-types Specific types of actions
     68 *
     69 *  There are some special types of Actions:
     70 *  -# Calculation: A process with a final result that can be requested
     71 *  -# MakroAction: A chain of other Actions to be executed various times
     72 *  -# MethodAction: An action that basically calls a certain bound method
     73 *  -# Process: An action that takes some time to complete and informs about
     74 *     how much work remains
     75 *
     76 * \section actions-types-add Add a specific types of action ...
     77 *
     78 *  Instantiating the MakroAction is simple, only two functions, prepare()
     79 *  and unprepare(), are required that fill und empty the chain of Actions
     80 *  from Actions from the ActionRegistry.
     81 *
     82 *  Adding a Process is much the same as adding a normal Action. There is a
     83 *  keyword BASECLASS in the associated \b .def file which should say Process
     84 *  and one needs to use Process::setCurrStep(int) to tell the Process and
     85 *  all listening Observers what the current stage of execution is. Also,
     86 *  initially a total number of steps must be stated via Process::setMaxSteps()
     87 *  When the job executes, this is initiated with Process::start() and when
     88 *  it stops, this is told via Process::stop().
     89 *
     90 *  A Calculation must be derived by hand and is not supported via the
     91 *  boost::preprocessor magic but behaves very similar to the Process itself
     92 *  with respect to informing about the current stage of execution. What's
     93 *  more is essentially the Calculation::doCalc() function that performs the
     94 *  actual calculation (must not changed the state of the World and hence
     95 *  there is not need for undo). The Calculation implementation takes care
     96 *  of the rest.
     97 *
     98 *  A MethodAction is simply implemented by filling an ActionTraits structure
     99 *  with the desired values and bind a method that should get executed.
     100 *  Instantating the MethodAction with these parameters and executing
     101 *  ActionRegistry()::registerAction() then allows for using it in the context
     102 *  of the ActionQueue.
    58103 *
    59104 * \section actions-undo-redo Undoing and Redoing actions ...
     
    81126 *
    82127 *
    83  *  \date 2014-03-10
     128 *  \date 2015-08-03
    84129 *
    85130 */
Note: See TracChangeset for help on using the changeset viewer.