Changeset 750cff for src/documentation/constructs/observers_observables.dox
- Timestamp:
- Oct 31, 2011, 5:13:52 PM (14 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, Candidate_v1.7.0, 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:
- 5982c5
- Parents:
- 19bc74
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/documentation/constructs/observers_observables.dox
r19bc74 r750cff 12 12 * Author: heber 13 13 */ 14 15 /** \page observers Observers and Observables 16 * 17 * The Observer/Observerable mechanism is crucial to let different and 18 * independent components know about changes among one another. E.g. when an 19 * the element of an atom changes, the GUI (\ref graphical) needs to know 20 * about this change to plot the atom with a different color or shape. 21 * 22 * The Observer/Observerable mechanism is basically just a call-back: A 23 * class announces itself as Observable with having a specific interface 24 * of functions. Observer may signOn() to this class and have a specific 25 * function (update()) be called whenever a change occurs in the Observable 26 * class. 27 * 28 * Note that additionally an Observable may have various \a channels and 29 * Observers may signOn() to just such a channel to get a very specific 30 * update. E.g. a LinkedCell class needs to know when the position of an 31 * atom changes but it does not need to know about changes of element or 32 * velocity, ... These updates are called \a Notifications. 33 * 34 * As an example: 35 * \code 36 * World::getInstance().signOn(this, World::getInstance().getChannel(World::AtomInserted)); 37 * \endcode 38 * Here, in the constructor of GLWorldView the class signs on to atoms 39 * being inserted into the World such that it can add these onto the display 40 * as well. Notifications are received via recieveNotifications(), e.g. 41 * which you have to implement for an Observer class 42 * \code 43 * switch (notification->getChannelNo()) { 44 * case World::AtomInserted: 45 * { 46 * const atom *_atom = World::getInstance().lastChanged<atom>(); 47 * emit atomInserted(_atom); 48 * break; 49 * } 50 * \endcode 51 * Here, we just switch over all events that we process and care about (note 52 * that we only get called for those for which we have subscribed) and proceed. 53 * 54 * \note There is a complete logging mechanism available for this. However, 55 * it has to be compiled via a specific switch (\ref install). So, when 56 * you need to know why your function isn't notified, that's the way to 57 * find out. 58 * 59 * Be wary of where the update occurs: while the World tells you about new 60 * or destroyed atoms, only the atom itself tells you when its position has 61 * changed! 62 * 63 * \section observers-world Observers and the World 64 * 65 * The World, containing the arrays of all atoms and molecules, is a bit 66 * special with these observers. E.g. when you request a non-const array 67 * of atoms you receive an ObservedIterator. That is one where automatically 68 * it is assumed that you changed something and hence update() is called 69 * after you stepped over one of its elements. 70 * 71 * Thus, use const-iterators and arrays whenever possible, first to avoid 72 * this overhead, but second to avoid making pain-in-the-ass, hard-to-find 73 * mistakes. 74 * 75 * Also, the world stores specific information about what changed in the 76 * template function World::lastChanged() where it might contain reference 77 * to an atom that is about to be destroyed or just added. 78 * 79 * 80 * \date 2011-10-31 81 * 82 */
Note:
See TracChangeset
for help on using the changeset viewer.
