ITK  5.2.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  * 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 /*=========================================================================
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 
38 namespace itk
39 {
40 // Forward reference because of private implementation
41 class SubjectImplementation;
42 // Forward reference because of circular dependencies
43 class ITK_FORWARD_EXPORT Command;
44 
62 class ITKCommon_EXPORT Object : public LightObject
63 {
64 public:
65  ITK_DISALLOW_COPY_AND_MOVE(Object);
66 
68  using Self = Object;
72 
74  static Pointer
75  New();
76 
83  CreateAnother() const override;
84 
86  itkTypeMacro(Object, LightObject);
87 
89  virtual void
90  DebugOn() const;
91 
93  virtual void
94  DebugOff() const;
95 
97  bool
98  GetDebug() const;
99 
101  void
102  SetDebug(bool debugFlag) const;
103 
105  virtual ModifiedTimeType
106  GetMTime() const;
107 
109  virtual const TimeStamp &
110  GetTimeStamp() const;
111 
114  virtual void
115  Modified() const;
116 
118  void
119  Register() const override;
120 
122  void
123  UnRegister() const noexcept override;
124 
126  void
127  SetReferenceCount(int) override;
128 
131  static void
132  SetGlobalWarningDisplay(bool val);
133 
134  static bool
135  GetGlobalWarningDisplay();
136 
137  static void
138  GlobalWarningDisplayOn()
139  {
140  SetGlobalWarningDisplay(true);
141  }
142  static void
144  {
145  SetGlobalWarningDisplay(false);
146  }
147 
156  unsigned long
157  AddObserver(const EventObject & event, Command *);
158  unsigned long
159  AddObserver(const EventObject & event, Command *) 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);
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);
231 
239  itkSetMacro(ObjectName, std::string);
240  itkGetConstReferenceMacro(ObjectName, std::string);
242 
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 
272 
274  static bool * m_GlobalWarningDisplay;
275 
278  SubjectImplementation * m_SubjectImplementation{ nullptr };
279 
287  mutable MetaDataDictionary * m_MetaDataDictionary{ nullptr };
288 
289  std::string m_ObjectName;
290 };
291 } // end namespace itk
292 
293 #endif
itk::Object::GlobalWarningDisplayOff
static void GlobalWarningDisplayOff()
Definition: itkObject.h:143
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_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:53
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::Object::m_ObjectName
std::string m_ObjectName
Definition: itkObject.h:289
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:271
itkGetGlobalDeclarationMacro
#define itkGetGlobalDeclarationMacro(Type, VarName)
Definition: itkSingletonMacro.h:35
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::EventObject
Abstraction of the Events used to communicating among filters and with GUIs.
Definition: itkEventObject.h:57
itkEventObject.h
itkLightObject.h