Changeset 317df8
- Timestamp:
- Feb 3, 2010, 4:31:45 PM (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:
- 2ba827
- Parents:
- 5d1611
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/Observer.cpp
r5d1611 r317df8 51 51 depth.erase(publisher); 52 52 } 53 } 54 55 Observable::_Observable_protector::_Observable_protector(Observable *_protege) : 56 protege(_protege) 57 { 58 start_observer_internal(protege); 59 } 60 61 Observable::_Observable_protector::~_Observable_protector() 62 { 63 finish_observer_internal(protege); 53 64 } 54 65 -
src/Patterns/Observer.hpp
r5d1611 r317df8 16 16 * 17 17 * Observers register themselves with the observables to be notified when something changes. 18 * In the Observable code that changes attributes should be wrapped in 19 * START_OBSERVER ... END_OBSERVER blocks. If other methods are called that also contain 20 * Observation blocks from there, these functions wont trigger notifications. Only the end 21 * of the final observation block triggers the update of Observers. 22 * 23 * Returning from observed code should be done using the RETURN_OBSERVER() macro. This way the Observer mechanism 24 * is notified that the method is left. 18 * In the Observable code that changes attributes should be started with OBSERVE;. This macro 19 * locks the observer mechanism while changes are done. At the end of the scope in which the 20 * macro was placed the lock is released. When the last lock is released all changes are 21 * propagated to the observers. 25 22 * 26 23 * Each observerable can have sub-observables. When one of these sub-observables changes and … … 62 59 /** 63 60 * Internal method. 64 * Do not call directly. Use START_OBSERVERmacro instead61 * Do not call directly. Use OBSERVE macro instead 65 62 */ 66 63 static void start_observer_internal(Observable *publisher); 67 64 /** 68 65 * Internal method. 69 * Do not call directly. Use FINISH_OBSERVERmacro instead66 * Do not call directly. Use OBSERVE macro instead 70 67 */ 71 68 static void finish_observer_internal(Observable *publisher); … … 76 73 static std::map<Observable*,callees_t*> callTable; 77 74 static std::set<Observable*> busyObservables; 75 76 // Structure for RAII-Style notification 77 protected: 78 class _Observable_protector { 79 public: 80 _Observable_protector(Observable *); 81 ~_Observable_protector(); 82 private: 83 Observable *protege; 84 }; 78 85 }; 79 86 80 87 81 88 #define OBSERVE Observable::_Observable_protector _scope_obs_protector(this) 82 89 #define START_OBSERVER Observable::start_observer_internal(this);do{do{}while(0) 83 90 #define FINISH_OBSERVER }while(0);Observable::finish_observer_internal(this) -
src/unittests/ObserverTest.cpp
r5d1611 r317df8 39 39 public: 40 40 void changeMethod() { 41 START_OBSERVER; 42 int i; 43 i++; 44 FINISH_OBSERVER; 41 OBSERVE; 42 int i; 43 i++; 45 44 } 46 45 }; … … 49 48 public: 50 49 void changeMethod1() { 51 START_OBSERVER; 52 int i; 53 i++; 54 FINISH_OBSERVER; 50 OBSERVE; 51 int i; 52 i++; 55 53 } 56 54 57 55 void changeMethod2() { 58 START_OBSERVER;56 OBSERVE; 59 57 int i; 60 58 i++; 61 59 changeMethod1(); 62 FINISH_OBSERVER;63 60 } 64 61 }; … … 74 71 } 75 72 void changeMethod() { 76 START_OBSERVER;73 OBSERVE; 77 74 int i; 78 75 i++; 79 76 subObservable->changeMethod(); 80 FINISH_OBSERVER;81 77 } 82 78 SimpleObservable *subObservable;
Note:
See TracChangeset
for help on using the changeset viewer.