GDCM  2.2.6
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 
66  //typedef SmartPointer<Self> Pointer;
67 
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  {
105  {
106  ((*m_This).*(m_ConstMemberFunction))(caller, event);
107  }
108  }
109 
110 protected:
111 
112  T* m_This;
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>
132 {
133 public:
135  typedef void (T::*TMemberFunctionPointer)();
136 
139  //typedef SmartPointer<Self> Pointer;
140 
142  //gdcmTypeMacro(SimpleMemberCommand,Command);
143 
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;
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
superclass for callback/observer methods
Definition: gdcmEvent.h:26
Command subclass that calls a pointer to a member function.
Definition: gdcmCommand.h:56
T * m_This
Definition: gdcmCommand.h:175
static SmartPointer< SimpleMemberCommand > New()
Definition: gdcmCommand.h:145
virtual ~MemberCommand()
Definition: gdcmCommand.h:116
T * m_This
Definition: gdcmCommand.h:112
void(T::* TMemberFunctionPointer)()
Definition: gdcmCommand.h:135
static SmartPointer< MemberCommand > New()
Definition: gdcmCommand.h:69
void(T::* TMemberFunctionPointer)(Subject *, const Event &)
Definition: gdcmCommand.h:60
#define GDCM_EXPORT
Definition: gdcmWin32.h:34
void(T::* TConstMemberFunctionPointer)(const Subject *, const Event &)
Definition: gdcmCommand.h:61
void SetCallbackFunction(T *object, TConstMemberFunctionPointer memberFunction)
Definition: gdcmCommand.h:85
TMemberFunctionPointer m_MemberFunction
Definition: gdcmCommand.h:113
SimpleMemberCommand()
Definition: gdcmCommand.h:177
MemberCommand()
Definition: gdcmCommand.h:115
TConstMemberFunctionPointer m_ConstMemberFunction
Definition: gdcmCommand.h:114
Subject.
Definition: gdcmSubject.h:28
Command superclass for callback/observer methods.
Definition: gdcmCommand.h:27
void SetCallbackFunction(T *object, TMemberFunctionPointer memberFunction)
Definition: gdcmCommand.h:151
Class for Smart Pointer.
Definition: gdcmObject.h:26
virtual void Execute(Subject *caller, const Event &event)
Definition: gdcmCommand.h:93
SimpleMemberCommand Self
Definition: gdcmCommand.h:138
virtual void Execute(const Subject *caller, const Event &event)
Definition: gdcmCommand.h:102
virtual void Execute(const Subject *, const Event &)
Definition: gdcmCommand.h:166
void SetCallbackFunction(T *object, TMemberFunctionPointer memberFunction)
Definition: gdcmCommand.h:79
Command subclass that calls a pointer to a member function.
Definition: gdcmCommand.h:131
TMemberFunctionPointer m_MemberFunction
Definition: gdcmCommand.h:176
virtual ~SimpleMemberCommand()
Definition: gdcmCommand.h:178
virtual void Execute(Subject *, const Event &)
Definition: gdcmCommand.h:159
MemberCommand Self
Definition: gdcmCommand.h:65

Generated on Sat Dec 21 2013 05:56:16 for GDCM by doxygen 1.8.5
SourceForge.net Logo