ITK  5.4.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 "itkIndent.h"
22
23namespace itk
24{
57class ITKCommon_EXPORT EventObject
58{
59public:
62 EventObject() = default;
63
64 EventObject(const EventObject &) = default;
65
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
91protected:
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
107inline std::ostream &
108operator<<(std::ostream & os, const EventObject & e)
109{
110 e.Print(os);
111 return os;
112}
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// Support 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
205itkEventMacroDeclaration(DeleteEvent, AnyEvent);
206itkEventMacroDeclaration(StartEvent, AnyEvent);
207itkEventMacroDeclaration(EndEvent, AnyEvent);
208itkEventMacroDeclaration(ProgressEvent, AnyEvent);
209itkEventMacroDeclaration(ExitEvent, AnyEvent);
210itkEventMacroDeclaration(AbortEvent, AnyEvent);
211itkEventMacroDeclaration(ModifiedEvent, AnyEvent);
212itkEventMacroDeclaration(InitializeEvent, AnyEvent);
213itkEventMacroDeclaration(IterationEvent, AnyEvent);
214itkEventMacroDeclaration(MultiResolutionIterationEvent, IterationEvent);
215itkEventMacroDeclaration(PickEvent, AnyEvent);
216itkEventMacroDeclaration(StartPickEvent, PickEvent);
217itkEventMacroDeclaration(EndPickEvent, PickEvent);
218itkEventMacroDeclaration(AbortCheckEvent, PickEvent);
219itkEventMacroDeclaration(FunctionEvaluationIterationEvent, IterationEvent);
220itkEventMacroDeclaration(GradientEvaluationIterationEvent, IterationEvent);
221itkEventMacroDeclaration(FunctionAndGradientEvaluationIterationEvent, IterationEvent);
222itkEventMacroDeclaration(UserEvent, AnyEvent);
225#undef ITKEvent_EXPORT
226#define ITKEvent_EXPORT ITK_ABI_EXPORT
227
228} // end namespace itk
229
230#endif
Abstraction of the Events used to communicating among filters and with GUIs.
virtual void PrintHeader(std::ostream &os, Indent indent) const
EventObject(const EventObject &)=default
virtual void Print(std::ostream &os) const
virtual void PrintTrailer(std::ostream &os, Indent indent) const
EventObject()=default
virtual ~EventObject()=default
virtual void PrintSelf(std::ostream &os, Indent indent) const
EventObject & operator=(const EventObject &)=delete
virtual bool CheckEvent(const EventObject *) const =0
virtual EventObject * MakeObject() const =0
virtual const char * GetEventName() const =0
Control indentation during Print() invocation.
Definition: itkIndent.h:50
static constexpr double e
Definition: itkMath.h:56
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
itkEventMacroDeclaration(NoEvent, EventObject)
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:216