CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
Ptr< T > Class Template Reference

#include <Ptr.h>

Public Member Functions

void make_unique ()
 
 operator bool () const
 
Toperator* () const
 
Toperator-> () const
 
bool operator< (const Ptr< T > P) const
 
Ptroperator= (const Ptr &)
 
bool operator== (const Ptr< T > P) const
 
 Ptr ()
 
 Ptr (T *t)
 
 Ptr (const Ptr &h)
 
 ~Ptr ()
 

Private Attributes

Tp
 
std::size_t * refptr
 

Detailed Description

template<class T>
class Ptr< T >

Definition at line 9 of file Ptr.h.

Constructor & Destructor Documentation

template<class T>
Ptr< T >::Ptr ( )
inline

Definition at line 21 of file Ptr.h.

21 : p(0), refptr(new size_t(1)) { }
std::size_t * refptr
Definition: Ptr.h:39
T * p
Definition: Ptr.h:38
template<class T>
Ptr< T >::Ptr ( T t)
inline

Definition at line 22 of file Ptr.h.

22 : p(t), refptr(new size_t(1)) { }
std::size_t * refptr
Definition: Ptr.h:39
T * p
Definition: Ptr.h:38
template<class T>
Ptr< T >::Ptr ( const Ptr< T > &  h)
inline

Definition at line 23 of file Ptr.h.

References Ptr< T >::refptr.

23 : p(h.p), refptr(h.refptr) { ++*refptr; }
std::size_t * refptr
Definition: Ptr.h:39
T * p
Definition: Ptr.h:38
template<class T >
Ptr< T >::~Ptr ( )

Definition at line 72 of file Ptr.h.

73 {
74  if (--*refptr == 0) {
75  delete refptr;
76 /*
77  if (p)
78  std::cout << "DC:\t\tPtr deleted: " << std::endl;
79  else
80  std::cout << "DC: \t\tPtr deleted: dangling" << std::endl;
81  delete p;
82 */
83  }
84 }
std::size_t * refptr
Definition: Ptr.h:39

Member Function Documentation

template<class T>
void Ptr< T >::make_unique ( )
inline

Definition at line 12 of file Ptr.h.

References clone(), Ptr< T >::p, and Ptr< T >::refptr.

12  {
13  if (*refptr != 1) {
14  --*refptr;
15  refptr = new size_t(1);
16  p = p? clone(p): 0;
17  }
18  }
std::size_t * refptr
Definition: Ptr.h:39
T * clone(const T *tp)
Definition: Ptr.h:42
T * p
Definition: Ptr.h:38
template<class T>
Ptr< T >::operator bool ( ) const
inline

Definition at line 27 of file Ptr.h.

References Ptr< T >::p.

27 { return p; }
T * p
Definition: Ptr.h:38
template<class T >
T & Ptr< T >::operator* ( void  ) const

Definition at line 50 of file Ptr.h.

References L1TEmulatorMonitor_cff::p.

50 { if (p) return *p; throw std::runtime_error("unbound Ptr"); }
T * p
Definition: Ptr.h:38
template<class T >
T * Ptr< T >::operator-> ( ) const

Definition at line 53 of file Ptr.h.

References L1TEmulatorMonitor_cff::p.

53 { if (p) return p; throw std::runtime_error("unbound Ptr"); }
T * p
Definition: Ptr.h:38
template<class T>
bool Ptr< T >::operator< ( const Ptr< T P) const
inline

Definition at line 35 of file Ptr.h.

References P, and Ptr< T >::p.

35 { return p<P.p; }
T * p
Definition: Ptr.h:38
template<class T >
Ptr< T > & Ptr< T >::operator= ( const Ptr< T > &  rhs)

Definition at line 57 of file Ptr.h.

References Ptr< T >::p, L1TEmulatorMonitor_cff::p, and Ptr< T >::refptr.

58 {
59  ++*rhs.refptr;
60  // free the lhs, destroying pointers if appropriate
61  if (--*refptr == 0) {
62  delete refptr;
63  delete p;
64  }
65 
66  // copy in values from the right-hand side
67  refptr = rhs.refptr;
68  p = rhs.p;
69  return *this;
70 }
std::size_t * refptr
Definition: Ptr.h:39
T * p
Definition: Ptr.h:38
template<class T>
bool Ptr< T >::operator== ( const Ptr< T P) const
inline

Definition at line 32 of file Ptr.h.

References Ptr< T >::p.

32 { return p==P.p; }
T * p
Definition: Ptr.h:38

Member Data Documentation

template<class T>
T* Ptr< T >::p
private
template<class T>
std::size_t* Ptr< T >::refptr
private

Definition at line 39 of file Ptr.h.

Referenced by Ptr< T >::make_unique(), Ptr< T >::operator=(), and Ptr< T >::Ptr().