Public Member Functions |
| RefPtr () |
| Default constructor.
|
| ~RefPtr () |
| Destructor - decrements reference count.
|
| RefPtr (T_CppObject* pCppObject) |
| For use only by the ::create() methods.
|
| RefPtr (const RefPtr< T_CppObject >& src) |
| Copy constructor.
|
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).
|
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 |
| See operator==().
|
T_CppObject* | operator-> () const |
| Dereferencing.
|
| operator bool () const |
| Test whether the RefPtr<> points to any underlying instance.
|
void | clear () |
void | reset () |
| Set underlying instance to 0, decrementing reference count of existing instance appropriately.
|
bool | operator< (const RefPtr< T_CppObject >& src) const |
| Compare based on the underlying instance address.
|
bool | operator<= (const RefPtr< T_CppObject >& src) const |
| See operator<().
|
bool | operator> (const RefPtr< T_CppObject >& src) const |
| See operator<().
|
bool | operator>= (const RefPtr< T_CppObject >& src) const |
| See operator<().
|
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.
|
template<class T_CppObject>
class Glib::RefPtr< T_CppObject >
RefPtr<> is a reference-counting shared smartpointer.
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. In gtkmm, that is anything derived from Glib::ObjectBase, such as Gdk::Pixmap.
See the "Memory Management" section in the "Programming with gtkmm" book for further information.
- Examples:
- thread/dispatcher.cc.
template <class T_CppObject>
Compare based on the underlying instance address.
This is needed in code that requires an ordering on RefPtr<T_CppObject> instances, e.g. std::set<RefPtr<T_CppObject> >.
Without these, comparing two RefPtr<T_CppObject> instances is still syntactically possible, but the result is semantically wrong, as p1 REL_OP p2 is interpreted as (bool)p1 REL_OP (bool)p2.