fawkes::RefPtr< T_CppObject > Class Template Reference
[Fawkes Core Library]
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. | |
| 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. | |
| 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. | |
| 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. | |
Detailed Description
template<class T_CppObject>
class fawkes::RefPtr< T_CppObject >
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, and to prevent any need to manually reference and unreference cairo objects.
Note that RefPtr is thread-safe.
Definition at line 50 of file refptr.h.
Constructor & Destructor Documentation
| fawkes::RefPtr< T_CppObject >::RefPtr | ( | ) | [inline] |
| fawkes::RefPtr< T_CppObject >::~RefPtr | ( | ) | [inline] |
Destructor - decrements reference count.
Definition at line 228 of file refptr.h.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
| fawkes::RefPtr< T_CppObject >::RefPtr | ( | T_CppObject * | cpp_object | ) | [inline, explicit] |
| fawkes::RefPtr< T_CppObject >::RefPtr | ( | const RefPtr< T_CppObject > & | src | ) | [inline] |
Copy constructor This increments the shared reference count.
- Parameters:
-
src refptr to copy
Definition at line 286 of file refptr.h.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
| fawkes::RefPtr< T_CppObject >::RefPtr | ( | const RefPtr< T_CastFrom > & | src | ) | [inline] |
Copy constructor (from different, but castable type).
Increments the reference count.
- Parameters:
-
src refptr to copy
Definition at line 306 of file refptr.h.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
| fawkes::RefPtr< T_CppObject >::RefPtr | ( | T_CppObject * | cpp_object, | |
| int * | refcount, | |||
| Mutex * | refmutex | |||
| ) | [inline, explicit] |
For use only in the internal implementation of sharedptr.
- Parameters:
-
cpp_object C++ object to wrap refcount reference count refmutex reference count mutex
Definition at line 272 of file refptr.h.
References fawkes::Mutex::lock(), and fawkes::Mutex::unlock().
Member Function Documentation
| RefPtr< T_CppObject > fawkes::RefPtr< T_CppObject >::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);
- Parameters:
-
src source refptr to cast
- Returns:
- refptr to object casted to given type
Definition at line 449 of file refptr.h.
References fawkes::RefPtr< T_CppObject >::refcount_ptr(), and fawkes::RefPtr< T_CppObject >::refmutex_ptr().
| RefPtr< T_CppObject > fawkes::RefPtr< T_CppObject >::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);
- Parameters:
-
src source refptr to cast
- Returns:
- refptr to object casted to given type
Definition at line 424 of file refptr.h.
References fawkes::RefPtr< T_CppObject >::refcount_ptr(), and fawkes::RefPtr< T_CppObject >::refmutex_ptr().
| RefPtr< T_CppObject > fawkes::RefPtr< T_CppObject >::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);
- Parameters:
-
src source refptr to cast
- Returns:
- refptr to object casted to given type
Definition at line 438 of file refptr.h.
References fawkes::RefPtr< T_CppObject >::refcount_ptr(), and fawkes::RefPtr< T_CppObject >::refmutex_ptr().
| void fawkes::RefPtr< T_CppObject >::clear | ( | void | ) | [inline] |
Set underlying instance to 0, decrementing reference count of existing instance appropriately.
Definition at line 414 of file refptr.h.
References fawkes::RefPtr< T_CppObject >::swap().
Referenced by fawkes::InterruptibleBarrier::reset(), and fawkes::InterruptibleBarrier::wait().
| fawkes::RefPtr< T_CppObject >::operator bool | ( | ) | const [inline] |
| bool fawkes::RefPtr< T_CppObject >::operator!= | ( | const RefPtr< T_CppObject > & | src | ) | const [inline] |
| T_CppObject * fawkes::RefPtr< T_CppObject >::operator-> | ( | ) | const [inline] |
| RefPtr< T_CppObject > & fawkes::RefPtr< T_CppObject >::operator= | ( | T_CppObject * | ptr | ) | [inline] |
Assign object and claim ownership.
- Parameters:
-
ptr pointer to object, this refptr will claim ownership of the src!
- Returns:
- reference to this instance
Definition at line 374 of file refptr.h.
References fawkes::RefPtr< T_CppObject >::swap().
| RefPtr< T_CppObject > & fawkes::RefPtr< T_CppObject >::operator= | ( | const RefPtr< T_CastFrom > & | src | ) | [inline] |
Copy from different, but castable type).
Increments the reference count.
- Parameters:
-
src refptr to copy from
- Returns:
- reference to this instance
Definition at line 386 of file refptr.h.
References fawkes::RefPtr< T_CppObject >::swap().
| RefPtr< T_CppObject > & fawkes::RefPtr< T_CppObject >::operator= | ( | const RefPtr< T_CppObject > & | src | ) | [inline] |
Copy from another RefPtr.
- Parameters:
-
src refptr to copy from
- Returns:
- reference to this instance
Definition at line 341 of file refptr.h.
References fawkes::RefPtr< T_CppObject >::swap().
| bool fawkes::RefPtr< T_CppObject >::operator== | ( | const RefPtr< T_CppObject > & | src | ) | const [inline] |
| int* fawkes::RefPtr< T_CppObject >::refcount_ptr | ( | ) | const [inline] |
For use only in the internal implementation of sharedptr.
Get reference count pointer. Warning: This is for internal use only. Do not manually modify the reference count with this pointer.
- Returns:
- pointer to refcount integer
Definition at line 193 of file refptr.h.
Referenced by fawkes::RefPtr< T_CppObject >::cast_const(), fawkes::RefPtr< T_CppObject >::cast_dynamic(), and fawkes::RefPtr< T_CppObject >::cast_static().
| Mutex* fawkes::RefPtr< T_CppObject >::refmutex_ptr | ( | ) | const [inline] |
For use only in the internal implementation of sharedptr.
Get reference mutex.
- Returns:
- pointer to refcount mutex
Definition at line 199 of file refptr.h.
Referenced by fawkes::RefPtr< T_CppObject >::cast_const(), fawkes::RefPtr< T_CppObject >::cast_dynamic(), and fawkes::RefPtr< T_CppObject >::cast_static().
| void fawkes::RefPtr< T_CppObject >::swap | ( | RefPtr< T_CppObject > & | other | ) | [inline] |
Swap the contents of two RefPtr<>.
This method swaps the internal pointers to T_CppObject. This can be done safely without involving a reference/unreference cycle and is therefore highly efficient.
- Parameters:
-
other other instance to swap with.
Definition at line 324 of file refptr.h.
Referenced by fawkes::RefPtr< T_CppObject >::clear(), fawkes::RefPtr< T_CppObject >::operator=(), and fawkes::RefPtr< T_CppObject >::swap().
Friends And Related Function Documentation
| void swap | ( | RefPtr< T_CppObject > & | lrp, | |
| RefPtr< T_CppObject > & | rrp | |||
| ) | [related] |
Swap refptr instances.
- Parameters:
-
lrp "left" refptr rrp "right" refptr
Definition at line 464 of file refptr.h.
References fawkes::RefPtr< T_CppObject >::swap().
The documentation for this class was generated from the following file:
- src/libs/core/utils/refptr.h

