GDCM
2.0.18
|
00001 /*========================================================================= 00002 00003 Program: GDCM (Grassroots DICOM). A DICOM library 00004 00005 Copyright (c) 2006-2011 Mathieu Malaterre 00006 All rights reserved. 00007 See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details. 00008 00009 This software is distributed WITHOUT ANY WARRANTY; without even 00010 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00011 PURPOSE. See the above copyright notice for more information. 00012 00013 =========================================================================*/ 00014 #ifndef GDCMCOMMAND_H 00015 #define GDCMCOMMAND_H 00016 00017 #include "gdcmSubject.h" 00018 00019 namespace gdcm 00020 { 00021 class Event; 00022 00027 class GDCM_EXPORT Command : public Subject 00028 { 00029 public : 00031 virtual void Execute(Subject *caller, const Event & event ) = 0; 00032 00037 virtual void Execute(const Subject *caller, const Event & event ) = 0; 00038 00039 protected: 00040 Command(); 00041 ~Command(); 00042 00043 private: 00044 Command(const Command&); // Not implemented. 00045 void operator=(const Command&); // Not implemented. 00046 }; 00047 00055 template <class T> 00056 class MemberCommand : public Command 00057 { 00058 public: 00060 typedef void (T::*TMemberFunctionPointer)(Subject*, const Event &); 00061 typedef void (T::*TConstMemberFunctionPointer)(const Subject*, 00062 const Event &); 00063 00065 typedef MemberCommand Self; 00066 //typedef SmartPointer<Self> Pointer; 00067 00069 static SmartPointer<MemberCommand> New() 00070 { 00071 return new MemberCommand; 00072 } 00073 00075 //gdcmTypeMacro(MemberCommand,Command); 00076 00079 void SetCallbackFunction(T* object, 00080 TMemberFunctionPointer memberFunction) 00081 { 00082 m_This = object; 00083 m_MemberFunction = memberFunction; 00084 } 00085 void SetCallbackFunction(T* object, 00086 TConstMemberFunctionPointer memberFunction) 00087 { 00088 m_This = object; 00089 m_ConstMemberFunction = memberFunction; 00090 } 00091 00093 virtual void Execute(Subject *caller, const Event & event ) 00094 { 00095 if( m_MemberFunction ) 00096 { 00097 ((*m_This).*(m_MemberFunction))(caller, event); 00098 } 00099 } 00100 00102 virtual void Execute( const Subject *caller, const Event & event ) 00103 { 00104 if( m_ConstMemberFunction ) 00105 { 00106 ((*m_This).*(m_ConstMemberFunction))(caller, event); 00107 } 00108 } 00109 00110 protected: 00111 00112 T* m_This; 00113 TMemberFunctionPointer m_MemberFunction; 00114 TConstMemberFunctionPointer m_ConstMemberFunction; 00115 MemberCommand():m_MemberFunction(0),m_ConstMemberFunction(0) {} 00116 virtual ~MemberCommand(){} 00117 00118 private: 00119 MemberCommand(const Self&); //purposely not implemented 00120 void operator=(const Self&); //purposely not implemented 00121 00122 }; 00123 00130 template <typename T> 00131 class SimpleMemberCommand : public Command 00132 { 00133 public: 00135 typedef void (T::*TMemberFunctionPointer)(); 00136 00138 typedef SimpleMemberCommand Self; 00139 //typedef SmartPointer<Self> Pointer; 00140 00142 //gdcmTypeMacro(SimpleMemberCommand,Command); 00143 00145 static SmartPointer<SimpleMemberCommand> New() 00146 { 00147 return new SimpleMemberCommand; 00148 } 00149 00151 void SetCallbackFunction(T* object, 00152 TMemberFunctionPointer memberFunction) 00153 { 00154 m_This = object; 00155 m_MemberFunction = memberFunction; 00156 } 00157 00159 virtual void Execute(Subject *,const Event & ) 00160 { 00161 if( m_MemberFunction ) 00162 { 00163 ((*m_This).*(m_MemberFunction))(); 00164 } 00165 } 00166 virtual void Execute(const Subject *,const Event & ) 00167 { 00168 if( m_MemberFunction ) 00169 { 00170 ((*m_This).*(m_MemberFunction))(); 00171 } 00172 } 00173 00174 protected: 00175 T* m_This; 00176 TMemberFunctionPointer m_MemberFunction; 00177 SimpleMemberCommand():m_MemberFunction(0) {} 00178 virtual ~SimpleMemberCommand() {} 00179 00180 private: 00181 SimpleMemberCommand(const Self&); //purposely not implemented 00182 void operator=(const Self&); //purposely not implemented 00183 }; 00184 00185 } // end namespace gdcm 00186 //----------------------------------------------------------------------------- 00187 #endif //GDCMCOMMAND_H