ITK  5.2.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 
144 #define itkEventMacroDefinition(classname, super) \
145  classname::classname(const classname & s) \
146  : super(s){}; \
147  classname::~classname() {} \
148  const char * classname::GetEventName() const { return #classname; } \
149  bool classname::CheckEvent(const ::itk::EventObject * e) const \
150  { \
151  return (dynamic_cast<const classname *>(e) != nullptr); \
152  } \
153  ::itk::EventObject * classname::MakeObject() const { return new classname; }
154 
155 //
156 // This macro duplicates some of the declaration and definition
157 // macro code. The purpose is to provide a backward compatibility API
158 // for ITK applications.
159 // NOTE: New applications should use itkEventMacroDeclaration (in a
160 // .h file) and itkEventMacroDefinition (in a compiled .cxx
161 // file). This new approach guarantees that only one copy of the
162 // implementation will be present.
163 //
164 #define itkEventMacro(classname, super) \
165  \
166  class ITKEvent_EXPORT classname : public super \
167  { \
168  public: \
169  using Self = classname; \
170  using Superclass = super; \
171  classname() {} \
172  virtual ~classname() {} \
173  virtual const char * \
174  GetEventName() const \
175  { \
176  return #classname; \
177  } \
178  virtual bool \
179  CheckEvent(const ::itk::EventObject * e) const \
180  { \
181  return (dynamic_cast<const Self *>(e) != nullptr); \
182  } \
183  virtual ::itk::EventObject * \
184  MakeObject() const \
185  { \
186  return new Self; \
187  } \
188  classname(const Self & s) \
189  : super(s){}; \
190  \
191  private: \
192  void \
193  operator=(const Self &); \
194  };
195 
199 itkEventMacroDeclaration(NoEvent, EventObject) itkEventMacroDeclaration(AnyEvent, EventObject)
200  itkEventMacroDeclaration(DeleteEvent, AnyEvent) itkEventMacroDeclaration(StartEvent, AnyEvent)
201  itkEventMacroDeclaration(EndEvent, AnyEvent) itkEventMacroDeclaration(ProgressEvent, AnyEvent)
202  itkEventMacroDeclaration(ExitEvent, AnyEvent) itkEventMacroDeclaration(AbortEvent, AnyEvent)
203  itkEventMacroDeclaration(ModifiedEvent, AnyEvent) itkEventMacroDeclaration(InitializeEvent, AnyEvent)
204  itkEventMacroDeclaration(IterationEvent, AnyEvent)
205  itkEventMacroDeclaration(MultiResolutionIterationEvent, IterationEvent)
206  itkEventMacroDeclaration(PickEvent, AnyEvent) itkEventMacroDeclaration(StartPickEvent, PickEvent)
207  itkEventMacroDeclaration(EndPickEvent, PickEvent) itkEventMacroDeclaration(AbortCheckEvent, PickEvent)
208  itkEventMacroDeclaration(FunctionEvaluationIterationEvent, IterationEvent)
209  itkEventMacroDeclaration(GradientEvaluationIterationEvent, IterationEvent)
210  itkEventMacroDeclaration(FunctionAndGradientEvaluationIterationEvent, IterationEvent)
211  itkEventMacroDeclaration(UserEvent, AnyEvent)
212 
213 #undef ITKEvent_EXPORT
214 #define ITKEvent_EXPORT ITK_ABI_EXPORT
215 
216 } // end namespace itk
217 
218 #endif
itk::operator<<
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:213
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
itk::itkEventMacroDeclaration
itkEventMacroDeclaration(NoEvent, EventObject) itkEventMacroDeclaration(AnyEvent