ITK  6.0.0
Insight Toolkit
itkEventObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 "itkMacro.h"
22 #include "itkIndent.h"
23 
24 namespace itk
25 {
58 class ITKCommon_EXPORT EventObject
59 {
60 public:
63  EventObject() = default;
64 
65  EventObject(const EventObject &) = default;
66 
67  EventObject &
68  operator=(const EventObject &) = delete;
69 
71  virtual ~EventObject() = default;
72 
75  virtual EventObject *
76  MakeObject() const = 0;
77 
81  virtual void
82  Print(std::ostream & os) const;
83 
85  virtual const char *
86  GetEventName() const = 0;
87 
89  virtual bool
90  CheckEvent(const EventObject *) const = 0;
91 
92 protected:
97  virtual void
98  PrintSelf(std::ostream & os, Indent indent) const;
99 
100  virtual void
101  PrintHeader(std::ostream & os, Indent indent) const;
102 
103  virtual void
104  PrintTrailer(std::ostream & os, Indent indent) const;
105 };
106 
108 inline std::ostream &
109 operator<<(std::ostream & os, const EventObject & e)
110 {
111  e.Print(os);
112  return os;
113 }
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() = default; \
131  classname(const Self & s); \
132  virtual ~classname() override; \
133  virtual const char * \
134  GetEventName() const override; \
135  virtual bool \
136  CheckEvent(const itk::EventObject * e) const override; \
137  virtual itk::EventObject * \
138  MakeObject() const override; \
139  \
140  private: \
141  void \
142  operator=(const Self &); \
143  }; \
144  ITK_MACROEND_NOOP_STATEMENT
145 
146 #define itkEventMacroDefinition(classname, super) \
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  ITK_MACROEND_NOOP_STATEMENT
157 
158 #if !defined(ITK_LEGACY_REMOVE)
159 // Support Pre 2015 code bases
160 
161 // This macro duplicates some of the declaration and definition
162 // macro code. The purpose is to provide a backward compatibility API
163 // for ITK applications.
164 // NOTE: New applications should use itkEventMacroDeclaration (in a
165 // .h file) and itkEventMacroDefinition (in a compiled .cxx
166 // file). This new approach guarantees that only one copy of the
167 // implementation will be present.
168 //
169 # define itkEventMacro(classname, super) \
170  \
171  class ITKEvent_EXPORT classname : public super \
172  { \
173  public: \
174  using Self = classname; \
175  using Superclass = super; \
176  classname() {} \
177  virtual ~classname() {} \
178  virtual const char * \
179  GetEventName() const \
180  { \
181  return #classname; \
182  } \
183  virtual bool \
184  CheckEvent(const itk::EventObject * e) const \
185  { \
186  return (dynamic_cast<const Self *>(e) != nullptr); \
187  } \
188  virtual itk::EventObject * \
189  MakeObject() const \
190  { \
191  return new Self; \
192  } \
193  classname(const Self & s) \
194  : super(s) {}; \
195  \
196  private: \
197  void \
198  operator=(const Self &); \
199  };
200 #endif
201 
204 itkEventMacroDeclaration(NoEvent, EventObject);
205 itkEventMacroDeclaration(AnyEvent, EventObject);
206 itkEventMacroDeclaration(DeleteEvent, AnyEvent);
207 itkEventMacroDeclaration(StartEvent, AnyEvent);
208 itkEventMacroDeclaration(EndEvent, AnyEvent);
209 itkEventMacroDeclaration(ProgressEvent, AnyEvent);
210 itkEventMacroDeclaration(ExitEvent, AnyEvent);
211 itkEventMacroDeclaration(AbortEvent, AnyEvent);
212 itkEventMacroDeclaration(ModifiedEvent, AnyEvent);
213 itkEventMacroDeclaration(InitializeEvent, AnyEvent);
214 itkEventMacroDeclaration(IterationEvent, AnyEvent);
215 itkEventMacroDeclaration(MultiResolutionIterationEvent, IterationEvent);
216 itkEventMacroDeclaration(PickEvent, AnyEvent);
217 itkEventMacroDeclaration(StartPickEvent, PickEvent);
218 itkEventMacroDeclaration(EndPickEvent, PickEvent);
219 itkEventMacroDeclaration(AbortCheckEvent, PickEvent);
220 itkEventMacroDeclaration(FunctionEvaluationIterationEvent, IterationEvent);
221 itkEventMacroDeclaration(GradientEvaluationIterationEvent, IterationEvent);
222 itkEventMacroDeclaration(FunctionAndGradientEvaluationIterationEvent, IterationEvent);
223 itkEventMacroDeclaration(UserEvent, AnyEvent);
226 #undef ITKEvent_EXPORT
227 #define ITKEvent_EXPORT ITK_ABI_EXPORT
228 
229 } // end namespace itk
230 
231 #endif
itk::itkEventMacroDeclaration
itkEventMacroDeclaration(NoEvent, EventObject)
itk::operator<<
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itkMacro.h
itkIndent.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::Math::e
static constexpr double e
Definition: itkMath.h:56
itk::EventObject
Abstraction of the Events used to communicating among filters and with GUIs.
Definition: itkEventObject.h:58