Ignore:
Timestamp:
Apr 25, 2010, 12:48:24 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:
8de8f7
Parents:
ccacba
Message:

Small improvements to Observer code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/Observer.cpp

    rccacba r033a05  
    2626
    2727map<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 Observers
     28map<Observable*,multimap<int,Observer*> > Observable::callTable; //!< Table for each Observable of all its Observers
    2929std::map<Observable*,std::set<Notification*> > Observable::notifications;
    3030set<Observable*> Observable::busyObservables; //!< Set of Observables that are currently busy notifying their sign-on'ed Observers
     
    103103 * and removes from busy list.
    104104 */
    105 void Observable::notifyAll() try {
     105void Observable::notifyAll() {
    106106  // we are busy notifying others right now
    107107  // add ourselves to the list of busy subjects to enable circle detection
     
    109109  // see if anyone has signed up for observation
    110110  // 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");
    121124
    122125  // send out all notifications that need to be done
     
    133136  busyObservables.erase(this);
    134137}
    135 ASSERT_NOCATCH("Exception thrown from Observer Update")
     138
    136139
    137140/** Handles passing on updates from sub-Observables.
     
    169172  ASSERT(priority>=-20 && priority<=+20, "Priority out of range [-20:+20] when signing on Observer");
    170173  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];
    179175
    180176  callees_t::iterator iter;
    181   for(iter=callees->begin();iter!=callees->end();++iter){
     177  for(iter=callees.begin();iter!=callees.end();++iter){
    182178    res |= ((*iter).second == target);
    183179  }
    184180  if(!res)
    185     callees->insert(pair<int,Observer*>(priority,target));
     181    callees.insert(pair<int,Observer*>(priority,target));
    186182}
    187183
     
    192188void Observable::signOff(Observer *target) {
    193189  ASSERT(callTable.count(this),"SignOff called for an Observable without Observers.");
    194   callees_t *callees = callTable[this];
     190  callees_t &callees = callTable[this];
    195191  callees_t::iterator iter;
    196192  callees_t::iterator deliter;
    197   for(iter=callees->begin();iter!=callees->end();) {
     193  for(iter=callees.begin();iter!=callees.end();) {
    198194    if((*iter).second == target) {
    199       callees->erase(iter++);
     195      callees.erase(iter++);
    200196    }
    201197    else {
     
    203199    }
    204200  }
    205   if(callees->empty()){
     201  if(callees.empty()){
    206202    callTable.erase(this);
    207     delete callees;
    208203  }
    209204}
     
    246241  if(callTable.count(this)) {
    247242    // delete all entries for this observable
    248     callees_t *callees = callTable[this];
     243    callees_t callees = callTable[this];
    249244    callees_t::iterator iter;
    250     for(iter=callees->begin();iter!=callees->end();++iter){
     245    for(iter=callees.begin();iter!=callees.end();++iter){
    251246      (*iter).second->subjectKilled(this);
    252247    }
    253248    callTable.erase(this);
    254     delete callees;
    255249  }
    256250}
     
    272266 */
    273267void Observer::recieveNotification(Observable *publisher, Notification_ptr notification){
     268  ASSERT(0,"Notification received by object that did not sign on for it.");
    274269}
    275270
Note: See TracChangeset for help on using the changeset viewer.