Remake
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Classes | Public Member Functions | Public Attributes | List of all members
ref_ptr< T > Struct Template Reference

Classes

struct  content
 

Public Member Functions

 ref_ptr ()
 
 ref_ptr (T const &t)
 
 ref_ptr (ref_ptr const &p)
 
 ~ref_ptr ()
 
ref_ptroperator= (ref_ptr const &p)
 
T & operator* () const
 
T * operator-> () const
 

Public Attributes

contentptr
 

Detailed Description

template<class T>
struct ref_ptr< T >

Reference-counted shared object.

Note
The default constructor delays the creation of the object until it is first dereferenced.

Definition at line 425 of file remake.cpp.

Constructor & Destructor Documentation

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

Definition at line 435 of file remake.cpp.

435 : ptr(NULL) {}
template<class T>
ref_ptr< T >::ref_ptr ( T const &  t)
inline

Definition at line 436 of file remake.cpp.

436 : ptr(new content(t)) {}
template<class T>
ref_ptr< T >::ref_ptr ( ref_ptr< T > const &  p)
inline

Definition at line 437 of file remake.cpp.

437 : ptr(p.ptr) { if (ptr) ++ptr->cnt; }
template<class T>
ref_ptr< T >::~ref_ptr ( )
inline

Definition at line 438 of file remake.cpp.

438 { if (ptr && --ptr->cnt == 0) delete ptr; }

Member Function Documentation

template<class T>
T& ref_ptr< T >::operator* ( ) const
inline

Definition at line 447 of file remake.cpp.

448  {
449  if (!ptr) ptr = new content;
450  return ptr->val;
451  }
template<class T>
T* ref_ptr< T >::operator-> ( ) const
inline

Definition at line 452 of file remake.cpp.

452 { return &**this; }
template<class T>
ref_ptr& ref_ptr< T >::operator= ( ref_ptr< T > const &  p)
inline

Definition at line 439 of file remake.cpp.

440  {
441  if (ptr == p.ptr) return *this;
442  if (ptr && --ptr->cnt == 0) delete ptr;
443  ptr = p.ptr;
444  if (ptr) ++ptr->cnt;
445  return *this;
446  }

Member Data Documentation

template<class T>
content* ref_ptr< T >::ptr
mutable

The documentation for this struct was generated from the following file: