Ignore:
Timestamp:
Apr 24, 2010, 3:27:00 PM (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:
033a05
Parents:
8a34392
Message:

Added methods for specialized Notifications from the Observer Framework

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/Observer.hpp

    r8a34392 rccacba  
    2929
    3030class Observable;
     31class Notification;
     32
     33// Pointers to notifications are used for unique identification
     34// using this typedef makes it hard for others to mess up this
     35// identification process
     36typedef Notification *const Notification_ptr;
    3137
    3238/**
     
    4652{
    4753  friend class Observable;
     54  friend class Notification;
    4855public:
    4956  Observer();
     
    5562   */
    5663  virtual void update(Observable *publisher)=0;
     64
     65  /**
     66   * This method is called when a special named change
     67   * of the Observable occured
     68   */
     69  virtual void recieveNotification(Observable *publisher, Notification_ptr notification);
    5770
    5871  /**
     
    96109
    97110  /**
     111   * Sign on for specialized notifications
     112   */
     113  virtual void signOn(Observer *target, Notification_ptr notification);
     114
     115  /**
     116   * Stop receiving a specialized notification
     117   */
     118  virtual void signOff(Observer *target, Notification_ptr notification);
     119
     120  /**
    98121   * Ask an Observer if it is currently in a blocked state, i.e. if
    99122   * Changes are in Progress, that are not yet published.
     
    119142  static void finish_observer_internal(Observable *publisher);
    120143
     144  static void enque_notification_internal(Observable *publisher, Notification_ptr notification);
     145
    121146private:
    122147  typedef std::multimap<int,Observer*> callees_t;
     148  typedef std::set<Notification*> notificationSet;
    123149  static std::map<Observable*, int> depth;
    124150  static std::map<Observable*,callees_t*> callTable;
     151  static std::map<Observable*,notificationSet> notifications;
    125152  static std::set<Observable*> busyObservables;
     153
    126154
    127155  //! @cond
     
    143171};
    144172
     173class Notification {
     174  friend class Observable;
     175public:
     176  Notification(Observable *_owner);
     177  virtual ~Notification();
     178protected:
     179
     180  void addObserver(Observer *target);
     181  void removeObserver(Observer *target);
     182
     183  void notifyAll();
     184private:
     185  Observable * const owner;
     186  std::set<Observer*> targets;
     187};
     188
    145189// extra macro is necessary to work with __LINE__
    146190#define PASTE(a,b) PASTE_HELPER(a,b)
    147191#define PASTE_HELPER(a,b) a ## b
    148192#define OBSERVE Observable::_Observable_protector PASTE(_scope_obs_protector_,__LINE__)(this)
    149 // deprecated macros from before RAII was used
    150 //#define START_OBSERVER Observable::start_observer_internal(this);do{do{}while(0)
    151 //#define FINISH_OBSERVER }while(0);Observable::finish_observer_internal(this)
    152 //#define RETURN_OBSERVER( retval ) do{Observable::finish_observer_internal(this); return (retval);}while(0)
     193#define NOTIFY(notification) do{Observable::enque_notification_internal(this,notification);}while(0)
     194
    153195#endif /* OBSERVER_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.