Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

mitkRCPtr.h

00001 /*=========================================================================
00002 
00003   Program:   3DMed
00004   Date:      $Date: 2014-02-25 18:30:00 +0800 $
00005   Version:   $Version: 4.6.0 $
00006   Copyright: MIPG, Institute of Automation, Chinese Academy of Sciences
00007 
00008 =========================================================================*/
00009 
00010 
00011 #ifndef __mitkRCPtr_h
00012 #define __mitkRCPtr_h
00013 
00017 template<class T>
00018 class mitkRCPtr
00019 {
00020 public:
00021     mitkRCPtr(T* realPtr = 0)
00022     {
00023         m_Pointee = realPtr;
00024         if(m_Pointee)   m_Pointee->AddReference();
00025     }
00026 
00027     ~mitkRCPtr()
00028     {
00029         if(m_Pointee)    m_Pointee->RemoveReference();
00030     }
00031     
00032     mitkRCPtr& operator=(T* realPtr);
00033     mitkRCPtr& operator=(const mitkRCPtr& ptr); 
00034 
00035     T* operator->() const {return m_Pointee;}
00036     T& operator*() const  {return *m_Pointee;} 
00037     operator T*() {return m_Pointee;}
00038     operator T const *() const {return m_Pointee;}
00039 
00040 private:
00041     T *m_Pointee; 
00042 
00043     mitkRCPtr(const mitkRCPtr&) {}
00044 };
00045 //---------------------------------------------------------------------------
00046 template<class T>
00047 inline mitkRCPtr<T>& mitkRCPtr<T>::operator=(T* realPtr)
00048 {
00049     if(realPtr == m_Pointee) return *this;
00050     if(m_Pointee) m_Pointee->RemoveReference();
00051     m_Pointee = realPtr;
00052     if (m_Pointee) m_Pointee->AddReference();
00053     return *this;
00054 }
00055 //---------------------------------------------------------------------------
00056 
00057 //---------------------------------------------------------------------------
00058 template<class T>
00059 inline mitkRCPtr<T>& mitkRCPtr<T>::operator=(const mitkRCPtr& ptr)
00060 {
00061     if(ptr.m_Pointee == m_Pointee) return *this;
00062     if(m_Pointee) m_Pointee->RemoveReference();
00063     m_Pointee = ptr.m_Pointee;
00064     if (m_Pointee) m_Pointee->AddReference();
00065     return *this;
00066 }
00067 //---------------------------------------------------------------------------
00068 
00069 
00070  
00071 //#define DEFINED_mitkRCPtr
00072 
00073 
00074 
00075 #endif
00076 

Generated on Tue Feb 25 15:00:37 2014 for MITK (Medical Imaging ToolKit) by  doxygen 1.4.3