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"
34#include "itkSingletonMacro.h"
35
36#include <functional>
37#include <memory> // For unique_ptr.
38
39namespace itk
40{
41// Forward reference because of circular dependencies
42class ITK_FORWARD_EXPORT Command;
43
61class ITKCommon_EXPORT Object : public LightObject
62{
63public:
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 &
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
192
195 void
196 InvokeEvent(const EventObject &) const;
197
199 void
200 RemoveObserver(unsigned long tag) const;
201
203 void
205
207 bool
208 HasObserver(const EventObject & event) const;
209
216
220 const MetaDataDictionary &
222
226 void
228 void
239 itkSetMacro(ObjectName, std::string);
240 itkGetConstReferenceMacro(ObjectName, std::string);
243protected:
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
263private:
265 itkGetGlobalDeclarationMacro(bool, GlobalWarningDisplay);
266
268 mutable bool m_Debug{ false };
269
271 mutable TimeStamp m_MTime{};
272
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
Superclass for callback/observer methods.
Definition: itkCommand.h:46
Abstraction of the Events used to communicating among filters and with GUIs.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Provides a mechanism for storing a collection of arbitrary data types.
Base class for most ITK classes.
Definition: itkObject.h:62
void InvokeEvent(const EventObject &)
virtual const TimeStamp & GetTimeStamp() const
std::unique_ptr< SubjectImplementation > m_SubjectImplementation
Definition: itkObject.h:277
virtual ModifiedTimeType GetMTime() const
MetaDataDictionary & GetMetaDataDictionary()
virtual void DebugOff() const
void RemoveAllObservers()
static bool * m_GlobalWarningDisplay
Definition: itkObject.h:274
const MetaDataDictionary & GetMetaDataDictionary() const
~Object() override
void RemoveObserver(unsigned long tag) const
static void GlobalWarningDisplayOff()
Definition: itkObject.h:142
void UnRegister() const noexcept override
unsigned long AddObserver(const EventObject &event, Command *cmd) const
Add an observer/command to this object invoked for event.
unsigned long AddObserver(const EventObject &event, std::function< void(const EventObject &)> function) const
A convenient method to add an C++ lambda function as an observer.
void PrintSelf(std::ostream &os, Indent indent) const override
void SetMetaDataDictionary(MetaDataDictionary &&rrhs)
void SetMetaDataDictionary(const MetaDataDictionary &rhs)
void SetDebug(bool debugFlag) const
bool PrintObservers(std::ostream &os, Indent indent) const
LightObject::Pointer CreateAnother() const override
bool HasObserver(const EventObject &event) const
void Register() const override
virtual void SetTimeStamp(const TimeStamp &timeStamp)
static Pointer New()
void InvokeEvent(const EventObject &) const
itkGetGlobalDeclarationMacro(bool, GlobalWarningDisplay)
virtual void DebugOn() const
Command * GetCommand(unsigned long tag)
virtual void Modified() const
bool GetDebug() const
Generate a unique, increasing time value.
Definition: itkTimeStamp.h:61
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
SizeValueType ModifiedTimeType
Definition: itkIntTypes.h:105