00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __freEvents_h
00023 #define __freEvents_h
00024
00025 #include "freElementals.h"
00026 #include "itkLightObject.h"
00027
00028 namespace FREE
00029 {
00030
00031
00032 #define freNewEventBaseMacro(x, FncPtr) \
00033 static Pointer New(FncPtr pE)\
00034 {\
00035 Pointer smartPtr;\
00036 x* rawPtr = new x(pE);\
00037 smartPtr = rawPtr;\
00038 rawPtr->UnRegister();\
00039 return smartPtr;\
00040 }\
00041
00042 #define freNewEventMacro(x, T, FncPtr) \
00043 static Pointer New(T* pObject,FncPtr pE)\
00044 {\
00045 Pointer smartPtr;\
00046 x* rawPtr = new x(pObject, pE);\
00047 smartPtr = rawPtr;\
00048 rawPtr->UnRegister();\
00049 return smartPtr;\
00050 }\
00051
00052
00060 class NotificationEventBase : public itk::LightObject
00061 {
00062 public:
00063 typedef void (*NotifyEvent)(void* pSender, long threadID);
00064 typedef itk::SmartPointer<NotificationEventBase> Pointer;
00065 freNewEventBaseMacro(NotificationEventBase,NotifyEvent);
00066 itkTypeMacro(NotificationEventBase,itk::LightObject);
00067
00068 private:
00069 NotifyEvent m_NotifyEvent;
00070
00071 protected:
00072 NotificationEventBase(NotifyEvent pNE);
00073 NotificationEventBase();
00074
00075 public:
00076
00083 virtual void Execute(void* pSender, long threadID = 0);
00084 };
00085
00097 class CallbackEventBase : public itk::LightObject
00098 {
00099 public:
00100 typedef bool (*CallEvent)(CallbackType callbackID, CallbackFlagType flag,
00101 void* pData, void* pSender, long threadID);
00102 typedef itk::SmartPointer<CallbackEventBase> Pointer;
00103
00104 freNewEventBaseMacro(CallbackEventBase,CallEvent);
00105 itkTypeMacro(CallbackEventBase,itk::LightObject);
00106
00107 private:
00108 CallEvent m_CallEvent;
00109
00110 protected:
00111 CallbackEventBase(CallEvent pCE);
00112 CallbackEventBase();
00113
00114 public:
00115
00131 virtual bool Execute(CallbackType callbackID, CallbackFlagType flag,
00132 void* pData, void* pSender, long threadID = 0);
00133 };
00134
00143 class ProgressEventBase: public NotificationEventBase
00144 {
00145 public:
00146 typedef void (*ProgEvent)(const long status, const std::string& sComment, void* pSender, long threadID);
00147 typedef itk::SmartPointer<ProgressEventBase> Pointer;
00148
00149 freNewEventBaseMacro(ProgressEventBase,ProgEvent);
00150 itkTypeMacro(ProgressEventBase,NotificationEventBase);
00151
00152 private:
00153 ProgEvent m_ProgressEvent;
00154
00155 protected:
00156 ProgressEventBase(ProgEvent pPE);
00157 ProgressEventBase();
00158
00159 public:
00169 virtual void Execute(const long status, const std::string& sComment, void* pSender, long threadID = 0);
00170 };
00171
00181 template <typename T>
00182 class NotificationEvent : public NotificationEventBase
00183 {
00184 public:
00185 typedef void (T::*NotifyEvent)(void* pSender, long threadID);
00186 typedef itk::SmartPointer<NotificationEvent<T> > Pointer;
00187
00188 freNewEventMacro(NotificationEvent, T, NotifyEvent);
00189 itkTypeMacro(NotificationEvent,NotificationEventBase);
00190
00191 private:
00192 T* m_Object;
00193 NotifyEvent m_NotifyEvent;
00194
00195 protected:
00196 NotificationEvent(T* pObject, NotifyEvent pNE)
00197 {
00198 m_Object = pObject;
00199 m_NotifyEvent = pNE;
00200 };
00201
00202 public:
00206 virtual void Execute(void* pSender, long threadID = 0)
00207 { (m_Object->*m_NotifyEvent)(pSender, threadID); };
00208 };
00209
00225 template <typename T>
00226 class CallbackEvent: public CallbackEventBase
00227 {
00228 public:
00229 typedef bool (T::*CallEvent)(CallbackType callbackID, CallbackFlagType flag,
00230 void* pData, void* pSender, long threadID);
00231 typedef itk::SmartPointer<CallbackEvent<T> > Pointer;
00232
00233 freNewEventMacro(CallbackEvent, T, CallEvent);
00234 itkTypeMacro(CallbackEvent,CallbackEventBase);
00235
00236 private:
00237 T* m_Object;
00238 CallEvent m_CallEvent;
00239
00240 protected:
00241 CallbackEvent(T* pObject, CallEvent pCE)
00242 {
00243 m_Object = pObject;
00244 m_CallEvent = pCE;
00245 };
00246
00247 public:
00263 virtual bool Execute(CallbackType callbackID, CallbackFlagType flag,
00264 void* pData, void* pSender, long threadID = 0)
00265 { return (m_Object->*m_CallEvent)(callbackID, flag, pData, pSender, threadID); };
00266 };
00267
00282 template <typename T>
00283 class ProgressEvent: public ProgressEventBase
00284 {
00285 public:
00286 typedef void (T::*ProgEvent)(const long status, const std::string& sComment, void* pSender, long threadID);
00287 typedef itk::SmartPointer<ProgressEvent<T> > Pointer;
00288
00289 freNewEventMacro(ProgressEvent, T, ProgEvent);
00290 itkTypeMacro(ProgressEvent,ProgressEventBase);
00291
00292 private:
00293 T* m_Object;
00294 ProgEvent m_ProgressEvent;
00295
00296 protected:
00297 ProgressEvent(T* pObject, ProgEvent pPE)
00298 {
00299 m_Object = pObject;
00300 m_ProgressEvent = pPE;
00301 };
00302
00303 public:
00313 virtual void Execute(const long status, const std::string& sComment, void* pSender, long threadID = 0)
00314 { (m_Object->*m_ProgressEvent)(status, sComment, pSender, threadID); };
00315 };
00316
00317 }
00318 #endif