ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkEventObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkEventObject_h
19 #define itkEventObject_h
20 
21 #include "itkIndent.h"
22 
23 namespace itk
24 {
57 class ITKCommon_EXPORT EventObject
58 {
59 public:
63 
65 
67  virtual ~EventObject() {}
68 
71  virtual EventObject * MakeObject() const = 0;
72 
76  virtual void Print(std::ostream & os) const;
77 
79  virtual const char * GetEventName(void) const = 0;
80 
82  virtual bool CheckEvent(const EventObject *) const = 0;
83 
84 protected:
89  virtual void PrintSelf(std::ostream & os, Indent indent) const;
90 
91  virtual void PrintHeader(std::ostream & os, Indent indent) const;
92 
93  virtual void PrintTrailer(std::ostream & os, Indent indent) const;
94 
95 private:
97  void operator=(const EventObject &);
98 };
99 
101 inline std::ostream & operator<<(std::ostream & os, EventObject & e)
102 {
103  ( &e )->Print(os);
104  return os;
105 }
107 
108 
109 #define ITKEvent_EXPORT ITKCommon_EXPORT
110 
115 #define itkEventMacroDeclaration(classname, super) \
116  \
117  class ITKEvent_EXPORT classname:public super \
118  { \
119 public: \
120  typedef classname Self; \
121  typedef super Superclass; \
122  classname(); \
123  classname(const Self &s); \
124  virtual ~classname(); \
125  virtual const char *GetEventName() const; \
126  virtual bool CheckEvent(const::itk::EventObject * e) const; \
127  virtual ::itk::EventObject *MakeObject() const; \
128 private: \
129  void operator=(const Self &); \
130  };
131 
132 #define itkEventMacroDefinition(classname, super) \
133 classname::classname() {} \
134 classname::classname(const classname &s):super(s){}; \
135 classname::~classname() {} \
136 const char * classname::GetEventName() const { return #classname; } \
137 bool classname::CheckEvent(const::itk::EventObject * e) const \
138  { return ( dynamic_cast< const classname * >( e ) != ITK_NULLPTR ); } \
139 ::itk::EventObject *classname::MakeObject() const { return new classname; } \
140 
141 //
142 // This macro duplicates some of the declaration and definition
143 // macro code. The purpose is to provide a backward compatibility API
144 // for ITK applications.
145 // NOTE: New applications should use itkEventMacroDeclaration (in a
146 // .h file) and itkEventMacroDefinition (in a compiled .cxx
147 // file). This new approach guarantees that only one copy of the
148 // implementation will be present.
149 //
150 #define itkEventMacro(classname, super) \
151  \
152  class ITKEvent_EXPORT classname:public super \
153  { \
154 public: \
155  typedef classname Self; \
156  typedef super Superclass; \
157  classname() {} \
158  virtual ~classname() {} \
159  virtual const char *GetEventName() const { return #classname; } \
160  virtual bool CheckEvent(const::itk::EventObject * e) const \
161  { return ( dynamic_cast< const Self * >( e ) != ITK_NULLPTR ); } \
162  virtual::itk::EventObject *MakeObject() const \
163  { return new Self; } \
164  classname(const Self &s):super(s){}; \
165 private: \
166  void operator=(const Self &); \
167  };
168 
172 itkEventMacroDeclaration(NoEvent, EventObject)
173 itkEventMacroDeclaration(AnyEvent, EventObject)
174 itkEventMacroDeclaration(DeleteEvent, AnyEvent)
175 itkEventMacroDeclaration(StartEvent, AnyEvent)
176 itkEventMacroDeclaration(EndEvent, AnyEvent)
177 itkEventMacroDeclaration(ProgressEvent, AnyEvent)
178 itkEventMacroDeclaration(ExitEvent, AnyEvent)
179 itkEventMacroDeclaration(AbortEvent, AnyEvent)
180 itkEventMacroDeclaration(ModifiedEvent, AnyEvent)
181 itkEventMacroDeclaration(InitializeEvent, AnyEvent)
182 itkEventMacroDeclaration(IterationEvent, AnyEvent)
183 itkEventMacroDeclaration(MultiResolutionIterationEvent,IterationEvent)
184 itkEventMacroDeclaration(PickEvent, AnyEvent)
185 itkEventMacroDeclaration(StartPickEvent, PickEvent)
186 itkEventMacroDeclaration(EndPickEvent, PickEvent)
187 itkEventMacroDeclaration(AbortCheckEvent, PickEvent)
188 itkEventMacroDeclaration(FunctionEvaluationIterationEvent, IterationEvent)
189 itkEventMacroDeclaration(GradientEvaluationIterationEvent, IterationEvent)
190 itkEventMacroDeclaration(FunctionAndGradientEvaluationIterationEvent, IterationEvent)
191 itkEventMacroDeclaration(UserEvent, AnyEvent)
192 
193 #undef ITKEvent_EXPORT
194 #define ITKEvent_EXPORT ITK_ABI_EXPORT
195 
196 } // end namespace itk
197 
198 #endif
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:192
virtual ~EventObject()
#define itkEventMacroDeclaration(classname, super)
EventObject * EventFactoryFunction()
Abstraction of the Events used to communicating among filters and with GUIs.
EventObject(const EventObject &)
Control indentation during Print() invocation.
Definition: itkIndent.h:49
static ITK_CONSTEXPR_VAR double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:56