ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkLightObject.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkLightObject_h
00019 #define __itkLightObject_h
00020 
00021 #include "itkSmartPointer.h"
00022 #include "itkTimeStamp.h"
00023 #include "itkIndent.h"
00024 #include "itkSimpleFastMutexLock.h"
00025 
00026 #include <iostream>
00027 #include <typeinfo>
00028 
00029 #if defined( _WIN32 )
00030 // To get LONG defined
00031   #include "itkWindows.h"
00032 #elif defined( __APPLE__ )
00033 // To get MAC_OS_X_VERSION_MIN_REQUIRED defined
00034   #include <AvailabilityMacros.h>
00035 #endif
00036 
00037 namespace itk
00038 {
00054 class ITKCommon_EXPORT LightObject
00055 {
00056 public:
00058   typedef LightObject                Self;
00059   typedef SmartPointer< Self >       Pointer;
00060   typedef SmartPointer< const Self > ConstPointer;
00061 
00063   static Pointer New();
00064 
00070   virtual Pointer CreateAnother() const;
00071 
00072   itkCloneMacro(Self);
00073 
00077   virtual void Delete();
00078 
00082   virtual const char * GetNameOfClass() const
00083   { return "LightObject"; }
00084 
00085 #ifdef _WIN32
00086 
00087   void * operator new(size_t);
00088 
00089   void * operator new[](size_t);
00090 
00091   void operator delete(void *);
00092 
00093   void operator delete[](void *, size_t);
00094 
00095 #endif
00096 
00098   void Print(std::ostream & os, Indent indent = 0) const;
00099 
00102   static void BreakOnError();
00103 
00105   virtual void Register() const;
00106 
00108   virtual void UnRegister() const;
00109 
00111   virtual int GetReferenceCount() const
00112   { return static_cast< int >( m_ReferenceCount ); }
00113 
00116   virtual void SetReferenceCount(int);
00117 
00118 protected:
00119   LightObject():m_ReferenceCount(1) {}
00120   virtual ~LightObject();
00121 
00126   virtual void PrintSelf(std::ostream & os, Indent indent) const;
00127 
00128   virtual void PrintHeader(std::ostream & os, Indent indent) const;
00129 
00130   virtual void PrintTrailer(std::ostream & os, Indent indent) const;
00131 
00136   virtual LightObject::Pointer InternalClone() const;
00137 
00140 #if ( defined( WIN32 ) || defined( _WIN32 ) )
00141   typedef LONG InternalReferenceCountType;
00142 #elif defined( __APPLE__ ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 )
00143  #if defined ( __LP64__ ) && __LP64__
00144   typedef volatile int64_t InternalReferenceCountType;
00145  #else
00146   typedef volatile int32_t InternalReferenceCountType;
00147  #endif
00148 #elif defined( __GLIBCPP__ ) || defined( __GLIBCXX__ )
00149   typedef _Atomic_word InternalReferenceCountType;
00150 #else
00151   typedef int InternalReferenceCountType;
00152 #endif
00153 
00154 
00156   mutable InternalReferenceCountType m_ReferenceCount;
00157 
00159   mutable SimpleFastMutexLock m_ReferenceCountLock;
00160 private:
00161   LightObject(const Self &);    //purposely not implemented
00162   void operator=(const Self &); //purposely not implemented
00163 };
00164 } // end namespace itk
00166 
00167 #endif
00168