Some objects in gtkmm are obtained from a shared store. Consequently you cannot instantiate them yourself. Instead they return a RefPtr which behaves much like an ordinary pointer in that members can be reached with the usual object_ptr->member
notation. Unlike most other smart pointers, RefPtr doesn't support dereferencing through *object_ptr
.
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, meaning you don't need to remember to delete the object.
RefPtr<> can store any class that has reference() and unreference() methods.
Public Member Functions | |
void | clear () |
Set underlying instance to 0, decrementing reference count of existing instance appropriately. | |
operator bool () const | |
Test whether the RefPtr<> points to any underlying instance. | |
bool | operator!= (const RefPtr< T_CppObject > &src) const |
See operator==(). | |
T_CppObject * | operator-> () const |
Dereferencing. | |
template<class T_CastFrom> | |
RefPtr< T_CppObject > & | operator= (const RefPtr< T_CastFrom > &src) |
Copy from different, but castable type). | |
RefPtr< T_CppObject > & | operator= (const RefPtr< T_CppObject > &src) |
Copy from another RefPtr:. | |
bool | operator== (const RefPtr< T_CppObject > &src) const |
Tests whether the RefPtr<> point to the same underlying instance. | |
template<class T_CastFrom> | |
RefPtr (const RefPtr< T_CastFrom > &src) | |
Copy constructor (from different, but castable type). | |
RefPtr (const RefPtr< T_CppObject > &src) | |
Copy constructor. | |
RefPtr (T_CppObject *pCppObject) | |
For use only by the create() methods. | |
RefPtr () | |
Default constructor. | |
void | swap (RefPtr< T_CppObject > &other) |
Swap the contents of two RefPtr<>. | |
~RefPtr () | |
Destructor - decrements reference count. | |
Static Public Member Functions | |
template<class T_CastFrom> | |
static RefPtr< T_CppObject > | cast_const (const RefPtr< T_CastFrom > &src) |
Cast to non-const. | |
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. |
|
Default constructor. Afterwards it will be null and use of -> will cause a segmentation fault. |
|
Destructor - decrements reference count.
|
|
For use only by the create() methods.
|
|
Copy constructor. This increments the shared reference count. |
|
Copy constructor (from different, but castable type). Increments the reference count. |
|
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); |
|
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); |
|
Static cast to derived class. Like the dynamic cast; the notation is ptr_derived = RefPtr<Derived>::cast_static(ptr_base); |
|
Set underlying instance to 0, decrementing reference count of existing instance appropriately.
|
|
Test whether the RefPtr<> points to any underlying instance. Mimics usage of ordinary pointers: if (ptr)
do_something();
|
|
See operator==().
|
|
Dereferencing.
Use the methods of the underlying instance like so: |
|
Copy from different, but castable type). Increments the reference count. |
|
Copy from another RefPtr:.
|
|
Tests whether the RefPtr<> point to the same underlying instance.
|
|
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. |