source: src/EntityObserver_impl.hpp@ 4464ef

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 4464ef was d4ba3f, checked in by Frederik Heber <heber@…>, 9 years ago

Extracted common code out of Molecule/AtomObserver into EntityObserver.

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/*
2 * EntityObserver_impl.hpp
3 *
4 * Created on: Dec 29, 2015
5 * Author: heber
6 */
7
8
9#ifndef ENTITYOBSERVER_IMPL_HPP_
10#define ENTITYOBSERVER_IMPL_HPP_
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include <algorithm>
18
19#include <boost/bind.hpp>
20
21#include "CodePatterns/Observer/Channels.hpp"
22
23/** Private constructor of class EntityObserver.
24 *
25 */
26template <class T>
27EntityObserver<T>::EntityObserver(
28 const Observable::channels_t &_Channels,
29 const std::string &_name) :
30 Relay(_name),
31 EntityChannels(_Channels)
32{
33 Channels *OurChannel = new Channels();
34 Observable::insertNotificationChannel( std::make_pair(static_cast<Observable *>(this), OurChannel) );
35 std::for_each(EntityChannels.begin(), EntityChannels.end(),
36 boost::bind(&Channels::addChannel, OurChannel, _1));
37}
38
39/** Function to call when a new atom has been created.
40 *
41 * @param res
42 */
43template <class T>
44void EntityObserver<T>::Inserted(Observable *res)
45{
46 ASSERT( dynamic_cast<Observable *>(res) != NULL,
47 "EntityObserver<T>::Inserted - type is not derived from Observable.");
48 std::for_each(EntityChannels.begin(), EntityChannels.end(),
49 boost::bind(&Observable::signOn, res, this, _1, GlobalObservableInfo::PriorityDefault));
50}
51
52/** Function to call when an atom is about to get deleted.
53 *
54 * @param res
55 */
56template <class T>
57void EntityObserver<T>::Removed(Observable *res)
58{
59 std::for_each(EntityChannels.begin(), EntityChannels.end(),
60 boost::bind(&Observable::signOff, res, this, _1));
61}
62
63#endif /* ENTITYOBSERVER_IMPL_HPP_ */
Note: See TracBrowser for help on using the repository browser.