GDCM 3.0.24
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
19namespace gdcm
20{
21class Event;
22
28{
29public :
30 Command(const Command&) = delete;
31 void operator=(const Command&) = delete;
32
34 virtual void Execute(Subject *caller, const Event & event ) = 0;
35
40 virtual void Execute(const Subject *caller, const Event & event ) = 0;
41
42protected:
44 ~Command() override;
45};
46
54template <class T>
55class MemberCommand : public Command
56{
57public:
58
60 typedef void (T::*TMemberFunctionPointer)(Subject*, const Event &);
61 typedef void (T::*TConstMemberFunctionPointer)(const Subject*,
62 const Event &);
63
66 //typedef SmartPointer<Self> Pointer;
67
68 MemberCommand(const Self&) = delete;
69 void operator=(const Self&) = delete;
70
73 {
74 return new MemberCommand;
75 }
76
78 //gdcmTypeMacro(MemberCommand,Command);
79
82 void SetCallbackFunction(T* object,
83 TMemberFunctionPointer memberFunction)
84 {
85 m_This = object;
86 m_MemberFunction = memberFunction;
87 }
88 void SetCallbackFunction(T* object,
89 TConstMemberFunctionPointer memberFunction)
90 {
91 m_This = object;
92 m_ConstMemberFunction = memberFunction;
93 }
94
96 void Execute(Subject *caller, const Event & event ) override
97 {
99 {
100 ((*m_This).*(m_MemberFunction))(caller, event);
101 }
102 }
103
105 void Execute( const Subject *caller, const Event & event ) override
106 {
108 {
109 ((*m_This).*(m_ConstMemberFunction))(caller, event);
110 }
111 }
112
113protected:
114
119 ~MemberCommand() override= default;
120
121};
122
129template <typename T>
131{
132public:
133
135 typedef void (T::*TMemberFunctionPointer)();
136
139 //typedef SmartPointer<Self> Pointer;
140
141 SimpleMemberCommand(const Self&) = delete;
142 void operator=(const Self&) = delete;
143
145 //gdcmTypeMacro(SimpleMemberCommand,Command);
146
149 {
150 return new SimpleMemberCommand;
151 }
152
154 void SetCallbackFunction(T* object,
155 TMemberFunctionPointer memberFunction)
156 {
157 m_This = object;
158 m_MemberFunction = memberFunction;
159 }
160
162 void Execute(Subject *,const Event & ) override
163 {
164 if( m_MemberFunction )
165 {
166 ((*m_This).*(m_MemberFunction))();
167 }
168 }
169 void Execute(const Subject *,const Event & ) override
170 {
171 if( m_MemberFunction )
172 {
173 ((*m_This).*(m_MemberFunction))();
174 }
175 }
176
177protected:
181 ~SimpleMemberCommand() override = default;
182};
183
184} // end namespace gdcm
185//-----------------------------------------------------------------------------
186#endif //GDCMCOMMAND_H
Command superclass for callback/observer methods.
Definition gdcmCommand.h:28
~Command() override
virtual void Execute(Subject *caller, const Event &event)=0
Abstract method that defines the action to be taken by the command.
Command(const Command &)=delete
virtual void Execute(const Subject *caller, const Event &event)=0
void operator=(const Command &)=delete
superclass for callback/observer methods
Definition gdcmEvent.h:27
Command subclass that calls a pointer to a member function.
Definition gdcmCommand.h:56
void SetCallbackFunction(T *object, TMemberFunctionPointer memberFunction)
Definition gdcmCommand.h:82
MemberCommand()
Definition gdcmCommand.h:118
void Execute(const Subject *caller, const Event &event) override
Definition gdcmCommand.h:105
void(T::* TConstMemberFunctionPointer)(const Subject *, const Event &)
Definition gdcmCommand.h:61
static SmartPointer< MemberCommand > New()
Definition gdcmCommand.h:72
T * m_This
Definition gdcmCommand.h:115
TConstMemberFunctionPointer m_ConstMemberFunction
Definition gdcmCommand.h:117
void Execute(Subject *caller, const Event &event) override
Definition gdcmCommand.h:96
void operator=(const Self &)=delete
void(T::* TMemberFunctionPointer)(Subject *, const Event &)
Definition gdcmCommand.h:60
void SetCallbackFunction(T *object, TConstMemberFunctionPointer memberFunction)
Definition gdcmCommand.h:88
~MemberCommand() override=default
TMemberFunctionPointer m_MemberFunction
Definition gdcmCommand.h:116
MemberCommand(const Self &)=delete
MemberCommand Self
Definition gdcmCommand.h:65
Command subclass that calls a pointer to a member function.
Definition gdcmCommand.h:131
void(T::* TMemberFunctionPointer)()
Definition gdcmCommand.h:135
SimpleMemberCommand()
Definition gdcmCommand.h:180
void Execute(const Subject *, const Event &) override
Definition gdcmCommand.h:169
void Execute(Subject *, const Event &) override
Definition gdcmCommand.h:162
SimpleMemberCommand(const Self &)=delete
void SetCallbackFunction(T *object, TMemberFunctionPointer memberFunction)
Definition gdcmCommand.h:154
~SimpleMemberCommand() override=default
T * m_This
Definition gdcmCommand.h:178
void operator=(const Self &)=delete
TMemberFunctionPointer m_MemberFunction
Definition gdcmCommand.h:179
static SmartPointer< SimpleMemberCommand > New()
Definition gdcmCommand.h:148
SimpleMemberCommand Self
Definition gdcmCommand.h:138
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
Subject.
Definition gdcmSubject.h:29
#define GDCM_EXPORT
Definition gdcmWin32.h:34
Definition gdcmASN1.h:21