ITK  4.3.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 "itkSmartPointer.h"
22 #include "itkTimeStamp.h"
23 #include "itkIndent.h"
24 #include "itkSimpleFastMutexLock.h"
25 
26 #include <iostream>
27 #include <typeinfo>
28 
29 #if defined( _WIN32 )
30 // To get LONG defined
31  #include "itkWindows.h"
32 #elif defined( __APPLE__ )
33 // To get MAC_OS_X_VERSION_MIN_REQUIRED defined
34  #include <AvailabilityMacros.h>
35 #endif
36 
37 namespace itk
38 {
54 class ITKCommon_EXPORT LightObject
55 {
56 public:
58  typedef LightObject Self;
61 
63  static Pointer New();
64 
70  virtual Pointer CreateAnother() const;
71 
72  itkCloneMacro(Self);
73 
77  virtual void Delete();
78 
82  virtual const char * GetNameOfClass() const
83  { return "LightObject"; }
84 
85 #ifdef _WIN32
86 
87  void * operator new(size_t);
88 
89  void * operator new[](size_t);
90 
91  void operator delete(void *);
92 
93  void operator delete[](void *, size_t);
94 
95 #endif
96 
98  void Print(std::ostream & os, Indent indent = 0) const;
99 
102  static void BreakOnError();
103 
105  virtual void Register() const;
106 
108  virtual void UnRegister() const;
109 
111  virtual int GetReferenceCount() const
112  { return static_cast< int >( m_ReferenceCount ); }
113 
116  virtual void SetReferenceCount(int);
117 
118 protected:
119  LightObject():m_ReferenceCount(1) {}
120  virtual ~LightObject();
121 
126  virtual void PrintSelf(std::ostream & os, Indent indent) const;
127 
128  virtual void PrintHeader(std::ostream & os, Indent indent) const;
129 
130  virtual void PrintTrailer(std::ostream & os, Indent indent) const;
131 
136  virtual LightObject::Pointer InternalClone() const;
137 
140 #if ( defined( WIN32 ) || defined( _WIN32 ) )
141  typedef LONG InternalReferenceCountType;
142 #elif defined( __APPLE__ ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 )
143  #if defined ( __LP64__ ) && __LP64__
144  typedef volatile int64_t InternalReferenceCountType;
145  #else
146  typedef volatile int32_t InternalReferenceCountType;
147  #endif
148 #elif defined( __GLIBCPP__ ) || defined( __GLIBCXX__ )
149  typedef _Atomic_word InternalReferenceCountType;
150 #else
152 #endif
153 
154 
157 
160 
161 private:
162  LightObject(const Self &); //purposely not implemented
163  void operator=(const Self &); //purposely not implemented
164 };
165 } // end namespace itk
166 
167 #endif
168