GDCM 2.2.1

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

gdcmCommand.h
Go to the documentation of this file.
1 /*=========================================================================
2
3 Program: GDCM (Grassroots DICOM). A DICOM library
4
5 Copyright (c) 2006-2011 Mathieu Malaterre
6 All rights reserved.
7 See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12
13 =========================================================================*/
14 #ifndef GDCMCOMMAND_H
15 #define GDCMCOMMAND_H
16
17 #include "gdcmSubject.h"
18
19 namespace gdcm
20 {
21 class Event;
22
27 class GDCM_EXPORT Command : public Subject
28 {
29 public :
31 virtual void Execute(Subject *caller, const Event & event ) = 0;
32
37 virtual void Execute(const Subject *caller, const Event & event ) = 0;
38
39 protected:
40 Command();
41 ~Command();
42
43 private:
44 Command(const Command&); // Not implemented.
45 void operator=(const Command&); // Not implemented.
46 };
47
55 template <class T>
56 class MemberCommand : public Command
57 {
58 public:
60 typedef void (T::*TMemberFunctionPointer)(Subject*, const Event &);
61 typedef void (T::*TConstMemberFunctionPointer)(const Subject*,
62 const Event &);
63
65 typedef MemberCommand Self;
66 //typedef SmartPointer<Self> Pointer;
67
69 static SmartPointer<MemberCommand> New()
70 {
71 return new MemberCommand;
72 }
73
75 //gdcmTypeMacro(MemberCommand,Command);
76
79 void SetCallbackFunction(T* object,
80 TMemberFunctionPointer memberFunction)
81 {
82 m_This = object;
83 m_MemberFunction = memberFunction;
84 }
85 void SetCallbackFunction(T* object,
86 TConstMemberFunctionPointer memberFunction)
87 {
88 m_This = object;
89 m_ConstMemberFunction = memberFunction;
90 }
91
93 virtual void Execute(Subject *caller, const Event & event )
94 {
95 if( m_MemberFunction )
96 {
97 ((*m_This).*(m_MemberFunction))(caller, event);
98 }
99 }
100
102 virtual void Execute( const Subject *caller, const Event & event )
103 {
104 if( m_ConstMemberFunction )
105 {
106 ((*m_This).*(m_ConstMemberFunction))(caller, event);
107 }
108 }
109
110 protected:
111
112 T* m_This;
113 TMemberFunctionPointer m_MemberFunction;
114 TConstMemberFunctionPointer m_ConstMemberFunction;
115 MemberCommand():m_MemberFunction(0),m_ConstMemberFunction(0) {}
116 virtual ~MemberCommand(){}
117
118 private:
119 MemberCommand(const Self&); //purposely not implemented
120 void operator=(const Self&); //purposely not implemented
121
122 };
123
130 template <typename T>
131 class SimpleMemberCommand : public Command
132 {
133 public:
135 typedef void (T::*TMemberFunctionPointer)();
136
138 typedef SimpleMemberCommand Self;
139 //typedef SmartPointer<Self> Pointer;
140
142 //gdcmTypeMacro(SimpleMemberCommand,Command);
143
145 static SmartPointer<SimpleMemberCommand> New()
146 {
147 return new SimpleMemberCommand;
148 }
149
151 void SetCallbackFunction(T* object,
152 TMemberFunctionPointer memberFunction)
153 {
154 m_This = object;
155 m_MemberFunction = memberFunction;
156 }
157
159 virtual void Execute(Subject *,const Event & )
160 {
161 if( m_MemberFunction )
162 {
163 ((*m_This).*(m_MemberFunction))();
164 }
165 }
166 virtual void Execute(const Subject *,const Event & )
167 {
168 if( m_MemberFunction )
169 {
170 ((*m_This).*(m_MemberFunction))();
171 }
172 }
173
174 protected:
175 T* m_This;
176 TMemberFunctionPointer m_MemberFunction;
177 SimpleMemberCommand():m_MemberFunction(0) {}
178 virtual ~SimpleMemberCommand() {}
179
180 private:
181 SimpleMemberCommand(const Self&); //purposely not implemented
182 void operator=(const Self&); //purposely not implemented
183 };
184
185 } // end namespace gdcm
186 //-----------------------------------------------------------------------------
187 #endif //GDCMCOMMAND_H