Changeset 033a05 for src/Patterns/Observer.cpp
- Timestamp:
- Apr 25, 2010, 12:48:24 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:
- 8de8f7
- Parents:
- ccacba
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Patterns/Observer.cpp
rccacba r033a05 26 26 27 27 map<Observable*, int> Observable::depth; //!< Map of Observables to the depth of the DAG of Observers 28 map<Observable*,multimap<int,Observer*> *> Observable::callTable; //!< Table for each Observable of all its Observers28 map<Observable*,multimap<int,Observer*> > Observable::callTable; //!< Table for each Observable of all its Observers 29 29 std::map<Observable*,std::set<Notification*> > Observable::notifications; 30 30 set<Observable*> Observable::busyObservables; //!< Set of Observables that are currently busy notifying their sign-on'ed Observers … … 103 103 * and removes from busy list. 104 104 */ 105 void Observable::notifyAll() try{105 void Observable::notifyAll() { 106 106 // we are busy notifying others right now 107 107 // add ourselves to the list of busy subjects to enable circle detection … … 109 109 // see if anyone has signed up for observation 110 110 // and call all observers 111 if(callTable.count(this)) { 112 // elements are stored sorted by keys in the multimap 113 // so iterating over it gives us a the callees sorted by 114 // the priorities 115 callees_t *callees = callTable[this]; 116 callees_t::iterator iter; 117 for(iter=callees->begin();iter!=callees->end();++iter){ 118 (*iter).second->update(this); 119 } 120 } 111 try { 112 if(callTable.count(this)) { 113 // elements are stored sorted by keys in the multimap 114 // so iterating over it gives us a the callees sorted by 115 // the priorities 116 callees_t callees = callTable[this]; 117 callees_t::iterator iter; 118 for(iter=callees.begin();iter!=callees.end();++iter){ 119 (*iter).second->update(this); 120 } 121 } 122 } 123 ASSERT_NOCATCH("Exception thrown from Observer Update"); 121 124 122 125 // send out all notifications that need to be done … … 133 136 busyObservables.erase(this); 134 137 } 135 ASSERT_NOCATCH("Exception thrown from Observer Update") 138 136 139 137 140 /** Handles passing on updates from sub-Observables. … … 169 172 ASSERT(priority>=-20 && priority<=+20, "Priority out of range [-20:+20] when signing on Observer"); 170 173 bool res = false; 171 callees_t *callees = 0; 172 if(callTable.count(this)){ 173 callees = callTable[this]; 174 } 175 else { 176 callees = new multimap<int,Observer*>; 177 callTable.insert(pair<Observable*,callees_t*>(this,callees)); 178 } 174 callees_t &callees = callTable[this]; 179 175 180 176 callees_t::iterator iter; 181 for(iter=callees ->begin();iter!=callees->end();++iter){177 for(iter=callees.begin();iter!=callees.end();++iter){ 182 178 res |= ((*iter).second == target); 183 179 } 184 180 if(!res) 185 callees ->insert(pair<int,Observer*>(priority,target));181 callees.insert(pair<int,Observer*>(priority,target)); 186 182 } 187 183 … … 192 188 void Observable::signOff(Observer *target) { 193 189 ASSERT(callTable.count(this),"SignOff called for an Observable without Observers."); 194 callees_t *callees = callTable[this];190 callees_t &callees = callTable[this]; 195 191 callees_t::iterator iter; 196 192 callees_t::iterator deliter; 197 for(iter=callees ->begin();iter!=callees->end();) {193 for(iter=callees.begin();iter!=callees.end();) { 198 194 if((*iter).second == target) { 199 callees ->erase(iter++);195 callees.erase(iter++); 200 196 } 201 197 else { … … 203 199 } 204 200 } 205 if(callees ->empty()){201 if(callees.empty()){ 206 202 callTable.erase(this); 207 delete callees;208 203 } 209 204 } … … 246 241 if(callTable.count(this)) { 247 242 // delete all entries for this observable 248 callees_t *callees = callTable[this];243 callees_t callees = callTable[this]; 249 244 callees_t::iterator iter; 250 for(iter=callees ->begin();iter!=callees->end();++iter){245 for(iter=callees.begin();iter!=callees.end();++iter){ 251 246 (*iter).second->subjectKilled(this); 252 247 } 253 248 callTable.erase(this); 254 delete callees;255 249 } 256 250 } … … 272 266 */ 273 267 void Observer::recieveNotification(Observable *publisher, Notification_ptr notification){ 268 ASSERT(0,"Notification received by object that did not sign on for it."); 274 269 } 275 270
Note:
See TracChangeset
for help on using the changeset viewer.