source: src/EntityObserver_impl.hpp@ ff4fff9

CombiningParticlePotentialParsing
Last change on this file since ff4fff9 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.