ITK  5.4.0
Insight Toolkit
itkObject.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 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef itkObject_h
29 #define itkObject_h
30 
31 #include "itkLightObject.h"
32 #include "itkEventObject.h"
33 #include "itkMetaDataDictionary.h"
34 #include "itkSingletonMacro.h"
35 
36 #include <functional>
37 #include <memory> // For unique_ptr.
38 
39 namespace itk
40 {
41 // Forward reference because of circular dependencies
42 class ITK_FORWARD_EXPORT Command;
43 
61 class ITKCommon_EXPORT Object : public LightObject
62 {
63 public:
64  ITK_DISALLOW_COPY_AND_MOVE(Object);
65 
67  using Self = Object;
71 
73  static Pointer
74  New();
75 
82  CreateAnother() const override;
83 
85  itkTypeMacro(Object, LightObject);
86 
88  virtual void
89  DebugOn() const;
90 
92  virtual void
93  DebugOff() const;
94 
96  bool
97  GetDebug() const;
98 
100  void
101  SetDebug(bool debugFlag) const;
102 
104  virtual ModifiedTimeType
105  GetMTime() const;
106 
108  virtual const TimeStamp &
109  GetTimeStamp() const;
110 
113  virtual void
114  Modified() const;
115 
117  void
118  Register() const override;
119 
121  void
122  UnRegister() const noexcept override;
123 
125  void
126  SetReferenceCount(int) override;
127 
130  static void
131  SetGlobalWarningDisplay(bool val);
132 
133  static bool
134  GetGlobalWarningDisplay();
135 
136  static void
137  GlobalWarningDisplayOn()
138  {
139  SetGlobalWarningDisplay(true);
140  }
141  static void
143  {
144  SetGlobalWarningDisplay(false);
145  }
146 
160  unsigned long
161  AddObserver(const EventObject & event, Command *);
162  unsigned long
163  AddObserver(const EventObject & event, Command *) const;
164 
182  unsigned long
183  AddObserver(const EventObject & event, std::function<void(const EventObject &)> function) const;
184 
190  Command *
191  GetCommand(unsigned long tag);
192 
194  void
195  InvokeEvent(const EventObject &);
196 
199  void
200  InvokeEvent(const EventObject &) const;
201 
203  void
204  RemoveObserver(unsigned long tag);
205 
207  void
208  RemoveAllObservers();
209 
211  bool
212  HasObserver(const EventObject & event) const;
213 
219  GetMetaDataDictionary();
220 
224  const MetaDataDictionary &
225  GetMetaDataDictionary() const;
226 
230  void
231  SetMetaDataDictionary(const MetaDataDictionary & rhs);
232  void
233  SetMetaDataDictionary(MetaDataDictionary && rrhs);
243  itkSetMacro(ObjectName, std::string);
244  itkGetConstReferenceMacro(ObjectName, std::string);
247 protected:
248  Object();
249  ~Object() override;
250 
255  void
256  PrintSelf(std::ostream & os, Indent indent) const override;
257 
258  bool
259  PrintObservers(std::ostream & os, Indent indent) const;
260 
264  virtual void
265  SetTimeStamp(const TimeStamp & timeStamp);
266 
267 private:
269  itkGetGlobalDeclarationMacro(bool, GlobalWarningDisplay);
270 
272  mutable bool m_Debug{ false };
273 
276 
278  static bool * m_GlobalWarningDisplay;
279 
280  // Forward reference because of private implementation
281  class SubjectImplementation;
282 
285  mutable std::unique_ptr<SubjectImplementation> m_SubjectImplementation;
286 
294  mutable std::unique_ptr<MetaDataDictionary> m_MetaDataDictionary{ nullptr };
295 
296  std::string m_ObjectName;
297 };
298 } // end namespace itk
299 
300 #endif
itk::Object::GlobalWarningDisplayOff
static void GlobalWarningDisplayOff()
Definition: itkObject.h:142
itk::ModifiedTimeType
SizeValueType ModifiedTimeType
Definition: itkIntTypes.h:102
itkSingletonMacro.h
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Object::m_SubjectImplementation
std::unique_ptr< SubjectImplementation > m_SubjectImplementation
Definition: itkObject.h:281
itk::Object::m_GlobalWarningDisplay
static bool * m_GlobalWarningDisplay
Definition: itkObject.h:278
itk::Command
Superclass for callback/observer methods.
Definition: itkCommand.h:45
itk::MetaDataDictionary
Provides a mechanism for storing a collection of arbitrary data types.
Definition: itkMetaDataDictionary.h:54
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::Object::m_ObjectName
std::string m_ObjectName
Definition: itkObject.h:296
itk::TimeStamp
Generate a unique, increasing time value.
Definition: itkTimeStamp.h:60
itkMetaDataDictionary.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Object::m_MTime
TimeStamp m_MTime
Definition: itkObject.h:275
itkGetGlobalDeclarationMacro
#define itkGetGlobalDeclarationMacro(Type, VarName)
Definition: itkSingletonMacro.h:35
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::EventObject
Abstraction of the Events used to communicating among filters and with GUIs.
Definition: itkEventObject.h:57
itkEventObject.h
New
static Pointer New()
itkLightObject.h