cairomm: Cairo::RefPtr< T_CppObject > Class Template Reference

Public Member Functions | Static Public Member Functions

# Cairo::RefPtr< T_CppObject > Class Template Reference

RefPtr<> is a reference-counting shared smartpointer. More...

List of all members.

## Public Member Functions
| RefPtr ()
| Default constructor.
| ~RefPtr ()
| Destructor - decrements reference count.
| RefPtr (T_CppObject* pCppObject)
| For use only in the internal implementation of cairomm, gtkmm, etc.
| RefPtr (T_CppObject* pCppObject, int* refcount)
| For use only in the internal implementation of sharedptr.
| 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 ()
| Set underlying instance to 0, decrementing reference count of existing instance appropriately.
## 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.

## Detailed Description

### template <class T_CppObject>
class Cairo::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

cairomm 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.

Examples:

  image-surface.cc, pdf-surface.cc, ps-surface.cc, svg-surface.cc, toy-text.cc, and user-font.cc.

## Constructor & Destructor Documentation

template <class T_CppObject>

Cairo::RefPtr< T_CppObject >::RefPtr | ( |  | ) | `[inline]`

Default constructor.

Afterwards it will be null and use of -> will cause a segmentation fault.

template <class T_CppObject>

Cairo::RefPtr< T_CppObject >::~RefPtr | ( |  | ) | `[inline]`

Destructor - decrements reference count.

template <class T_CppObject>

Cairo::RefPtr< T_CppObject >::RefPtr | ( | T_CppObject * | pCppObject | ) | `[inline, explicit]`

For use only in the internal implementation of cairomm, gtkmm, etc.

This takes ownership of pCppObject, so it will be deleted when the last RefPtr is deleted, for instance when it goes out of scope.

This assumes that pCppObject already has a starting reference for its underlying cairo object, so that destruction of will cause a corresponding unreference of its underlying cairo object. For instance, a cairo_*_create() function usually provides a starting reference, but a cairo_*_get_*() function requires the caller to manually reference the returned object. In this case, you should call reference() on pCppObject before passing it to this constructor.

template <class T_CppObject>

Cairo::RefPtr< T_CppObject >::RefPtr | ( | T_CppObject * | pCppObject,
|  | int * | refcount |
| ) |  |  | `[inline, explicit]`

For use only in the internal implementation of sharedptr.

template <class T_CppObject>

Cairo::RefPtr< T_CppObject >::RefPtr | ( | const RefPtr< T_CppObject >& | src | ) | `[inline]`

Copy constructor.

This increments the shared reference count.

template <class T_CppObject>
template <class T_CastFrom >

Cairo::RefPtr< T_CppObject >::RefPtr | ( | const RefPtr< T_CastFrom >& | src | ) | `[inline]`

Copy constructor (from different, but castable type).

Increments the reference count.

## Member Function Documentation

template <class T_CppObject>
template <class T_CastFrom >

static RefPtr<T_CppObject> Cairo::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);

template <class T_CppObject>
template <class T_CastFrom >

static RefPtr<T_CppObject> Cairo::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);

template <class T_CppObject>
template <class T_CastFrom >

static RefPtr<T_CppObject> Cairo::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);

template <class T_CppObject>

void Cairo::RefPtr< T_CppObject >::clear | ( |  | ) | `[inline]`

Set underlying instance to 0, decrementing reference count of existing instance appropriately.

template <class T_CppObject>

Cairo::RefPtr< T_CppObject >::operator bool | ( |  | ) | const`[inline]`

Test whether the RefPtr<> points to any underlying instance.

Mimics usage of ordinary pointers:

       if (ptr)
         do_something();

template <class T_CppObject>

bool Cairo::RefPtr< T_CppObject >::operator!= | ( | const RefPtr< T_CppObject >& | src | ) | const`[inline]`

See operator==().

template <class T_CppObject>

T_CppObject* Cairo::RefPtr< T_CppObject >::operator-> | ( |  | ) | const`[inline]`

Dereferencing.

Use the methods of the underlying instance like so: `refptr->memberfun()`.

template <class T_CppObject>

RefPtr<T_CppObject>& Cairo::RefPtr< T_CppObject >::operator= | ( | const RefPtr< T_CppObject >& | src | ) | `[inline]`

Copy from another RefPtr:

template <class T_CppObject>
template <class T_CastFrom >

RefPtr<T_CppObject>& Cairo::RefPtr< T_CppObject >::operator= | ( | const RefPtr< T_CastFrom >& | src | ) | `[inline]`

Copy from different, but castable type).

Increments the reference count.

template <class T_CppObject>

bool Cairo::RefPtr< T_CppObject >::operator== | ( | const RefPtr< T_CppObject >& | src | ) | const`[inline]`

Tests whether the RefPtr<> point to the same underlying instance.

template <class T_CppObject>

void Cairo::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.

The documentation for this class was generated from the following file:

- cairomm/refptr.h