CLHEP
2.4.7.1
C++ Class Library for High Energy Physics
CLHEP
RefCount
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
18
template
<
class
T>
19
inline
ZMhandleTo<T>::ZMhandleTo
()
20
:
u_
()
21
,
rep_
( new T )
22
{ ; }
23
24
25
template
<
class
T>
26
inline
ZMhandleTo<T>::ZMhandleTo
(
const
ZMhandleTo<T>
& h )
27
:
u_
( h.
u_
)
28
,
rep_
( h.
rep_
)
29
{ ; }
// copy constructor, share the representation
30
31
32
template
<
class
T>
33
inline
ZMhandleTo<T>::~ZMhandleTo
() {
34
if
(
u_
.only() )
35
delete
rep_
;
36
}
// destructor
37
38
39
template
<
class
T>
40
inline
ZMhandleTo<T>
&
ZMhandleTo<T>::operator=
(
const
ZMhandleTo<T>
& rhs ) {
41
if
(
u_
.reattach( rhs.
u_
) )
42
delete
rep_
;
43
rep_
= rhs.
rep_
;
44
45
return
*
this
;
46
}
// operator=()
47
48
49
template
<
class
T>
50
inline
ZMhandleTo<T>::ZMhandleTo
(
const
T & t )
51
:
rep_
( t.clone() )
52
{ ; }
53
54
55
template
<
class
T>
56
inline
ZMhandleTo<T>::ZMhandleTo
(
const
T * t )
57
:
rep_
( t->clone() )
58
{ ; }
ZMhandleTo::ZMhandleTo
ZMhandleTo()
Definition
ZMhandleTo.icc:19
ZMhandleTo::~ZMhandleTo
~ZMhandleTo()
Definition
ZMhandleTo.icc:33
ZMhandleTo::rep_
T * rep_
Definition
ZMhandleTo.h:39
ZMhandleTo::u_
ZMuseCount u_
Definition
ZMhandleTo.h:38
ZMhandleTo::operator=
ZMhandleTo & operator=(const ZMhandleTo &rhs)
Definition
ZMhandleTo.icc:40
Generated by
1.13.2