Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-03-13 09:06:16

0001 // ----------------------------------------------------------------------
0002 //
0003 // ZMhandleTo.icc - generic handle class for objects that need to be
0004 //   reference-counted
0005 //
0006 // History:
0007 //   19-Sep-1997  WEB  Design stolen, and code adapted, from
0008 //     Stroustrup: "The C++ Programming Language, 3rd ed" (1997), p 783
0009 //     Koenig & Moo: "Ruminations on C++" (1996), ch 7
0010 //   22-Sep-1997  WEB  Updated to require (& use) clone() operator
0011 //     for reference-counted objects; this is to insure against a user's
0012 //     destroying the object while one or more handles are still pointing
0013 //     to it
0014 //
0015 // ----------------------------------------------------------------------
0016 
0017 
0018 template< class T>
0019 inline ZMhandleTo<T>::ZMhandleTo()
0020 : u_()
0021 , rep_( new T )
0022 { ; }
0023 
0024 
0025 template< class T>
0026 inline ZMhandleTo<T>::ZMhandleTo( const ZMhandleTo<T> & h )
0027 : u_  ( h.u_   )
0028 , rep_( h.rep_ )
0029 { ; }  // copy constructor, share the representation
0030 
0031 
0032 template< class T>
0033 inline ZMhandleTo<T>::~ZMhandleTo()  {
0034   if ( u_.only() )
0035     delete rep_;
0036 }  // destructor
0037 
0038 
0039 template< class T>
0040 inline ZMhandleTo<T> & ZMhandleTo<T>::operator=( const ZMhandleTo<T> & rhs )  {
0041   if ( u_.reattach( rhs.u_) )
0042     delete rep_;
0043   rep_ = rhs.rep_;
0044 
0045   return *this;
0046 }  // operator=()
0047 
0048 
0049 template< class T>
0050 inline ZMhandleTo<T>::ZMhandleTo( const T & t )
0051 : rep_( t.clone() )
0052 { ; }
0053 
0054 
0055 template< class T>
0056 inline ZMhandleTo<T>::ZMhandleTo( const T * t )
0057 : rep_( t->clone() )
0058 { ; }