gdcmCommand.h

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

Generated on Tue Mar 9 22:40:39 2010 for GDCM by doxygen 1.6.3
SourceForge.net Logo