CLHEP  2.4.7.2
C++ Class Library for High Energy Physics
ZMuseCount.icc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 //
3 // ZMuseCount.icc - utility class for use in reference-counting
4 //
5 //
6 // History:
7 // 19-Sep-1997 WEB Design stolen, and code adapted, from pp 70-73 of
8 // Koenig & Moo: "Ruminations on C++" (1996)
9 // 23-Sep-1997 WEB Furnished overlooked body of copy constructor.
10 //
11 // ----------------------------------------------------------------------
12 
13 
14 ZMuseCount::ZMuseCount()
15 : p( new int(1) )
16 {
17  // DEBUG if ( p == 0 )
18  // DEBUG std::cerr << "ZMuseCount memory allocation failure!" << std::endl;
19 }
20 
21 
22 ZMuseCount::ZMuseCount( const ZMuseCount & u )
23 : p( u.p )
24 {
25  ++*p;
26 }
27 
28 
29 ZMuseCount::~ZMuseCount() {
30  if ( --*p == 0 )
31  delete p;
32 }
33 
34 
35 bool ZMuseCount::only() {
36  return *p == 1;
37 }