| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkEventObject.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:35 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
|
| 18 |
|
#ifndef __itkEventObject_h |
| 19 |
|
#define __itkEventObject_h |
| 20 |
|
|
| 21 |
|
#include "itkIndent.h" |
| 22 |
|
|
| 23 |
|
|
| 24 |
|
namespace itk |
| 25 |
|
{ |
| 26 |
|
|
| 27 |
|
/** \class EventObject |
| 28 |
|
* \brief Abstraction of the Events used to communicating among filters |
| 29 |
IND |
****and with GUIs. |
| 30 |
|
* |
| 31 |
|
* EventObject provides a standard coding for sending and receiving messages |
| 32 |
|
* indicating things like the initiation of processes, end of processes, |
| 33 |
|
* modification of filters. |
| 34 |
|
* |
| 35 |
|
* EventObjects form a hierarchy similar to the itk::ExceptionObject allowing |
| 36 |
|
* to factorize common events in a tree-like structure. Higher detail can |
| 37 |
|
* be assigned by users by subclassing existing itk::EventObjects. |
| 38 |
|
* |
| 39 |
|
* EventObjects are used by itk::Command and itk::Object for implementing the |
| 40 |
|
* Observer/Subject design pattern. Observers register their interest in |
| 41 |
|
* particular kinds of events produced by a specific itk::Object. This |
| 42 |
|
* mechanism decouples classes among them. |
| 43 |
|
* |
| 44 |
|
* As oppossed to itk::Exception, itk::EventObject does not represent error |
| 45 |
|
* states, but simply flow of information allowing to trigger actions |
| 46 |
|
* as a consecuence of changes occurring in state on some itk::Objects. |
| 47 |
|
* |
| 48 |
|
* itk::EventObject carries information in its own type, it relies on the |
| 49 |
|
* appropiate use of the RTTI (Run Time Type Information). |
| 50 |
|
* |
| 51 |
|
* A set of standard EventObjects is defined near the end of itkIndent.h. |
| 52 |
|
* |
| 53 |
|
* \sa itk::Command |
| 54 |
|
* \sa itk::ExceptionObject |
| 55 |
|
* |
| 56 |
|
* \ingroup ITKSystemObjects |
| 57 |
|
*/ |
| 58 |
|
class ITKCommon_EXPORT EventObject |
| 59 |
|
{ |
| 60 |
|
public: |
| 61 |
|
/** Constructor and copy constructor. Note that these functions will be |
| 62 |
|
* called when children are instantiated. */ |
| 63 |
|
EventObject() {} |
| 64 |
|
|
| 65 |
|
/** Virtual destructor needed */ |
| 66 |
|
virtual ~EventObject() {} |
| 67 |
|
|
| 68 |
|
/** Create an Event of this type This method work as a Factory for |
| 69 |
|
* creating events of each particular type. */ |
| 70 |
|
virtual EventObject* MakeObject() const=0; |
| 71 |
|
|
| 72 |
|
/** Print Event information. This method can be overridden by |
| 73 |
|
* specific Event subtypes. The default is to print out the type of |
| 74 |
|
* the event. */ |
| 75 |
|
virtual void Print(std::ostream& os) const; |
| 76 |
|
|
| 77 |
|
/** Return the StringName associated with the event. */ |
| 78 |
|
virtual const char * GetEventName(void) const=0; |
| 79 |
|
|
| 80 |
|
/** Check if given event matches or derives from this event. */ |
| 81 |
|
virtual bool CheckEvent(const EventObject*) const=0; |
| 82 |
|
|
| 83 |
|
protected: |
| 84 |
|
/** Methods invoked by Print() to print information about the object |
| 85 |
|
* including superclasses. Typically not called by the user (use Print() |
| 86 |
|
* instead) but used in the hierarchical print process to combine the |
| 87 |
|
* output of several classes. */ |
| 88 |
|
virtual void PrintSelf(std::ostream& os, Indent indent) const; |
| 89 |
|
virtual void PrintHeader(std::ostream& os, Indent indent) const; |
| 90 |
|
virtual void PrintTrailer(std::ostream& os, Indent indent) const; |
| 91 |
|
|
| 92 |
|
EventObject(const EventObject&){}; |
| 93 |
|
private: |
| 94 |
|
typedef EventObject * EventFactoryFunction(); |
| 95 |
|
void operator=(const EventObject&); |
| 96 |
|
}; |
| 97 |
|
|
| 98 |
|
|
| 99 |
|
/** Generic inserter operator for EventObject and its subclasses. */ |
| 100 |
|
inline std::ostream& operator<<(std::ostream& os, EventObject &e) |
| 101 |
|
{ |
| 102 |
|
(&e)->Print(os); |
| 103 |
|
return os; |
| 104 |
|
} |
| 105 |
|
|
| 106 |
|
|
| 107 |
EML |
|
| 108 |
EML |
|
| 109 |
|
/* |
| 110 |
IND |
** Macro for creating new Events |
| 111 |
IND |
**/ |
| 112 |
|
#define itkEventMacro( classname , super ) \ |
| 113 |
IND |
*/** \class classname */ \ |
| 114 |
IND,IND |
*class classname : public super { \ |
| 115 |
IND |
***public: \ |
| 116 |
IND |
*****typedef classname Self; \ |
| 117 |
TDA,IND |
*****typedef super Superclass; \ |
| 118 |
IND |
*****classname() {} \ |
| 119 |
IND |
*****virtual ~classname() {} \ |
| 120 |
IND |
*****virtual const char * GetEventName() const { return #classname; } \ |
| 121 |
IND |
*****virtual bool CheckEvent(const ::itk::EventObject* e) const \ |
| 122 |
IND |
*******{ return dynamic_cast<const Self*>(e); } \ |
| 123 |
IND |
*****virtual ::itk::EventObject* MakeObject() const \ |
| 124 |
IND |
*******{ return new Self; } \ |
| 125 |
IND |
*****classname(const Self&s) :super(s){}; \ |
| 126 |
IND |
***private: \ |
| 127 |
IND |
*****void operator=(const Self&); \ |
| 128 |
IND |
*} |
| 129 |
|
|
| 130 |
|
|
| 131 |
EML |
|
| 132 |
|
/** |
| 133 |
|
* Define some common ITK events |
| 134 |
|
*/ |
| 135 |
|
itkEventMacro( NoEvent , EventObject ); |
| 136 |
|
itkEventMacro( AnyEvent , EventObject ); |
| 137 |
|
itkEventMacro( DeleteEvent , AnyEvent ); |
| 138 |
|
itkEventMacro( StartEvent , AnyEvent ); |
| 139 |
|
itkEventMacro( EndEvent , AnyEvent ); |
| 140 |
|
itkEventMacro( ProgressEvent , AnyEvent ); |
| 141 |
|
itkEventMacro( ExitEvent , AnyEvent ); |
| 142 |
|
itkEventMacro( AbortEvent , AnyEvent ); |
| 143 |
|
itkEventMacro( ModifiedEvent , AnyEvent ); |
| 144 |
|
itkEventMacro( InitializeEvent , AnyEvent ); |
| 145 |
|
itkEventMacro( IterationEvent , AnyEvent ); |
| 146 |
|
itkEventMacro( PickEvent , AnyEvent ); |
| 147 |
|
itkEventMacro( StartPickEvent , PickEvent ); |
| 148 |
|
itkEventMacro( EndPickEvent , PickEvent ); |
| 149 |
|
itkEventMacro( AbortCheckEvent , PickEvent ); |
| 150 |
|
itkEventMacro( FunctionEvaluationIterationEvent, IterationEvent ); |
| 151 |
|
itkEventMacro( GradientEvaluationIterationEvent, IterationEvent ); |
| 152 |
|
itkEventMacro( FunctionAndGradientEvaluationIterationEvent, IterationEvent ); |
| 153 |
|
|
| 154 |
|
itkEventMacro( UserEvent , AnyEvent ); |
| 155 |
|
|
| 156 |
|
|
| 157 |
|
} // end namespace itk |
| 158 |
|
|
| 159 |
|
#endif |
| 160 |
|
|
| 161 |
EOF |
|