ITK  5.1.0
Insight 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:
62  EventObject() = default;
63 
64  EventObject(const EventObject &) = default;
65 
67  virtual ~EventObject() = default;
68 
71  virtual EventObject *
72  MakeObject() const = 0;
73 
77  virtual void
78  Print(std::ostream & os) const;
79 
81  virtual const char *
82  GetEventName() const = 0;
83 
85  virtual bool
86  CheckEvent(const EventObject *) const = 0;
87 
88 protected:
93  virtual void
94  PrintSelf(std::ostream & os, Indent indent) const;
95 
96  virtual void
97  PrintHeader(std::ostream & os, Indent indent) const;
98 
99  virtual void
100  PrintTrailer(std::ostream & os, Indent indent) const;
101 
102 private:
103  void
104  operator=(const EventObject &) = delete;
105 };
106 
108 inline std::ostream &
109 operator<<(std::ostream & os, const EventObject & e)
110 {
111  (&e)->Print(os);
112  return os;
113 }
115 
116 
117 #define ITKEvent_EXPORT ITKCommon_EXPORT
118 
123 #define itkEventMacroDeclaration(classname, super) \
124  \
125  class ITKEvent_EXPORT classname : public super \
126  { \
127  public: \
128  using Self = classname; \
129  using Superclass = super; \
130  classname(); \
131  classname(const Self & s); \
132  virtual ~classname(); \
133  virtual const char * \
134  GetEventName() const; \
135  virtual bool \
136  CheckEvent(const ::itk::EventObject * e) const; \
137  virtual ::itk::EventObject * \
138  MakeObject() const; \
139  \
140  private: \
141  void \
142  operator=(const Self &); \
143  };
144 
145 #define itkEventMacroDefinition(classname, super) \
146  classname::classname() {} \
147  classname::classname(const classname & s) \
148  : super(s){}; \
149  classname::~classname() {} \
150  const char * classname::GetEventName() const { return #classname; } \
151  bool classname::CheckEvent(const ::itk::EventObject * e) const \
152  { \
153  return (dynamic_cast<const classname *>(e) != nullptr); \
154  } \
155  ::itk::EventObject * classname::MakeObject() const { return new classname; }
156 
157 //
158 // This macro duplicates some of the declaration and definition
159 // macro code. The purpose is to provide a backward compatibility API
160 // for ITK applications.
161 // NOTE: New applications should use itkEventMacroDeclaration (in a
162 // .h file) and itkEventMacroDefinition (in a compiled .cxx
163 // file). This new approach guarantees that only one copy of the
164 // implementation will be present.
165 //
166 #define itkEventMacro(classname, super) \
167  \
168  class ITKEvent_EXPORT classname : public super \
169  { \
170  public: \
171  using Self = classname; \
172  using Superclass = super; \
173  classname() {} \
174  virtual ~classname() {} \
175  virtual const char * \
176  GetEventName() const \
177  { \
178  return #classname; \
179  } \
180  virtual bool \
181  CheckEvent(const ::itk::EventObject * e) const \
182  { \
183  return (dynamic_cast<const Self *>(e) != nullptr); \
184  } \
185  virtual ::itk::EventObject * \
186  MakeObject() const \
187  { \
188  return new Self; \
189  } \
190  classname(const Self & s) \
191  : super(s){}; \
192  \
193  private: \
194  void \
195  operator=(const Self &); \
196  };
197 
201 itkEventMacroDeclaration(NoEvent, EventObject) itkEventMacroDeclaration(AnyEvent, EventObject)
202  itkEventMacroDeclaration(DeleteEvent, AnyEvent) itkEventMacroDeclaration(StartEvent, AnyEvent)
203  itkEventMacroDeclaration(EndEvent, AnyEvent) itkEventMacroDeclaration(ProgressEvent, AnyEvent)
204  itkEventMacroDeclaration(ExitEvent, AnyEvent) itkEventMacroDeclaration(AbortEvent, AnyEvent)
205  itkEventMacroDeclaration(ModifiedEvent, AnyEvent) itkEventMacroDeclaration(InitializeEvent, AnyEvent)
206  itkEventMacroDeclaration(IterationEvent, AnyEvent)
207  itkEventMacroDeclaration(MultiResolutionIterationEvent, IterationEvent)
208  itkEventMacroDeclaration(PickEvent, AnyEvent) itkEventMacroDeclaration(StartPickEvent, PickEvent)
209  itkEventMacroDeclaration(EndPickEvent, PickEvent) itkEventMacroDeclaration(AbortCheckEvent, PickEvent)
210  itkEventMacroDeclaration(FunctionEvaluationIterationEvent, IterationEvent)
211  itkEventMacroDeclaration(GradientEvaluationIterationEvent, IterationEvent)
212  itkEventMacroDeclaration(FunctionAndGradientEvaluationIterationEvent, IterationEvent)
213  itkEventMacroDeclaration(UserEvent, AnyEvent)
214 
215 #undef ITKEvent_EXPORT
216 #define ITKEvent_EXPORT ITK_ABI_EXPORT
217 
218 } // end namespace itk
219 
220 #endif
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:211
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itkIndent.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::Math::e
static constexpr double e
Definition: itkMath.h:54
itk::EventObject
Abstraction of the Events used to communicating among filters and with GUIs.
Definition: itkEventObject.h:57
itk::itkEventMacroDeclaration
itkEventMacroDeclaration(NoEvent, EventObject) itkEventMacroDeclaration(AnyEvent