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
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 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
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}
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
206itkEventMacroDeclaration(DeleteEvent, AnyEvent);
207itkEventMacroDeclaration(StartEvent, AnyEvent);
208itkEventMacroDeclaration(EndEvent, AnyEvent);
209itkEventMacroDeclaration(ProgressEvent, AnyEvent);
210itkEventMacroDeclaration(ExitEvent, AnyEvent);
211itkEventMacroDeclaration(AbortEvent, AnyEvent);
212itkEventMacroDeclaration(ModifiedEvent, AnyEvent);
213itkEventMacroDeclaration(InitializeEvent, AnyEvent);
214itkEventMacroDeclaration(IterationEvent, AnyEvent);
215itkEventMacroDeclaration(MultiResolutionIterationEvent, IterationEvent);
216itkEventMacroDeclaration(PickEvent, AnyEvent);
217itkEventMacroDeclaration(StartPickEvent, PickEvent);
218itkEventMacroDeclaration(EndPickEvent, PickEvent);
219itkEventMacroDeclaration(AbortCheckEvent, PickEvent);
220itkEventMacroDeclaration(FunctionEvaluationIterationEvent, IterationEvent);
221itkEventMacroDeclaration(GradientEvaluationIterationEvent, IterationEvent);
222itkEventMacroDeclaration(FunctionAndGradientEvaluationIterationEvent, IterationEvent);
223itkEventMacroDeclaration(UserEvent, AnyEvent);
226#undef ITKEvent_EXPORT
227#define ITKEvent_EXPORT ITK_ABI_EXPORT
228
229} // end namespace itk
230
231#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....
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
itkEventMacroDeclaration(NoEvent, EventObject)