source: src/EntityObserver_impl.hpp@ bccbe9

Action_Thermostats Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.1 ChemicalSpaceEvaluator Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Exclude_Hydrogens_annealWithBondGraph Fix_Verbose_Codepatterns ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion Gui_displays_atomic_force_velocity JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool PythonUI_with_named_parameters Recreated_GuiChecks StoppableMakroAction TremoloParser_IncreasedPrecision
Last change on this file since bccbe9 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.