ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
24namespace itk
25{
58class ITKCommon_EXPORT EventObject
59{
60public:
63 EventObject() = default;
64
65 EventObject(const EventObject &) = default;
66
68 operator=(const EventObject &) = delete;
69
71 virtual ~EventObject() = default;
72
75 [[nodiscard]] virtual EventObject *
76 MakeObject() const = 0;
77
81 virtual void
82 Print(std::ostream & os) const;
83
85 [[nodiscard]] virtual const char *
86 GetEventName() const = 0;
87
89 virtual bool
90 CheckEvent(const EventObject *) const = 0;
91
92protected:
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
108inline std::ostream &
109operator<<(std::ostream & os, const EventObject & e)
110{
111 e.Print(os);
112 return os;
113}
114
115
116#define ITKEvent_EXPORT ITKCommon_EXPORT
117
121
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 ~classname() override; \
132 const char * \
133 GetEventName() const override; \
134 bool \
135 CheckEvent(const itk::EventObject * e) const override; \
136 itk::EventObject * \
137 MakeObject() const override; \
138 Self & \
139 operator=(const Self &) = delete; \
140 }; \
141 ITK_MACROEND_NOOP_STATEMENT
142
143// Note: From ITK 6.0, the second parameter of itkEventMacroDefinition (`super`) is ignored.
144#define itkEventMacroDefinition(classname, super) \
145 classname::classname(const classname &) = default; \
146 classname::~classname() = default; \
147 const char * classname::GetEventName() const { return #classname; } \
148 bool classname::CheckEvent(const itk::EventObject * e) const \
149 { \
150 return dynamic_cast<const classname *>(e) != nullptr; \
151 } \
152 itk::EventObject * classname::MakeObject() const { return new classname; } \
153 ITK_MACROEND_NOOP_STATEMENT
154
155#if !defined(ITK_LEGACY_REMOVE)
156// Support Pre 2015 code bases
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() = default; \
174 ~classname() override = default; \
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 &) = default; \
191 Self & \
192 operator=(const Self &) = delete; \
193 };
194#endif
201itkEventMacroDeclaration(DeleteEvent, AnyEvent);
202itkEventMacroDeclaration(StartEvent, AnyEvent);
203itkEventMacroDeclaration(EndEvent, AnyEvent);
204itkEventMacroDeclaration(ProgressEvent, AnyEvent);
205itkEventMacroDeclaration(ExitEvent, AnyEvent);
206itkEventMacroDeclaration(AbortEvent, AnyEvent);
207itkEventMacroDeclaration(ModifiedEvent, AnyEvent);
208itkEventMacroDeclaration(InitializeEvent, AnyEvent);
209itkEventMacroDeclaration(IterationEvent, AnyEvent);
210itkEventMacroDeclaration(MultiResolutionIterationEvent, IterationEvent);
211itkEventMacroDeclaration(PickEvent, AnyEvent);
212itkEventMacroDeclaration(StartPickEvent, PickEvent);
213itkEventMacroDeclaration(EndPickEvent, PickEvent);
214itkEventMacroDeclaration(AbortCheckEvent, PickEvent);
215itkEventMacroDeclaration(FunctionEvaluationIterationEvent, IterationEvent);
216itkEventMacroDeclaration(GradientEvaluationIterationEvent, IterationEvent);
217itkEventMacroDeclaration(FunctionAndGradientEvaluationIterationEvent, IterationEvent);
218itkEventMacroDeclaration(UserEvent, AnyEvent);
220#undef ITKEvent_EXPORT
221#define ITKEvent_EXPORT ITK_ABI_EXPORT
222
223} // end namespace itk
224
225#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:51
#define itkEventMacroDeclaration(classname, super)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, AnatomicalOrientation::CoordinateEnum value)