EGS Brachy
An egs++ user code for rapid brachytherapy calculations
Loading...
Searching...
No Matches
/Users/marc/Developer/EGSnrc/HEN_HOUSE/user_codes/egs_brachy/egs_brachy/pubsub.h
Go to the documentation of this file.
1/*
2################################################################################
3#
4# egs_brachy pubsub.h
5# Copyright (C) 2016 Rowan Thomson, Dave Rogers, Randle Taylor, and Marc
6# Chamberland
7#
8# This file is part of egs_brachy
9#
10# egs_brachy is free software: you can redistribute it and/or modify it
11# under the terms of the GNU Affero General Public License as published
12# by the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# egs_brachy is distributed in the hope that it will be useful, but
16# WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18# Affero General Public License for more details:
19# <http://www.gnu.org/licenses/>.
20#
21################################################################################
22#
23# When egs_brachy is used for publications, please cite our paper:
24# M. J. P. Chamberland, R. E. P. Taylor, D. W. O. Rogers, and R. M. Thomson,
25# egs brachy: a versatile and fast Monte Carlo code for brachytherapy,
26# Phys. Med. Biol. 61, 8214-8231 (2016).
27#
28################################################################################
29#
30# Author: Randle Taylor, 2016
31#
32# Contributors: Marc Chamberland
33# Dave Rogers
34# Rowan Thomson
35#
36################################################################################
37*/
38
46#ifndef PUBSUB_H
47#define PUBSUB_H
48#include <list>
49#include <string>
50#include <map>
51using namespace std;
52class Publisher;
53
68
69typedef pair<bool, EB_Message> EBSendMessage;
70
72public:
73 virtual ~Subscriber() {}
74 virtual void update(EB_Message message, void *what = 0) = 0;
75};
76
77class Publisher {
78public:
80 notifyEnabled = true;
81 }
82 virtual ~Publisher() { }
83 void subscribe(Subscriber *s, EB_Message message) {
84 subscribers[message].push_back(s);
85 }
86 void unsubscribe(Subscriber *s, EB_Message message) {
87 subscribers[message].remove(s);
88 }
89 void notify(EB_Message message, void *what = 0, Subscriber *s = 0);
90 void setNotifyEnabled(bool flag) {
91 notifyEnabled = flag;
92 }
93 bool getNotifyEnabled() const {
94 return notifyEnabled;
95 }
96private:
97 map<EB_Message, list<Subscriber *> > subscribers;
99};
100#endif
void setNotifyEnabled(bool flag)
Definition pubsub.h:90
void subscribe(Subscriber *s, EB_Message message)
Definition pubsub.h:83
map< EB_Message, list< Subscriber * > > subscribers
Definition pubsub.h:97
Publisher()
Definition pubsub.h:79
void unsubscribe(Subscriber *s, EB_Message message)
Definition pubsub.h:86
bool getNotifyEnabled() const
Definition pubsub.h:93
virtual ~Publisher()
Definition pubsub.h:82
bool notifyEnabled
Definition pubsub.h:98
void notify(EB_Message message, void *what=0, Subscriber *s=0)
Definition pubsub.cpp:46
virtual ~Subscriber()
Definition pubsub.h:73
virtual void update(EB_Message message, void *what=0)=0
pair< bool, EB_Message > EBSendMessage
Definition pubsub.h:69
EB_Message
Definition pubsub.h:54
@ PARTICLE_ESCAPING_SOURCE
Definition pubsub.h:60
@ NEW_HISTORY
Definition pubsub.h:56
@ PARTICLE_ESCAPED_SOURCE
Definition pubsub.h:61
@ PARTICLE_TAKING_STEP
Definition pubsub.h:58
@ NON_SOURCE_PHOTON_SCATTER_EVENT
Definition pubsub.h:65
@ PARTICLE_ESCAPED_GEOM
Definition pubsub.h:63
@ PHOTON_SCATTER_EVENT
Definition pubsub.h:64
@ PARTICLE_TOOK_STEP
Definition pubsub.h:59
@ PARTICLE_INITIALIZED
Definition pubsub.h:57
@ PARTICLE_ESCAPING_GEOM
Definition pubsub.h:62