GDCM: gdcmCommand.h Source File

GDCM 3.2.10

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
27 class GDCM_EXPORT Command : public Subject
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:
43 Command();
44 ~Command() override;
45};
46
54template <class T>
55 class 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
65 typedef MemberCommand Self;
66 //typedef SmartPointer<Self> Pointer;
67
68 MemberCommand(const Self&) = delete;
69 void operator=(const Self&) = delete;
70
72 static SmartPointer<MemberCommand> New()
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 {
98 if( m_MemberFunction )
99 {
100 ((*m_This).*(m_MemberFunction))(caller, event);
101 }
102 }
103
105 void Execute( const Subject *caller, const Event & event ) override
106 {
107 if( m_ConstMemberFunction )
108 {
109 ((*m_This).*(m_ConstMemberFunction))(caller, event);
110 }
111 }
112
113protected:
114
115 T* m_This;
116 TMemberFunctionPointer m_MemberFunction;
117 TConstMemberFunctionPointer m_ConstMemberFunction;
118 MemberCommand():m_This(nullptr),m_MemberFunction(nullptr),m_ConstMemberFunction(nullptr) {}
119 ~MemberCommand() override= default;
120
121};
122
129template <typename T>
130 class SimpleMemberCommand : public Command
131{
132public:
133
135 typedef void (T::*TMemberFunctionPointer)();
136
138 typedef SimpleMemberCommand Self;
139 //typedef SmartPointer<Self> Pointer;
140
141 SimpleMemberCommand(const Self&) = delete;
142 void operator=(const Self&) = delete;
143
145 //gdcmTypeMacro(SimpleMemberCommand,Command);
146
148 static SmartPointer<SimpleMemberCommand> New()
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:
178 T* m_This;
179 TMemberFunctionPointer m_MemberFunction;
180 SimpleMemberCommand():m_This(nullptr),m_MemberFunction(nullptr) {}
181 ~SimpleMemberCommand() override = default;
182};
183
184} // end namespace gdcm
185//-----------------------------------------------------------------------------
186#endif //GDCMCOMMAND_H
gdcm::Command::~Command
~Command() override
gdcm::Command::Execute
virtual void Execute(Subject *caller, const Event &event)=0
Abstract method that defines the action to be taken by the command.
gdcm::Command::Command
Command(const Command &)=delete
gdcm::Command::Execute
virtual void Execute(const Subject *caller, const Event &event)=0
gdcm::Command::operator=
void operator=(const Command &)=delete
gdcm::Command::Command
Command()
gdcm::Event
superclass for callback/observer methods
Definition gdcmEvent.h:27
gdcm::MemberCommand::SetCallbackFunction
void SetCallbackFunction(T *object, TMemberFunctionPointer memberFunction)
Definition gdcmCommand.h:82
gdcm::MemberCommand::MemberCommand
MemberCommand()
Definition gdcmCommand.h:118
gdcm::MemberCommand::Execute
void Execute(const Subject *caller, const Event &event) override
Definition gdcmCommand.h:105
gdcm::MemberCommand::TConstMemberFunctionPointer
void(T::* TConstMemberFunctionPointer)(const Subject *, const Event &)
Definition gdcmCommand.h:61
gdcm::MemberCommand::New
static SmartPointer< MemberCommand > New()
Definition gdcmCommand.h:72
gdcm::MemberCommand< SimpleSubjectWatcher >::m_This
SimpleSubjectWatcher * m_This
Definition gdcmCommand.h:115
gdcm::MemberCommand< SimpleSubjectWatcher >::m_ConstMemberFunction
TConstMemberFunctionPointer m_ConstMemberFunction
Definition gdcmCommand.h:117
gdcm::MemberCommand::Execute
void Execute(Subject *caller, const Event &event) override
Definition gdcmCommand.h:96
gdcm::MemberCommand::operator=
void operator=(const Self &)=delete
gdcm::MemberCommand::TMemberFunctionPointer
void(T::* TMemberFunctionPointer)(Subject *, const Event &)
Definition gdcmCommand.h:60
gdcm::MemberCommand::SetCallbackFunction
void SetCallbackFunction(T *object, TConstMemberFunctionPointer memberFunction)
Definition gdcmCommand.h:88
gdcm::MemberCommand::~MemberCommand
~MemberCommand() override=default
gdcm::MemberCommand< SimpleSubjectWatcher >::m_MemberFunction
TMemberFunctionPointer m_MemberFunction
Definition gdcmCommand.h:116
gdcm::MemberCommand::MemberCommand
MemberCommand(const Self &)=delete
gdcm::MemberCommand::Self
MemberCommand Self
Definition gdcmCommand.h:65
gdcm::SimpleMemberCommand::TMemberFunctionPointer
void(T::* TMemberFunctionPointer)()
Definition gdcmCommand.h:135
gdcm::SimpleMemberCommand::SimpleMemberCommand
SimpleMemberCommand()
Definition gdcmCommand.h:180
gdcm::SimpleMemberCommand::Execute
void Execute(const Subject *, const Event &) override
Definition gdcmCommand.h:169
gdcm::SimpleMemberCommand::Execute
void Execute(Subject *, const Event &) override
Definition gdcmCommand.h:162
gdcm::SimpleMemberCommand::SimpleMemberCommand
SimpleMemberCommand(const Self &)=delete
gdcm::SimpleMemberCommand::SetCallbackFunction
void SetCallbackFunction(T *object, TMemberFunctionPointer memberFunction)
Definition gdcmCommand.h:154
gdcm::SimpleMemberCommand::~SimpleMemberCommand
~SimpleMemberCommand() override=default
gdcm::SimpleMemberCommand< SimpleSubjectWatcher >::m_This
SimpleSubjectWatcher * m_This
Definition gdcmCommand.h:178
gdcm::SimpleMemberCommand::operator=
void operator=(const Self &)=delete
gdcm::SimpleMemberCommand< SimpleSubjectWatcher >::m_MemberFunction
TMemberFunctionPointer m_MemberFunction
Definition gdcmCommand.h:179
gdcm::SimpleMemberCommand::New
static SmartPointer< SimpleMemberCommand > New()
Definition gdcmCommand.h:148
gdcm::SimpleMemberCommand::Self
SimpleMemberCommand Self
Definition gdcmCommand.h:138
gdcm::SmartPointer
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
gdcm::Subject
Subject.
Definition gdcmSubject.h:29
gdcm::Subject::Subject
Subject()
gdcmSubject.h
GDCM_EXPORT
#define GDCM_EXPORT
Definition gdcmWin32.h:34
gdcm
Definition gdcmASN1.h:21