3#include <cgv/defines/assert.h>
4#include <cgv/type/cond/is_base_of.h>
5#include <cgv/type/cond/has_virtual_destructor.h>
18 counter_type(T* a,
int c) : arr(a), count(c) {}
23 counter_type* counter;
30 if (--counter->count == 0) {
31 delete [] counter->arr;
40 explicit ref_arr(T* a = 0, counter_type* c = 0) : counter(c), arr(a) {
42 counter =
new counter_type(a, 1);
88 return counter ? counter->count : 0;
99 operator bool ()
const {
T & operator[](int i)
access to i-th element
ref_arr(const ref_arr< T > &ra)
copy construct from same pointer type and increment count
T * operator->() const
access to element pointer
void clear()
clear the array pointer
bool unique() const
check if this is the only reference
~ref_arr()
destruct reference counted pointer
int get_count() const
return current count
bool empty() const
check if pointer is not yet set
ref_arr< T > operator()(int i) const
return an array pointer pointing to the i-th element
ref_arr< T > & operator=(const ref_arr< T > &ra)
assignment to pointer of same type
bool operator==(const ref_arr< T > &ra) const
compare by pointer
T & operator*() const
access to element
ref_arr(T *a=0, counter_type *c=0)
construct reference counted pointer
T * ptr() const
return array pointer