Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/ObserversRegistry.h @ 147:f48c5d422d45 wasm
removed meaningless ImageInterpolation_Linear value
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 23 Jan 2018 17:50:19 +0100 |
parents | e2fe9352f240 |
children | fccffbf99ba1 |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
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 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 8 * modify it under the terms of the GNU Affero General Public License |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
0 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
47 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #pragma once | |
23 | |
113
2eca030792aa
using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
91
diff
changeset
|
24 #include <Core/OrthancException.h> |
0 | 25 |
26 #include <boost/noncopyable.hpp> | |
27 #include <set> | |
28 | |
29 namespace OrthancStone | |
30 { | |
31 template < | |
32 typename Source, | |
91 | 33 typename Observer = typename Source::IObserver |
0 | 34 > |
35 class ObserversRegistry : public boost::noncopyable | |
36 { | |
37 private: | |
38 typedef std::set<Observer*> Observers; | |
39 | |
53
c2dc924f1a63
removing threading out of the framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
40 Observers observers_; |
0 | 41 |
42 public: | |
43 template <typename Functor> | |
91 | 44 void Notify(const Source& source, |
0 | 45 Functor& functor) |
46 { | |
47 for (typename Observers::const_iterator observer = observers_.begin(); | |
48 observer != observers_.end(); ++observer) | |
49 { | |
91 | 50 functor(**observer, source); |
0 | 51 } |
52 } | |
53 | |
54 void Register(Observer& observer) | |
55 { | |
56 observers_.insert(&observer); | |
57 } | |
58 | |
59 void Unregister(Observer& observer) | |
60 { | |
61 observers_.erase(&observer); | |
62 } | |
63 | |
64 bool IsEmpty() | |
65 { | |
66 return observers_.empty(); | |
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 | 104 }; |
105 } |