annotate Framework/Toolbox/ObserversRegistry.h @ 194:7a031ac16b2d wasm

rename Enumerations.h to StoneEnumerations.h to avoid clashes with Orthanc
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 20 Mar 2018 14:46:58 +0100
parents e2fe9352f240
children fccffbf99ba1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
135
e2fe9352f240 upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
47
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
10 * the License, or (at your option) any later version.
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
47
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
15 * Affero General Public License for more details.
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
16 *
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #pragma once
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
113
2eca030792aa using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 91
diff changeset
24 #include <Core/OrthancException.h>
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <boost/noncopyable.hpp>
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <set>
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 namespace OrthancStone
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 template <
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 typename Source,
91
81f73efd81a1 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 90
diff changeset
33 typename Observer = typename Source::IObserver
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 >
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 class ObserversRegistry : public boost::noncopyable
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 private:
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 typedef std::set<Observer*> Observers;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
53
c2dc924f1a63 removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 47
diff changeset
40 Observers observers_;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 public:
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 template <typename Functor>
91
81f73efd81a1 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 90
diff changeset
44 void Notify(const Source& source,
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 Functor& functor)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 for (typename Observers::const_iterator observer = observers_.begin();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 observer != observers_.end(); ++observer)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
91
81f73efd81a1 cleaning up
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 90
diff changeset
50 functor(**observer, source);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 void Register(Observer& observer)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 observers_.insert(&observer);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 void Unregister(Observer& observer)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 observers_.erase(&observer);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 bool IsEmpty()
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 return observers_.empty();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 }
90
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
68
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
69 void Apply(const Source& source,
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
70 void (Observer::*method) (const Source&))
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
71 {
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
72 for (typename Observers::const_iterator it = observers_.begin();
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
73 it != observers_.end(); ++it)
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
74 {
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
75 ((*it)->*method) (source);
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
76 }
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
77 }
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
78
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
79 template <typename Argument0>
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
80 void Apply(const Source& source,
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
81 void (Observer::*method) (const Source&, const Argument0&),
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
82 const Argument0& argument0)
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
83 {
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
84 for (typename Observers::const_iterator it = observers_.begin();
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
85 it != observers_.end(); ++it)
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
86 {
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
87 ((*it)->*method) (source, argument0);
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
88 }
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
89 }
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
90
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
91 template <typename Argument0,
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
92 typename Argument1>
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
93 void Apply(const Source& source,
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
94 void (Observer::*method) (const Source&, const Argument0&, const Argument1&),
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
95 const Argument0& argument0,
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
96 const Argument1& argument1)
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
97 {
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
98 for (typename Observers::const_iterator it = observers_.begin();
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
99 it != observers_.end(); ++it)
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
100 {
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
101 ((*it)->*method) (source, argument0, argument1);
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
102 }
64e60018943f fix and observer refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 53
diff changeset
103 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 };
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 }