ITK  4.0.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 
00075   virtual void Delete();
00076 
00080   virtual const char * GetNameOfClass() const
00081   { return "LightObject"; }
00082 
00083 #ifdef _WIN32
00084 
00085   void * operator new(size_t);
00086 
00087   void * operator new[](size_t);
00088 
00089   void operator delete(void *);
00090 
00091   void operator delete[](void *, size_t);
00092 
00093 #endif
00094 
00096   void Print(std::ostream & os, Indent indent = 0) const;
00097 
00100   static void BreakOnError();
00101 
00103   virtual void Register() const;
00104 
00106   virtual void UnRegister() const;
00107 
00109   virtual int GetReferenceCount() const
00110   { return static_cast< int >( m_ReferenceCount ); }
00111 
00114   virtual void SetReferenceCount(int);
00115 
00116 protected:
00117   LightObject():m_ReferenceCount(1) {}
00118   virtual ~LightObject();
00119 
00124   virtual void PrintSelf(std::ostream & os, Indent indent) const;
00125 
00126   virtual void PrintHeader(std::ostream & os, Indent indent) const;
00127 
00128   virtual void PrintTrailer(std::ostream & os, Indent indent) const;
00129 
00132 #if ( defined( WIN32 ) || defined( _WIN32 ) )
00133   typedef LONG InternalReferenceCountType;
00134 #elif defined( __APPLE__ ) && ( MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 )
00135  #if defined ( __LP64__ ) && __LP64__
00136   typedef volatile int64_t InternalReferenceCountType;
00137  #else
00138   typedef volatile int32_t InternalReferenceCountType;
00139  #endif
00140 #elif defined( __GLIBCPP__ ) || defined( __GLIBCXX__ )
00141   typedef _Atomic_word InternalReferenceCountType;
00142 #else
00143   typedef int InternalReferenceCountType;
00144 #endif
00145 
00146 
00148   mutable InternalReferenceCountType m_ReferenceCount;
00149 
00151   mutable SimpleFastMutexLock m_ReferenceCountLock;
00152 private:
00153   LightObject(const Self &);    //purposely not implemented
00154   void operator=(const Self &); //purposely not implemented
00155 };
00156 } // end namespace itk
00158 
00159 #endif
00160