3#include "ref_counted.h"
5#include <cgv/defines/assert.h>
6#include <cgv/type/cond/is_base_of.h>
7#include <cgv/type/cond/has_virtual_destructor.h>
18template <
class T,
bool is_ref_counted>
44template <
typename T,
bool is_ref_counted = false>
110 if (dec_ref_count(ptr)) {
133 template <
typename S>
150 return ptr ? ptr->get_ref_count() : 0;
158template <class T, bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
176 template <
typename S>
179 template <
typename S>
199 template <
typename S>
215 return this->
ref() == r.
ref();
219 return this->
ref() < r.
ref();
223 return this->
ref() != r.
ref();
234 operator bool ()
const {
246#include <cgv/config/lib_end.h>
if you derive your class from this class, a ref_ptr will do reference counting in the inhereted ref_c...
int get_ref_count() const
read access to current count
void set_ref_count(int c) const
write access is also const to allow ref counted pointers to const instances
ref_ptr_impl(T *p)
construct from pointer and increment reference count
T * ref() const
return the pointer itself
ref_ptr_impl(const ref_ptr_impl< T, true > &r)
copy construct from same pointer type and increment count
int get_count() const
return the reference count
void release()
if the pointer had been initialized before, decrement reference count and release pointer,...
ref_ptr_impl(const ref_ptr_impl< S, true > &s)
copy construct from pointer of derived type with virtual destructor
void release()
decrement the count, delete if it is 0
int get_count() const
return current count
ref_ptr_impl(T *p=0)
construct reference counted pointer
counter_type * counter
store pointer to counter struct
T * ref() const
return the pointer itself
ref_ptr_impl(const ref_ptr_impl< T, false > &r)
copy construct from same pointer type and increment count
ref_ptr_impl(const ref_ptr_impl< S, false > &s)
copy construct from pointer of derived type with virtual destructor
struct used to make ref pointers to ref_counted friends of ref_counted
bool dec_ref_count(const ref_counted *ptr) const
decrement the count of a ref counted object and return whether to delete the object
void inc_ref_count(const ref_counted *ptr) const
increment the count of a ref counted object
reference counted pointer, which can work together with types that are derived from ref_counted,...
bool empty() const
check if pointer is not yet set
ref_ptr_impl< T, is_ref_counted > base_type
type of base class that implements the reference count specific methods
ref_ptr(const ref_ptr< S, is_ref_counted > &s)
allow to copy ref_ptr to a ref_ptr<T> if T is a base class of S and if T has a virtual destructor
T * operator->() const
access to element pointer
ref_ptr(const this_type &r)
copy constructor for reference pointers of the same type
bool unique() const
check if this is the only reference
void clear()
set to null pointer
ref_ptr(T *p=0)
construction from pointer or empty if pointer is not given
this_type & operator=(const this_type &r)
assignment to pointer of same type
~ref_ptr()
destruct reference counted pointer
bool operator!=(const this_type &r) const
compare by pointer
T & operator*() const
access to element
bool operator<(const this_type &r) const
compare by pointer
ref_ptr< S, is_ref_counted > down_cast() const
use static cast to convert from T to S if T is a base class of S and has a virtual destructor
ref_ptr< T, is_ref_counted > this_type
type of the reference counted pointer
bool operator==(const this_type &r) const
compare by pointer
struct to store the pointer with a count
template condition returning, whether the passed type has a virtual destructor
template condition returning, whether the first argument is a base class of the second argument