31 #ifndef __BASE_REFCNT_HH__
32 #define __BASE_REFCNT_HH__
180 T *
get()
const {
return data; }
193 operator bool()
const {
return data != 0; }
199 {
return l.
get() == r.
get(); }
205 {
return l.
get() ==
r; }
211 {
return l == r.
get(); }
216 {
return l.
get() != r.
get(); }
222 {
return l.
get() !=
r; }
228 {
return l != r.
get(); }
230 #endif // __BASE_REFCNT_HH__
bool operator!() const
Check if the pointer is empty.
virtual ~RefCounted()
We make the destructor virtual because we're likely to have virtual functions on reference counted ob...
T * get() const
Directly access the pointer itself without taking a reference.
If you want a reference counting pointer to a mutable object, create it like this: ...
RefCountingPtr()
Create an empty reference counting pointer.
const RefCountingPtr & operator=(T *p)
Assign a new value to the pointer.
void set(T *d)
Drop the old reference and change it to something new.
~RefCountingPtr()
Destroy the pointer and any reference it may hold.
RefCounted()
We initialize the reference count to zero and the first object to take ownership of it must increment...
T * operator->() const
Access a member variable.
void del()
Delete the reference to any existing object if it is non NULL.
Derive from RefCounted if you want to enable reference counting of this class.
RefCountingPtr(T *data)
Create a new reference counting pointer to some object (probably something newly created).
RefCountingPtr(const RefCountingPtr &r)
Create a new reference counting pointer by copying another one.
bool operator==(const RefCountingPtr< T > &l, const RefCountingPtr< T > &r)
Check for equality of two reference counting pointers.
RefCounted & operator=(const RefCounted &)
void copy(T *d)
Copy a new pointer value and increment the reference count if it is a valid pointer.
bool operator!=(const RefCountingPtr< T > &l, const RefCountingPtr< T > &r)
Check for inequality of two reference counting pointers.
const RefCountingPtr & operator=(const RefCountingPtr &r)
Copy the pointer from another RefCountingPtr.
T * data
The stored pointer.
void incref()
Increment the reference count.
void decref()
Decrement the reference count and destroy the object if all references are gone.
T & operator*() const
Dereference the pointer.