Fawkes API
Fawkes Development Version
|
RefPtr<> is a reference-counting shared smartpointer. More...
#include <refptr.h>
Public Member Functions | |
RefPtr () | |
Default constructor. | |
~RefPtr () | |
Destructor - decrements reference count. | |
RefPtr (T_CppObject *cpp_object) | |
Constructor that takes ownership. | |
RefPtr (const RefPtr< T_CppObject > &src) | |
Copy constructor This increments the shared reference count. | |
template<class T_CastFrom > | |
RefPtr (const RefPtr< T_CastFrom > &src) | |
Copy constructor (from different, but castable type). | |
void | swap (RefPtr< T_CppObject > &other) |
Swap the contents of two RefPtr<>. | |
RefPtr< T_CppObject > & | operator= (const RefPtr< T_CppObject > &src) |
Copy from another RefPtr. | |
template<class T_CastFrom > | |
RefPtr< T_CppObject > & | operator= (const RefPtr< T_CastFrom > &src) |
Copy from different, but castable type). | |
RefPtr< T_CppObject > & | operator= (T_CppObject *ptr) |
Assign object and claim ownership. | |
bool | operator== (const RefPtr< T_CppObject > &src) const |
Tests whether the RefPtr<> point to the same underlying instance. | |
bool | operator!= (const RefPtr< T_CppObject > &src) const |
Tests whether the RefPtr<> do not point to the same underlying instance. | |
T_CppObject * | operator-> () const |
Dereferencing. | |
T_CppObject * | operator* () const |
Get underlying pointer. | |
operator bool () const | |
Test whether the RefPtr<> points to any underlying instance. | |
void | clear () |
Set underlying instance to 0, decrementing reference count of existing instance appropriately. | |
void | reset () |
Reset pointer. | |
RefPtr (T_CppObject *cpp_object, int *refcount, Mutex *refmutex) | |
For use only in the internal implementation of sharedptr. | |
int * | refcount_ptr () const |
For use only in the internal implementation of sharedptr. | |
int | use_count () const |
Get current reference count. | |
Mutex * | refmutex_ptr () const |
For use only in the internal implementation of sharedptr. | |
Static Public Member Functions | |
template<class T_CastFrom > | |
static RefPtr< T_CppObject > | cast_dynamic (const RefPtr< T_CastFrom > &src) |
Dynamic cast to derived class. | |
template<class T_CastFrom > | |
static RefPtr< T_CppObject > | cast_static (const RefPtr< T_CastFrom > &src) |
Static cast to derived class. | |
template<class T_CastFrom > | |
static RefPtr< T_CppObject > | cast_const (const RefPtr< T_CastFrom > &src) |
Cast to non-const. | |
Related Functions | |
(Note that these are not member functions.) | |
template<class T_CppObject > | |
void | swap (RefPtr< T_CppObject > &lrp, RefPtr< T_CppObject > &rrp) |
Swap refptr instances. |
RefPtr<> is a reference-counting shared smartpointer.
Reference counting means that a shared reference count is incremented each time a RefPtr is copied, and decremented each time a RefPtr is destroyed, for instance when it leaves its scope. When the reference count reaches zero, the contained object is deleted
Fawkes uses RefPtr so that you don't need to remember to delete the object explicitly, or know when a method expects you to delete the object that it returns.
Note that RefPtr is thread-safe.
fawkes::RefPtr::RefPtr | ( | ) | [inline] |
fawkes::RefPtr::~RefPtr | ( | ) | [inline] |
fawkes::RefPtr::RefPtr | ( | T_CppObject * | cpp_object | ) | [inline, explicit] |
fawkes::RefPtr::RefPtr | ( | const RefPtr< T_CppObject > & | src | ) | [inline] |
Copy constructor This increments the shared reference count.
src | refptr to copy |
Definition at line 311 of file refptr.h.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
fawkes::RefPtr::RefPtr | ( | const RefPtr< T_CastFrom > & | src | ) | [inline] |
Copy constructor (from different, but castable type).
Increments the reference count.
src | refptr to copy |
Definition at line 331 of file refptr.h.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
fawkes::RefPtr::RefPtr | ( | T_CppObject * | cpp_object, |
int * | refcount, | ||
Mutex * | refmutex | ||
) | [inline, explicit] |
For use only in the internal implementation of sharedptr.
cpp_object | C++ object to wrap |
refcount | reference count |
refmutex | reference count mutex |
Definition at line 297 of file refptr.h.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
RefPtr< T_CppObject > fawkes::RefPtr::cast_const | ( | const RefPtr< T_CastFrom > & | src | ) | [inline, static] |
Cast to non-const.
The RefPtr can't be cast with the usual notation so instead you can use
ptr_unconst = RefPtr<UnConstType>::cast_const(ptr_const);
src | source refptr to cast |
RefPtr< T_CppObject > fawkes::RefPtr::cast_dynamic | ( | const RefPtr< T_CastFrom > & | src | ) | [inline, static] |
Dynamic cast to derived class.
The RefPtr can't be cast with the usual notation so instead you can use
ptr_derived = RefPtr<Derived>::cast_dynamic(ptr_base);
src | source refptr to cast |
RefPtr< T_CppObject > fawkes::RefPtr::cast_static | ( | const RefPtr< T_CastFrom > & | src | ) | [inline, static] |
Static cast to derived class.
Like the dynamic cast; the notation is
ptr_derived = RefPtr<Derived>::cast_static(ptr_base);
src | source refptr to cast |
void fawkes::RefPtr::clear | ( | ) | [inline] |
Set underlying instance to 0, decrementing reference count of existing instance appropriately.
Definition at line 439 of file refptr.h.
Referenced by fawkes::InterruptibleBarrier::reset(), fawkes::InterruptibleBarrier::wait(), Roomba500Thread::init(), and Roomba500Thread::finalize().
fawkes::RefPtr::operator bool | ( | ) | const [inline] |
bool fawkes::RefPtr::operator!= | ( | const RefPtr< T_CppObject > & | src | ) | const [inline] |
T_CppObject * fawkes::RefPtr::operator* | ( | ) | const [inline] |
T_CppObject * fawkes::RefPtr::operator-> | ( | ) | const [inline] |
RefPtr< T_CppObject > & fawkes::RefPtr::operator= | ( | T_CppObject * | ptr | ) | [inline] |
bool fawkes::RefPtr::operator== | ( | const RefPtr< T_CppObject > & | src | ) | const [inline] |
int* fawkes::RefPtr::refcount_ptr | ( | ) | const [inline] |
Mutex* fawkes::RefPtr::refmutex_ptr | ( | ) | const [inline] |
void fawkes::RefPtr::reset | ( | ) | [inline] |
Reset pointer.
Set underlying instance to 0, decrementing reference count of existing instance appropriately.
Definition at line 446 of file refptr.h.
Referenced by KatanaActThread::loop(), PanTiltDirectedPerceptionThread::WorkerThread::loop(), and TabletopObjectsThread::finalize().
void fawkes::RefPtr::swap | ( | RefPtr< T_CppObject > & | other | ) | [inline] |
int fawkes::RefPtr::use_count | ( | ) | const [inline] |
Get current reference count.
Definition at line 211 of file refptr.h.
Referenced by OpenNiPclOnlyThread::loop().