CMS 3D CMS Logo

Public Member Functions | Private Attributes

Ptr< T > Class Template Reference

#include <Ptr.h>

List of all members.

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 (const Ptr &h)
 Ptr (T *t)
 ~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.

: p(0), refptr(new size_t(1))  { }
template<class T>
Ptr< T >::Ptr ( T t) [inline]

Definition at line 22 of file Ptr.h.

: p(t), refptr(new size_t(1)) { }
template<class T>
Ptr< T >::Ptr ( const Ptr< T > &  h) [inline]

Definition at line 23 of file Ptr.h.

References Ptr< T >::refptr.

: p(h.p), refptr(h.refptr)  { ++*refptr; }
template<class T >
Ptr< T >::~Ptr ( )

Definition at line 72 of file Ptr.h.

{
        if (--*refptr == 0) {
                delete refptr;
/*
                if (p)
                  std::cout << "DC:\t\tPtr deleted: " << std::endl;
                else
                  std::cout << "DC: \t\tPtr deleted: dangling" << std::endl;  
                delete p;
*/              
        }
}

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.

                           {
                if (*refptr != 1) {
                        --*refptr;
                        refptr = new size_t(1);
                        p = p? clone(p): 0;
                }
        }
template<class T>
Ptr< T >::operator bool ( ) const [inline]

Definition at line 27 of file Ptr.h.

References Ptr< T >::p.

{ return p; }
template<class T >
T & Ptr< T >::operator* ( void  ) const

Definition at line 50 of file Ptr.h.

References L1TEmulatorMonitor_cff::p.

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

Definition at line 53 of file Ptr.h.

References L1TEmulatorMonitor_cff::p.

{ if (p) return p; throw std::runtime_error("unbound Ptr"); }
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.

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

Definition at line 57 of file Ptr.h.

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

{
        ++*rhs.refptr;
        // free the lhs, destroying pointers if appropriate
        if (--*refptr == 0) {
                delete refptr;
                delete p;
        }

        // copy in values from the right-hand side
        refptr = rhs.refptr;
        p = rhs.p;
        return *this;
}
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.

{ return p==P.p; }

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().