Loading...
Searching...
No Matches
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.
| CountedRefPtr (ptr_type ptr)
| Convert from pointer.
template<bool Never>
| CountedRefPtr (const CountedRefPtr< ptr_type, !nondestructive, Never, count_type > &rhs)
| Convert from compatible smart pointer.
| CountedRefPtr (const self &rhs)
| Construct reference copy.
| ~CountedRefPtr ()
| Unlink one reference.
self & | operator= (const self &rhs)
self & | operator= (ptr_type ptr)
bool | operator== (const self &rhs) const
| Checking equality.
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.
count_type | count () const
| Store actual pointer.
void | reclaim ()
| Store actual pointer.
void | release ()
| Store actual pointer.

## 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.

{ nondestructive = Nondestructive, never_null = NeverNull };
CountedRefPtr
This class implements a smart pointer which handles pointer-style access to a reference-counted struc...
Definition countedref.h:43
CountedRefPtr::never_null
@ never_null
Definition countedref.h:50
CountedRefPtr::nondestructive
@ nondestructive
Definition countedref.h:50

## 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.

: m_ptr(NULL) {}
CountedRefPtr::m_ptr
ptr_type m_ptr
Store actual pointer.
Definition countedref.h:105

## 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.

: m_ptr(ptr) { reclaim(); }
CountedRefPtr::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.

:
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 reference copy.

Definition at line 65 of file countedref.h.

:
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.

{ release(); }
CountedRefPtr::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.

{ 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.

{ 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.

{ 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.

{ 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.

{ 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.

{ 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.

{ return operator=(rhs.m_ptr); }
CountedRefPtr::operator=
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.

{
release();
m_ptr = ptr;
reclaim();
return *this;
}

## 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.

{ 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.

{ 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.

{ 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.

{
if (*this && (--m_ptr->ref <= 0) && !nondestructive)
CountedRefPtr_kill(m_ptr);
}
CountedRefPtr_kill
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:

- Singular/countedref.h