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