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-2010 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 
00028 class GDCM_EXPORT Command : public Subject
00029 {
00030 public :
00032   virtual void Execute(Subject *caller, const Event & event ) = 0;
00033 
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   static SmartPointer<MemberCommand> New()
00071     {
00072     return new MemberCommand;
00073     }
00074  
00076   //gdcmTypeMacro(MemberCommand,Command);
00077 
00080   void SetCallbackFunction(T* object,  
00081                            TMemberFunctionPointer memberFunction)
00082     {
00083     m_This = object;
00084     m_MemberFunction = memberFunction;
00085     }
00086   void SetCallbackFunction(T* object,  
00087                            TConstMemberFunctionPointer memberFunction)
00088     {
00089     m_This = object;
00090     m_ConstMemberFunction = memberFunction;
00091     }
00092   
00094   virtual void Execute(Subject *caller, const Event & event )
00095     { 
00096     if( m_MemberFunction ) 
00097       {
00098       ((*m_This).*(m_MemberFunction))(caller, event);
00099       }
00100     }
00101 
00103   virtual void Execute( const Subject *caller, const Event & event )
00104     { 
00105     if( m_ConstMemberFunction ) 
00106       {
00107       ((*m_This).*(m_ConstMemberFunction))(caller, event);
00108       }
00109     }
00110 
00111 protected:
00112 
00113   T* m_This;
00114   TMemberFunctionPointer m_MemberFunction;
00115   TConstMemberFunctionPointer m_ConstMemberFunction;
00116   MemberCommand():m_MemberFunction(0),m_ConstMemberFunction(0) {}
00117   virtual ~MemberCommand(){}
00118 
00119 private:
00120   MemberCommand(const Self&); //purposely not implemented
00121   void operator=(const Self&); //purposely not implemented
00122 
00123 };
00124 
00131 template <typename T>
00132 class SimpleMemberCommand : public Command
00133 { 
00134 public:
00136   typedef  void (T::*TMemberFunctionPointer)(); 
00137   
00139   typedef SimpleMemberCommand   Self;
00140   //typedef SmartPointer<Self>    Pointer;
00141   
00143   //gdcmTypeMacro(SimpleMemberCommand,Command);
00144 
00146   static SmartPointer<SimpleMemberCommand> New()
00147     {
00148     return new SimpleMemberCommand;
00149     }
00150 
00152   void SetCallbackFunction(T* object,  
00153                            TMemberFunctionPointer memberFunction)
00154     {
00155     m_This = object;
00156     m_MemberFunction = memberFunction;
00157     }
00158   
00160   virtual void Execute(Subject *,const Event & ) 
00161     { 
00162     if( m_MemberFunction ) 
00163       {
00164       ((*m_This).*(m_MemberFunction))();
00165       }
00166     }
00167   virtual void Execute(const Subject *,const Event & ) 
00168     { 
00169     if( m_MemberFunction ) 
00170       {
00171       ((*m_This).*(m_MemberFunction))();
00172       }
00173     }
00174   
00175 protected:
00176   T* m_This;
00177   TMemberFunctionPointer m_MemberFunction;
00178   SimpleMemberCommand():m_MemberFunction(0) {}
00179   virtual ~SimpleMemberCommand() {}
00180 
00181 private:
00182   SimpleMemberCommand(const Self&); //purposely not implemented
00183   void operator=(const Self&); //purposely not implemented
00184 };
00185 
00186 } // end namespace gdcm
00187 //-----------------------------------------------------------------------------
00188 #endif //GDCMCOMMAND_H

Generated on Sat Dec 4 2010 08:58:39 for GDCM by doxygen 1.7.2
SourceForge.net Logo