ITK  6.0.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  itkOverrideGetNameOfClassMacro(Object);
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 
158  unsigned long
159  AddObserver(const EventObject & event, Command * cmd) const;
160 
178  unsigned long
179  AddObserver(const EventObject & event, std::function<void(const EventObject &)> function) const;
180 
186  Command *
187  GetCommand(unsigned long tag);
188 
190  void
191  InvokeEvent(const EventObject &);
192 
195  void
196  InvokeEvent(const EventObject &) const;
197 
199  void
200  RemoveObserver(unsigned long tag) const;
201 
203  void
204  RemoveAllObservers();
205 
207  bool
208  HasObserver(const EventObject & event) const;
209 
215  GetMetaDataDictionary();
216 
220  const MetaDataDictionary &
221  GetMetaDataDictionary() const;
222 
226  void
227  SetMetaDataDictionary(const MetaDataDictionary & rhs);
228  void
229  SetMetaDataDictionary(MetaDataDictionary && rrhs);
239  itkSetMacro(ObjectName, std::string);
240  itkGetConstReferenceMacro(ObjectName, std::string);
243 protected:
244  Object();
245  ~Object() override;
246 
251  void
252  PrintSelf(std::ostream & os, Indent indent) const override;
253 
254  bool
255  PrintObservers(std::ostream & os, Indent indent) const;
256 
260  virtual void
261  SetTimeStamp(const TimeStamp & timeStamp);
262 
263 private:
265  itkGetGlobalDeclarationMacro(bool, GlobalWarningDisplay);
266 
268  mutable bool m_Debug{ false };
269 
271  mutable TimeStamp m_MTime{};
272 
274  static bool * m_GlobalWarningDisplay;
275 
276  // Forward reference because of private implementation
277  class SubjectImplementation;
278 
281  mutable std::unique_ptr<SubjectImplementation> m_SubjectImplementation;
282 
290  mutable std::unique_ptr<MetaDataDictionary> m_MetaDataDictionary{ nullptr };
291 
292  std::string m_ObjectName{};
293 };
294 } // end namespace itk
295 
296 #endif
itk::Object::GlobalWarningDisplayOff
static void GlobalWarningDisplayOff()
Definition: itkObject.h:142
itk::ModifiedTimeType
SizeValueType ModifiedTimeType
Definition: itkIntTypes.h:105
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:277
itk::Object::m_GlobalWarningDisplay
static bool * m_GlobalWarningDisplay
Definition: itkObject.h:274
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::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: itkAnatomicalOrientation.h:29
itkGetGlobalDeclarationMacro
#define itkGetGlobalDeclarationMacro(Type, VarName)
Definition: itkSingletonMacro.h:34
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:58
itkEventObject.h
New
static Pointer New()
itkLightObject.h