GDCM  2.2.0
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

Generated on Wed Jun 13 2012 20:40:37 for GDCM by doxygen 1.8.1
SourceForge.net Logo