ITK  5.3.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  * 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 
66  EventObject &
67  operator=(const EventObject &) = delete;
68 
70  virtual ~EventObject() = default;
71 
74  virtual EventObject *
75  MakeObject() const = 0;
76 
80  virtual void
81  Print(std::ostream & os) const;
82 
84  virtual const char *
85  GetEventName() const = 0;
86 
88  virtual bool
89  CheckEvent(const EventObject *) const = 0;
90 
91 protected:
96  virtual void
97  PrintSelf(std::ostream & os, Indent indent) const;
98 
99  virtual void
100  PrintHeader(std::ostream & os, Indent indent) const;
101 
102  virtual void
103  PrintTrailer(std::ostream & os, Indent indent) const;
104 };
105 
107 inline std::ostream &
108 operator<<(std::ostream & os, const EventObject & e)
109 {
110  (&e)->Print(os);
111  return os;
112 }
114 
115 
116 #define ITKEvent_EXPORT ITKCommon_EXPORT
117 
122 #define itkEventMacroDeclaration(classname, super) \
123  \
124  class ITKEvent_EXPORT classname : public super \
125  { \
126  public: \
127  using Self = classname; \
128  using Superclass = super; \
129  classname() = default; \
130  classname(const Self & s); \
131  virtual ~classname() override; \
132  virtual const char * \
133  GetEventName() const override; \
134  virtual bool \
135  CheckEvent(const ::itk::EventObject * e) const override; \
136  virtual ::itk::EventObject * \
137  MakeObject() const override; \
138  \
139  private: \
140  void \
141  operator=(const Self &); \
142  }; \
143  static_assert(true, "Compile time eliminated. Used to require a semi-colon at end of macro.")
144 
145 #define itkEventMacroDefinition(classname, super) \
146  classname::classname(const classname & s) \
147  : super(s){}; \
148  classname::~classname() {} \
149  const char * classname::GetEventName() const { return #classname; } \
150  bool classname::CheckEvent(const ::itk::EventObject * e) const \
151  { \
152  return (dynamic_cast<const classname *>(e) != nullptr); \
153  } \
154  ::itk::EventObject * classname::MakeObject() const { return new classname; } \
155  static_assert(true, "Compile time eliminated. Used to require a semi-colon at end of macro.")
156 
157 #if !defined(ITK_LEGACY_REMOVE)
158 // Suppport Pre 2015 code bases
159 
160 // This macro duplicates some of the declaration and definition
161 // macro code. The purpose is to provide a backward compatibility API
162 // for ITK applications.
163 // NOTE: New applications should use itkEventMacroDeclaration (in a
164 // .h file) and itkEventMacroDefinition (in a compiled .cxx
165 // file). This new approach guarantees that only one copy of the
166 // implementation will be present.
167 //
168 # define itkEventMacro(classname, super) \
169  \
170  class ITKEvent_EXPORT classname : public super \
171  { \
172  public: \
173  using Self = classname; \
174  using Superclass = super; \
175  classname() {} \
176  virtual ~classname() {} \
177  virtual const char * \
178  GetEventName() const \
179  { \
180  return #classname; \
181  } \
182  virtual bool \
183  CheckEvent(const ::itk::EventObject * e) const \
184  { \
185  return (dynamic_cast<const Self *>(e) != nullptr); \
186  } \
187  virtual ::itk::EventObject * \
188  MakeObject() const \
189  { \
190  return new Self; \
191  } \
192  classname(const Self & s) \
193  : super(s){}; \
194  \
195  private: \
196  void \
197  operator=(const Self &); \
198  };
199 #endif
200 
203 itkEventMacroDeclaration(NoEvent, EventObject);
204 itkEventMacroDeclaration(AnyEvent, EventObject);
205 itkEventMacroDeclaration(DeleteEvent, AnyEvent);
206 itkEventMacroDeclaration(StartEvent, AnyEvent);
207 itkEventMacroDeclaration(EndEvent, AnyEvent);
208 itkEventMacroDeclaration(ProgressEvent, AnyEvent);
209 itkEventMacroDeclaration(ExitEvent, AnyEvent);
210 itkEventMacroDeclaration(AbortEvent, AnyEvent);
211 itkEventMacroDeclaration(ModifiedEvent, AnyEvent);
212 itkEventMacroDeclaration(InitializeEvent, AnyEvent);
213 itkEventMacroDeclaration(IterationEvent, AnyEvent);
214 itkEventMacroDeclaration(MultiResolutionIterationEvent, IterationEvent);
215 itkEventMacroDeclaration(PickEvent, AnyEvent);
216 itkEventMacroDeclaration(StartPickEvent, PickEvent);
217 itkEventMacroDeclaration(EndPickEvent, PickEvent);
218 itkEventMacroDeclaration(AbortCheckEvent, PickEvent);
219 itkEventMacroDeclaration(FunctionEvaluationIterationEvent, IterationEvent);
220 itkEventMacroDeclaration(GradientEvaluationIterationEvent, IterationEvent);
221 itkEventMacroDeclaration(FunctionAndGradientEvaluationIterationEvent, IterationEvent);
222 itkEventMacroDeclaration(UserEvent, AnyEvent);
224 
225 #undef ITKEvent_EXPORT
226 #define ITKEvent_EXPORT ITK_ABI_EXPORT
227 
228 } // end namespace itk
229 
230 #endif
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:216
itk::itkEventMacroDeclaration
itkEventMacroDeclaration(NoEvent, EventObject)
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: itkAnnulusOperator.h:24
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