ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkLightObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 #ifndef itkLightObject_h
19 #define itkLightObject_h
20 
21 #include "itkMacro.h"
22 #include "itkSmartPointer.h"
23 #include "itkTimeStamp.h"
24 #include "itkIndent.h"
25 #include <atomic>
26 
27 #include <iostream>
28 #include <typeinfo>
29 
30 #if defined( _WIN32 )
31 // To get LONG defined
32  #include "itkWindows.h"
33 #elif defined( __APPLE__ )
34 // To get MAC_OS_X_VERSION_MIN_REQUIRED defined
35  #include <AvailabilityMacros.h>
36 #endif
37 
38 namespace itk
39 {
55 class ITKCommon_EXPORT LightObject
56 {
57 public:
58  ITK_DISALLOW_COPY_AND_ASSIGN(LightObject);
59 
61  using Self = LightObject;
64 
66  static Pointer New();
67 
73  virtual Pointer CreateAnother() const;
74 
75  itkCloneMacro(Self);
76 
80  virtual void Delete();
81 
85  virtual const char * GetNameOfClass() const;
86 
87 #ifdef _WIN32
88 
89  void * operator new(size_t);
90 
91  void * operator new[](size_t);
92 
93  void operator delete(void *);
94 
95  void operator delete[](void *, size_t);
96 
97 #endif
98 
100  void Print(std::ostream & os, Indent indent = 0) const;
101 
104  static void BreakOnError();
105 
107  virtual void Register() const;
108 
110  virtual void UnRegister() const noexcept;
111 
113  virtual int GetReferenceCount() const
114  { return m_ReferenceCount; }
115 
118  virtual void SetReferenceCount(int);
119 
120 protected:
121  LightObject();
122  virtual ~LightObject();
123 
128  virtual void PrintSelf(std::ostream & os, Indent indent) const;
129 
130  virtual void PrintHeader(std::ostream & os, Indent indent) const;
131 
132  virtual void PrintTrailer(std::ostream & os, Indent indent) const;
133 
138  virtual LightObject::Pointer InternalClone() const;
139 
141  mutable std::atomic<int> m_ReferenceCount;
142 
143 };
144 
151 ITKCommon_EXPORT std::ostream &
152 operator<<(std::ostream & os, const LightObject & o);
153 
154 } // end namespace itk
155 
156 #endif
Light weight base class for most itk classes.
std::atomic< int > m_ReferenceCount
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:188
Control indentation during Print() invocation.
Definition: itkIndent.h:49