Changeset 126867


Ignore:
Timestamp:
Sep 19, 2013, 8:23:52 PM (11 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:
05c989
Parents:
d649b7
git-author:
Frederik Heber <heber@…> (08/20/13 15:45:30)
git-committer:
Frederik Heber <heber@…> (09/19/13 20:23:52)
Message:

Actions no longer register themselves, ActionQueue::addAction() introduced.

  • eventually, Actions should be constrained to the ActionQueue alone. They may be created externally but their control has to be delivered to the ActionQueue.
  • Hence, we reversed the registering process: Actions do not register themselves with the ActionRegistry but as almost all are created in ActionRegistry::fillRegistry() they are registered there as well.
  • Actions cstor and dstor are now protected, ActionRegistry is friend.
  • Action needs to befriend Registry<T> and ActionSequenceTest to grant access to dstor.
Location:
src
Files:
30 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/Action.cpp

    rd649b7 r126867  
    7575ActionState::ptr Action::failure;
    7676
    77 Action::Action(const ActionTrait &_Traits, ActionRegistry * const _AR) :
    78     Traits(_Traits),
    79     AR(_AR)
    80 {
    81   // register with ActionRegistry
    82   if(AR != NULL) {
    83     AR->registerInstance(this);
    84   }
    85 
     77Action::Action(const ActionTrait &_Traits) :
     78    Traits(_Traits)
     79{
    8680  // register with OptionRegistry
    8781  for (ActionTrait::options_const_iterator optioniter = Traits.getBeginIter();
     
    128122Action::~Action()
    129123{
    130   // unregister us if still registered
    131   if (AR != NULL)
    132     AR->unregisterInstance(this);
    133 
    134124  for (ActionTrait::options_const_iterator optioniter = Traits.getBeginIter();
    135125      optioniter != Traits.getEndIter();
  • src/Actions/Action.hpp

    rd649b7 r126867  
    2525
    2626// forward declaration
     27template <typename T> class Registry;
    2728
    2829namespace MoleCuilder {
     30  class ActionHistory;
    2931  class ActionRegistry;
    3032  class ActionSequence;
    3133}
     34class ActionSequenceTest;
    3235class Dialog;
    3336
     
    8083class Action
    8184{
    82 friend class ActionSequence;
    83 friend class ActionHistory;
     85  friend class ActionHistory;
     86  friend class ActionRegistry;
     87  friend class ActionSequence;
     88  template <typename T> friend class ::Registry;
     89  //!> TextMenu needs to instantiate some specific Actions, grant access to cstor
     90  friend class TextMenu;
     91
     92  // some unit tests on Actions
     93  friend class ::ActionSequenceTest;
    8494public:
    8595
    8696  enum QueryOptions {Interactive, NonInteractive};
    8797
     98protected:
    8899  /**
    89100   * Standard constructor of Action Base class
     
    97108   *
    98109   * \param Traits information class to this action
    99    * \param _AR pointer to ActionRegistry to register, NULL - do not register
    100    */
    101   Action(const ActionTrait &_Traits, ActionRegistry * const _AR = NULL);
     110   */
     111  Action(const ActionTrait &_Traits);
    102112  virtual ~Action();
    103113
     114public:
    104115  /**
    105116   * This method is used to call an action. The basic operations for the Action
     
    163174  const ActionTrait Traits;
    164175
    165   /** Action is registered with an ActionRegistry and stores its pointer internally.
    166    *
    167    */
    168   ActionRegistry* const AR;
    169 
    170176protected:
    171177  /** Removes the static entities Action::success and Action::failure.
  • src/Actions/ActionQueue.cpp

    rd649b7 r126867  
    6969}
    7070
     71void ActionQueue::registerAction(Action *_action)
     72{
     73  AR->registerInstance(_action);
     74}
     75
    7176const ActionTrait& ActionQueue::getActionsTrait(const std::string &name) const
    7277{
  • src/Actions/ActionQueue.hpp

    rd649b7 r126867  
    5555  bool isActionKnownByName(const std::string &name) const;
    5656
     57  /** Register an Action with the ActionRegistry.
     58   *
     59   * \param _action action to add
     60   */
     61  void registerAction(Action *_action);
     62
    5763  /** Returns the vector with the tokens of all currently known Actions.
    5864   *
     
    6773   */
    6874  const ActionTrait& getActionsTrait(const std::string &name) const;
    69 
    70   /** Getter function for the ActionRegistry for transitional purpose.
    71    *
    72    * \return ref to internal ActionRegistry
    73    */
    74   ActionRegistry& getActionRegistry() {
    75     return *AR;
    76   }
    7775
    7876  /** Undoes last called Action.
  • src/Actions/Action_impl_pre.hpp

    rd649b7 r126867  
    234234// =========== constructor ===========
    235235ACTION::ACTION () :
    236   Action(ActionTraits< ACTION >(), NULL)
     236  Action(ActionTraits< ACTION >())
    237237{}
    238238
  • src/Actions/AtomsCalculation_impl.hpp

    rd649b7 r126867  
    2222template<typename T>
    2323AtomsCalculation<T>::AtomsCalculation(boost::function<T(atom*)> _op,const ActionTrait &_trait,AtomDescriptor _descr) :
    24   Calculation<std::vector<T> >(0,_trait,NULL),
     24  Calculation<std::vector<T> >(0,_trait),
    2525  descr(_descr),
    2626  op(_op)
  • src/Actions/Calculation.hpp

    rd649b7 r126867  
    3030{
    3131public:
    32   Calculation(int _maxSteps, const ActionTrait &_trait, ActionRegistry * const _AR);
     32  Calculation(int _maxSteps, const ActionTrait &_trait);
    3333  virtual ~Calculation();
    3434
  • src/Actions/Calculation_impl.hpp

    rd649b7 r126867  
    2222
    2323template<typename T>
    24 Calculation<T>::Calculation(int _maxSteps, const ActionTrait &_trait, ActionRegistry * const _AR) :
    25   Process(_maxSteps,_trait,_AR),
     24Calculation<T>::Calculation(int _maxSteps, const ActionTrait &_trait) :
     25  Process(_maxSteps,_trait),
    2626  result(0),
    2727  done(false)
  • src/Actions/ErrorAction.cpp

    rd649b7 r126867  
    4444using namespace MoleCuilder;
    4545
    46 ErrorAction::ErrorAction(const ActionTrait &_trait,const char * _errorMsg, ActionRegistry * const _AR) :
    47 Action(_trait,_AR),
     46ErrorAction::ErrorAction(const ActionTrait &_trait,const char * _errorMsg) :
     47Action(_trait),
    4848errorMsg(_errorMsg)
    4949{
  • src/Actions/ErrorAction.hpp

    rd649b7 r126867  
    2323{
    2424public:
    25   ErrorAction(const ActionTrait &_trait,const char * _errorMsg, ActionRegistry * const _AR);
     25  ErrorAction(const ActionTrait &_trait,const char * _errorMsg);
    2626  virtual ~ErrorAction();
    2727
  • src/Actions/GraphAction/SubgraphDissectionAction.cpp

    rd649b7 r126867  
    7878
    7979GraphSubgraphDissectionAction::GraphSubgraphDissectionAction() :
    80   MakroAction(ActionTraits< GraphSubgraphDissectionAction >(), actions, false)
     80  MakroAction(ActionTraits< GraphSubgraphDissectionAction >(), actions)
    8181{}
    8282
  • src/Actions/MakroAction.cpp

    rd649b7 r126867  
    6161};
    6262
    63 MakroAction::MakroAction(const ActionTrait &_trait,ActionSequence& _actions, ActionRegistry * const _AR) :
    64 Action(_trait,_AR),
    65 actions(_actions)
     63MakroAction::MakroAction(const ActionTrait &_trait,ActionSequence& _actions) :
     64    Action(_trait),
     65    actions(_actions)
    6666{
    6767}
  • src/Actions/MakroAction.hpp

    rd649b7 r126867  
    3131{
    3232public:
    33   MakroAction(const ActionTrait &_trait,ActionSequence& _actions, ActionRegistry * const _AR=NULL);
     33  MakroAction(const ActionTrait &_trait,ActionSequence& _actions);
    3434  virtual ~MakroAction();
    3535
  • src/Actions/MakroAction_impl_pre.hpp

    rd649b7 r126867  
    235235// =========== constructor ===========
    236236ACTION::ACTION () :
    237   MakroAction(ActionTraits< ACTION >(), actions, NULL)
     237  MakroAction(ActionTraits< ACTION >(), actions)
    238238{}
    239239
  • src/Actions/ManipulateAtomsProcess.cpp

    rd649b7 r126867  
    4747    boost::function<void(atom*)> _operation,
    4848    AtomDescriptor _descr,
    49     const ActionTrait &_trait,
    50     ActionRegistry * const _AR) :
    51   Process(0,_trait,_AR),
     49    const ActionTrait &_trait) :
     50  Process(0,_trait),
    5251  descr(_descr),
    5352  operation(_operation)
  • src/Actions/ManipulateAtomsProcess.hpp

    rd649b7 r126867  
    3030{
    3131public:
    32   ManipulateAtomsProcess(boost::function<void(atom*)> _operation, AtomDescriptor descr,const ActionTrait &_trait,ActionRegistry * const _AR);
     32  ManipulateAtomsProcess(boost::function<void(atom*)> _operation, AtomDescriptor descr,const ActionTrait &_trait);
    3333  virtual ~ManipulateAtomsProcess();
    3434
  • src/Actions/MethodAction.cpp

    rd649b7 r126867  
    4444using namespace MoleCuilder;
    4545
    46 MethodAction::MethodAction(const ActionTrait &_trait,boost::function<void()> _executeMethod,ActionRegistry * const _AR) :
    47    Action(_trait,_AR),
     46MethodAction::MethodAction(const ActionTrait &_trait,boost::function<void()> _executeMethod) :
     47   Action(_trait),
    4848executeMethod(_executeMethod)
    4949{
  • src/Actions/MethodAction.hpp

    rd649b7 r126867  
    2929{
    3030public:
    31   MethodAction(const ActionTrait &_trait,boost::function<void()> _executeMethod,ActionRegistry * const _AR);
     31  MethodAction(const ActionTrait &_trait,boost::function<void()> _executeMethod);
    3232  virtual ~MethodAction();
    3333  virtual bool canUndo();
  • src/Actions/OptionRegistry.hpp

    rd649b7 r126867  
    2828 *
    2929 */
    30 class OptionRegistry : public Singleton<OptionRegistry>, public Registry<OptionTrait>
     30class OptionRegistry : public Singleton<OptionRegistry>, public ::Registry<OptionTrait>
    3131{
    3232  friend class Singleton<OptionRegistry>;
  • src/Actions/Process.cpp

    rd649b7 r126867  
    4141using namespace MoleCuilder;
    4242
    43 Process::Process(int _maxSteps, const ActionTrait &_trait, ActionRegistry * const _AR) :
    44   Action(_trait,_AR),
     43Process::Process(int _maxSteps, const ActionTrait &_trait) :
     44  Action(_trait),
    4545  Observable("Process"),
    4646  maxSteps(_maxSteps),
  • src/Actions/Process.hpp

    rd649b7 r126867  
    5151{
    5252public:
    53   Process(int _maxSteps, const ActionTrait &_trait, ActionRegistry * const _AR);
     53  Process(int _maxSteps, const ActionTrait &_trait);
    5454  virtual ~Process();
    5555
  • src/Actions/Reaction.hpp

    rd649b7 r126867  
    3030{
    3131public:
    32   Reaction(const ActionTrait &_trait, ActionRegistry * const _AR=NULL);
     32  Reaction(const ActionTrait &_trait);
    3333  virtual ~Reaction();
    3434
  • src/Actions/Reaction_impl.hpp

    rd649b7 r126867  
    2323
    2424template<typename T>
    25 Reaction<T>::Reaction(const ActionTrait &_trait, ActionRegistry * const _AR) :
    26   Action(_trait,_AR),
     25Reaction<T>::Reaction(const ActionTrait &_trait) :
     26  Action(_trait),
    2727  result(0),
    2828  done(false)
  • src/Actions/Reaction_impl_pre.hpp

    rd649b7 r126867  
    163163// =========== constructor ===========
    164164REACTION::REACTION () :
    165   Reaction< RETURNTYPE >(ActionTraits< REACTION >(), NULL)
     165  Reaction< RETURNTYPE >(ActionTraits< REACTION >())
    166166{}
    167167
  • src/Actions/unittests/ActionSequenceUnitTest.cpp

    rd649b7 r126867  
    6262public:
    6363  canUndoActionStub(const ActionTrait &_trait):
    64     Action(_trait,NULL){}
     64    Action(_trait){}
    6565  virtual ~canUndoActionStub(){}
    6666
     
    9191public:
    9292  cannotUndoActionStub(const ActionTrait &_trait) :
    93     Action(_trait,NULL){}
     93    Action(_trait){}
    9494  virtual ~cannotUndoActionStub(){}
    9595
     
    120120public:
    121121  wasCalledActionStub(const ActionTrait &_trait) :
    122       Action(_trait,NULL),
     122      Action(_trait),
    123123      called(false)
    124124  {}
     
    277277
    278278  ActionTrait MakroTrait("Test MakroAction");
    279   MakroAction act(MakroTrait,*sequence,NULL);
     279  MakroAction act(MakroTrait,*sequence);
    280280
    281281  act.call();
  • src/UIElements/Menu/TextMenu/TextMenu.hpp

    rd649b7 r126867  
    155155        token,
    156156        lastposition(token)+2); // have a separator in between
    157     new TxMenu::LeaveAction(NewMenu->getMenuInstance(), leaveTrait);
     157    MoleCuilder::Action *_action = new TxMenu::LeaveAction(NewMenu->getMenuInstance(), leaveTrait);
     158    MoleCuilder::ActionQueue::getInstance().registerAction(_action);
    158159    NewMenu->init();
    159160    new ActionMenuItem('q',"leave"+token,NewMenu->getMenuInstance(),"leave"+token);
  • src/UIElements/Menu/TextMenu/TxMenuLeaveAction.cpp

    rd649b7 r126867  
    4848 */
    4949TxMenu::LeaveAction::LeaveAction(TxMenu* const _menu, const ActionTrait & LeaveActionTrait) :
    50   Action(LeaveActionTrait, &ActionQueue::getInstance().getActionRegistry()),
     50  Action(LeaveActionTrait),
    5151  menu(_menu)
    5252{}
  • src/UIElements/TextUI/TextWindow.cpp

    rd649b7 r126867  
    9191  // create a specific quit action for this UI and store in registry
    9292  ActionTrait quitTrait(OptionTrait("quit", &typeid(void), "quits the program"));
    93   quitAction = new MethodAction(quitTrait,boost::bind(&TxMenu::doQuit,main_menu->getMenuInstance()),&ActionQueue::getInstance().getActionRegistry());
     93  quitAction = new MethodAction(quitTrait,boost::bind(&TxMenu::doQuit,main_menu->getMenuInstance()));
     94  MoleCuilder::ActionQueue::getInstance().registerAction(quitAction);
    9495  new ActionMenuItem('q',"quit",main_menu->getMenuInstance(),"quit");
    9596
     
    100101TextWindow::~TextWindow()
    101102{
    102   for (std::list<Action *>::iterator iter = returnFromActions.begin();
    103       !returnFromActions.empty();
    104       iter = returnFromActions.begin()) {
    105     delete (*iter);
    106     returnFromActions.erase(iter);
    107   }
    108103  delete moleculeView;
    109104  delete statusIndicator;
  • src/UIElements/TextUI/TextWindow.hpp

    rd649b7 r126867  
    4141  TextMenu<TxMenu> *main_menu;
    4242
    43   // some actions only needed in textMenus
    44   std::list<MoleCuilder::Action *> returnFromActions;
    4543  MoleCuilder::Action *quitAction;
    4644  // all views that are contained in the main Menu
  • src/World.cpp

    rd649b7 r126867  
    373373ManipulateAtomsProcess* World::manipulateAtoms(boost::function<void(atom*)> op,std::string name,AtomDescriptor descr){
    374374  ActionTrait manipulateTrait(name);
    375   return new ManipulateAtomsProcess(op, descr,manipulateTrait,NULL);
     375  return new ManipulateAtomsProcess(op, descr,manipulateTrait);
    376376}
    377377
Note: See TracChangeset for help on using the changeset viewer.