My Project
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Types
CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType > Class Template Reference

This class implements a smart pointer which handles pointer-style access to a reference-counted structure and destructing the latter after use. More...

#include <countedref.h>

Public Types

enum  { nondestructive = Nondestructive , never_null = NeverNull }
 
typedef PtrType ptr_type
 
typedef CountType count_type
 

Public Member Functions

 CountedRefPtr ()
 Default constructor. More...
 
 CountedRefPtr (ptr_type ptr)
 Convert from pointer. More...
 
template<bool Never>
 CountedRefPtr (const CountedRefPtr< ptr_type, !nondestructive, Never, count_type > &rhs)
 Convert from compatible smart pointer. More...
 
 CountedRefPtr (const self &rhs)
 Construct refernce copy. More...
 
 ~CountedRefPtr ()
 Unlink one reference. More...
 
selfoperator= (const self &rhs)
 
selfoperator= (ptr_type ptr)
 
bool operator== (const self &rhs) const
 Checking equality. More...
 
bool operator== (ptr_type ptr) const
 
 operator bool () const
 
 operator const ptr_type () const
 
 operator ptr_type ()
 
const ptr_type operator-> () const
 
ptr_type operator-> ()
 

Private Types

typedef CountedRefPtr self
 

Reference count interface

ptr_type m_ptr
 Store actual pointer. More...
 
count_type count () const
 Store actual pointer. More...
 
void reclaim ()
 Store actual pointer. More...
 
void release ()
 Store actual pointer. More...
 

Detailed Description

template<class PtrType, bool Nondestructive = false, bool NeverNull = false, class CountType = short>
class CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >

This class implements a smart pointer which handles pointer-style access to a reference-counted structure and destructing the latter after use.

The template arguments, include the pointer type PtrType, and two integral (bool) properties: use Nondestructive to disallow destruction and NeverNull to assume, that PtrType cannot be NULL. Finally, CountType allows you to select a typ to represent the internal reference count.

Note
The class of PtrType must have an accessible integral attribute ref. For convenience use RefCounter as public base. In addition you must overload void CountedRefPtr_kill(PtrType) accordingly.

Definition at line 43 of file countedref.h.

Member Typedef Documentation

◆ count_type

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
typedef CountType CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::count_type

Definition at line 49 of file countedref.h.

◆ ptr_type

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
typedef PtrType CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::ptr_type

Definition at line 48 of file countedref.h.

◆ self

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
typedef CountedRefPtr CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::self
private

Definition at line 44 of file countedref.h.

Member Enumeration Documentation

◆ anonymous enum

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
anonymous enum
Enumerator
nondestructive 
never_null 

Definition at line 50 of file countedref.h.

50{ nondestructive = Nondestructive, never_null = NeverNull };

Constructor & Destructor Documentation

◆ CountedRefPtr() [1/4]

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::CountedRefPtr ( )
inline

Default constructor.

Note
: exisis only if NeverNull is false

Definition at line 54 of file countedref.h.

54: m_ptr(NULL) {}
ptr_type m_ptr
Store actual pointer.
Definition: countedref.h:105
#define NULL
Definition: omList.c:12

◆ CountedRefPtr() [2/4]

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::CountedRefPtr ( ptr_type  ptr)
inline

Convert from pointer.

Definition at line 57 of file countedref.h.

57: m_ptr(ptr) { reclaim(); }
void reclaim()
Store actual pointer.
Definition: countedref.h:96

◆ CountedRefPtr() [3/4]

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
template<bool Never>
CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::CountedRefPtr ( const CountedRefPtr< ptr_type, !nondestructive, Never, count_type > &  rhs)
inline

Convert from compatible smart pointer.

Definition at line 61 of file countedref.h.

61 :
62 m_ptr(rhs.m_ptr) { reclaim(); }

◆ CountedRefPtr() [4/4]

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::CountedRefPtr ( const self rhs)
inline

Construct refernce copy.

Definition at line 65 of file countedref.h.

65 :
66 m_ptr(rhs.m_ptr) { reclaim(); }

◆ ~CountedRefPtr()

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::~CountedRefPtr ( )
inline

Unlink one reference.

Definition at line 69 of file countedref.h.

69{ release(); }
void release()
Store actual pointer.
Definition: countedref.h:97

Member Function Documentation

◆ count()

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
count_type CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::count ( ) const
inline

Store actual pointer.

Definition at line 95 of file countedref.h.

95{ return (*this? m_ptr->ref: 0); }

◆ operator bool()

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::operator bool ( ) const
inline

Definition at line 86 of file countedref.h.

86{ return NeverNull || m_ptr; }

◆ operator const ptr_type()

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::operator const ptr_type ( ) const
inline

Definition at line 87 of file countedref.h.

87{ return m_ptr; }

◆ operator ptr_type()

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::operator ptr_type ( )
inline

Definition at line 88 of file countedref.h.

88{ return m_ptr; }

◆ operator->() [1/2]

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
ptr_type CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::operator-> ( )
inline

Definition at line 90 of file countedref.h.

90{ return *this; }

◆ operator->() [2/2]

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
const ptr_type CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::operator-> ( ) const
inline

Definition at line 89 of file countedref.h.

89{ return *this; }

◆ operator=() [1/2]

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
self & CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::operator= ( const self rhs)
inline

Definition at line 72 of file countedref.h.

72{ return operator=(rhs.m_ptr); }
self & operator=(const self &rhs)
Definition: countedref.h:72

◆ operator=() [2/2]

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
self & CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::operator= ( ptr_type  ptr)
inline

Definition at line 73 of file countedref.h.

73 {
74 release();
75 m_ptr = ptr;
76 reclaim();
77 return *this;
78 }

◆ operator==() [1/2]

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
bool CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::operator== ( const self rhs) const
inline

Checking equality.

Definition at line 82 of file countedref.h.

82{ return m_ptr == rhs.m_ptr; }

◆ operator==() [2/2]

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
bool CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::operator== ( ptr_type  ptr) const
inline

Definition at line 85 of file countedref.h.

85{ return m_ptr == ptr; }

◆ reclaim()

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
void CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::reclaim ( )
inline

Store actual pointer.

Definition at line 96 of file countedref.h.

96{ if (*this) ++m_ptr->ref; }

◆ release()

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
void CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::release ( )
inline

Store actual pointer.

Definition at line 97 of file countedref.h.

97 {
98 if (*this && (--m_ptr->ref <= 0) && !nondestructive)
100 }
void CountedRefPtr_kill(CountedRefIndirectPtr< PtrType > *pval)
Definition: countedref.h:151

Field Documentation

◆ m_ptr

template<class PtrType , bool Nondestructive = false, bool NeverNull = false, class CountType = short>
ptr_type CountedRefPtr< PtrType, Nondestructive, NeverNull, CountType >::m_ptr
private

Store actual pointer.

Definition at line 105 of file countedref.h.


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