00001 #ifndef DCHAIN_REFERENCEHOLDERBASE_H 00002 #define DCHAIN_REFERENCEHOLDERBASE_H 00003 // -*- C++ -*- 00004 // 00005 // Package: DChain 00006 // Module: ReferenceHolderBase 00007 // 00008 // Description: Base implementation of smart pointer for classes that inherit from ReferenceCount 00009 // 00010 // Usage: 00011 // ReferenceHolderBase() - default constructor 00012 // ~ReferenceHolderBase() - destructor 00013 // 00014 // Author: Simon Patton 00015 // Created: Fri May 17 08:01:51 EDT 1996 00016 // $Id: ReferenceHolderBase.h,v 1.1.1.1 2009/03/03 06:06:56 maqm Exp $ 00017 // 00018 // Revision history 00019 // 00020 // $Log: ReferenceHolderBase.h,v $ 00021 // Revision 1.1.1.1 2009/03/03 06:06:56 maqm 00022 // first import of DecayChain 00023 // 00024 // Revision 1.1 2006/01/11 20:28:10 cdj 00025 // massive class renaming, addition of [] for selection and unit tests 00026 // 00027 // Revision 1.1 2003/05/15 19:56:02 cdj 00028 // revamped memory handling so always use a ReferenceHolder to deal with the reference counting 00029 // 00030 // 00031 00032 // system include files 00033 00034 // user include files 00035 00036 00037 // forward declarations 00038 namespace dchain { 00039 template< class TPtr, class TRef> 00040 class ReferenceHolderBase 00041 { 00042 public: 00043 // Constructors and destructor 00044 ReferenceHolderBase() : m_ref(0) {} 00045 ReferenceHolderBase(TPtr iRef) : m_ref(iRef) { 00046 if(0 != m_ref) { m_ref->addLink(); } } 00047 ~ReferenceHolderBase() { 00048 if (0 != m_ref ) {m_ref->dropLink();} 00049 } 00050 00051 ReferenceHolderBase( const ReferenceHolderBase<TPtr,TRef>& iOther) : 00052 m_ref( iOther.m_ref ) { 00053 if(0 != m_ref ) { 00054 m_ref->addLink(); 00055 } 00056 } 00057 00058 // assignment operator(s) 00059 const ReferenceHolderBase& operator=( const ReferenceHolderBase<TPtr,TRef>& iRHS) { 00060 if( 0 != iRHS.m_ref ) { 00061 iRHS.m_ref->addLink(); 00062 } 00063 if( 0 != m_ref ) { 00064 m_ref->dropLink(); 00065 } 00066 m_ref = iRHS.m_ref; 00067 return *this; 00068 } 00069 00070 // const member functions 00071 TPtr operator->() const { 00072 return m_ref; 00073 } 00074 00075 TRef operator*() const { 00076 return *m_ref; 00077 } 00078 00079 TPtr pointer() const { 00080 return m_ref; 00081 } 00082 00083 private: 00084 00085 // data members 00086 TPtr m_ref; 00087 00088 }; 00089 00090 // inline function definitions 00091 00092 // 00093 // constructors and destructor 00094 // 00095 00096 // 00097 // member functions 00098 // 00099 00100 } 00101 #endif // DCHAIN_REFERENCEHOLDERBASE_H