Remake
Loading...
Searching...
No Matches
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 481 of file remake.cpp.

Constructor & Destructor Documentation

◆ ref_ptr() [1/3]

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

Definition at line 491 of file remake.cpp.

491: ptr(NULL) {}
content * ptr
Definition remake.cpp:490

◆ ref_ptr() [2/3]

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

Definition at line 492 of file remake.cpp.

492: ptr(new content(t)) {}

◆ ref_ptr() [3/3]

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

Definition at line 493 of file remake.cpp.

493: ptr(p.ptr) { if (ptr) ++ptr->cnt; }

◆ ~ref_ptr()

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

Definition at line 494 of file remake.cpp.

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

Member Function Documentation

◆ operator*()

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

Definition at line 503 of file remake.cpp.

504 {
505 if (!ptr) ptr = new content;
506 return ptr->val;
507 }

◆ operator->()

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

Definition at line 508 of file remake.cpp.

508{ return &**this; }

◆ operator=()

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

Definition at line 495 of file remake.cpp.

496 {
497 if (ptr == p.ptr) return *this;
498 if (ptr && --ptr->cnt == 0) delete ptr;
499 ptr = p.ptr;
500 if (ptr) ++ptr->cnt;
501 return *this;
502 }

Member Data Documentation

◆ ptr

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

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