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"
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
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
196
199 void
200 InvokeEvent(const EventObject &) const;
201
203 void
204 RemoveObserver(unsigned long tag);
205
207 void
209
211 bool
212 HasObserver(const EventObject & event) const;
213
220
224 const MetaDataDictionary &
226
230 void
232 void
243 itkSetMacro(ObjectName, std::string);
244 itkGetConstReferenceMacro(ObjectName, std::string);
247protected:
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
267private:
269 itkGetGlobalDeclarationMacro(bool, GlobalWarningDisplay);
270
272 mutable bool m_Debug{ false };
273
275 mutable TimeStamp m_MTime{};
276
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
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:281
virtual ModifiedTimeType GetMTime() const
MetaDataDictionary & GetMetaDataDictionary()
unsigned long AddObserver(const EventObject &event, Command *) const
virtual void DebugOff() const
void RemoveAllObservers()
unsigned long AddObserver(const EventObject &event, Command *)
Add an observer/command to this object invoked for event.
static bool * m_GlobalWarningDisplay
Definition: itkObject.h:278
const MetaDataDictionary & GetMetaDataDictionary() const
~Object() override
static void GlobalWarningDisplayOff()
Definition: itkObject.h:142
void UnRegister() const noexcept override
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
void RemoveObserver(unsigned long tag)
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:102