CLHEP 2.4.7.1
C++ Class Library for High Energy Physics
ZMhandleTo.icc
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// ZMhandleTo.icc - generic handle class for objects that need to be
4// reference-counted
5//
6// History:
7// 19-Sep-1997 WEB Design stolen, and code adapted, from
8// Stroustrup: "The C++ Programming Language, 3rd ed" (1997), p 783
9// Koenig & Moo: "Ruminations on C++" (1996), ch 7
10// 22-Sep-1997 WEB Updated to require (& use) clone() operator
11// for reference-counted objects; this is to insure against a user's
12// destroying the object while one or more handles are still pointing
13// to it
14//
15// ----------------------------------------------------------------------
16
17
18template< class T>
20: u_()
21, rep_( new T )
22{ ; }
23
24
25template< class T>
27: u_ ( h.u_ )
28, rep_( h.rep_ )
29{ ; } // copy constructor, share the representation
31
32template< class T>
34 if ( u_.only() )
35 delete rep_;
36} // destructor
37
38
39template< class T>
41 if ( u_.reattach( rhs.u_) )
42 delete rep_;
43 rep_ = rhs.rep_;
44
45 return *this;
46} // operator=()
47
48
49template< class T>
50inline ZMhandleTo<T>::ZMhandleTo( const T & t )
51: rep_( t.clone() )
52{ ; }
53
54
55template< class T>
56inline ZMhandleTo<T>::ZMhandleTo( const T * t )
57: rep_( t->clone() )
58{ ; }
ZMuseCount u_
Definition ZMhandleTo.h:38
ZMhandleTo & operator=(const ZMhandleTo &rhs)