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

cairomm 1.14.4

Public Member Functions | Static Public Member Functions | List of all members
Cairo::RefPtr< T_CppObject > Class Template Reference

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

`#include <cairomm/refptr.h>`

Inheritance diagram for Cairo::RefPtr< T_CppObject >:
[legend]

## Public Member Functions
| RefPtr () noexcept
| Default constructor. More...
| ~RefPtr () noexcept
| Destructor - decrements reference count. More...
| RefPtr (T_CppObject * pCppObject) noexcept
| For use only in the internal implementation of cairomm, gtkmm, etc. More...
| RefPtr (T_CppObject * pCppObject, int * refcount) noexcept
| For use only in the internal implementation of sharedptr. More...
| RefPtr (RefPtr && src) noexcept
| Move constructor. More...
template<class T_CastFrom >
| RefPtr (RefPtr< T_CastFrom > && src) noexcept
| Move constructor (from different, but castable type). More...
| RefPtr (const RefPtr< T_CppObject > & src) noexcept
| Copy constructor. More...
template<class T_CastFrom >
| RefPtr (const RefPtr< T_CastFrom > & src) noexcept
| Copy constructor (from different, but castable type). More...
void | swap (RefPtr< T_CppObject > & other) noexcept
| Swap the contents of two RefPtr<>. More...
RefPtr< T_CppObject > & | operator= (const RefPtr< T_CppObject > & src) noexcept
| Copy from another RefPtr: More...
template<class T_CastFrom >
RefPtr< T_CppObject > & | operator= (const RefPtr< T_CastFrom > & src) noexcept
| Copy from different, but castable type). More...
RefPtr & | operator= (RefPtr && src) noexcept
| Move assignment operator: More...
template<class T_CastFrom >
RefPtr & | operator= (RefPtr< T_CastFrom > && src) noexcept
| Move assignment operator (from different, but castable type): More...
bool | operator== (const RefPtr< T_CppObject > & src) const noexcept
| Tests whether the RefPtr<> point to the same underlying instance. More...
bool | operator!= (const RefPtr< T_CppObject > & src) const noexcept
| See operator==(). More...
T_CppObject * | operator-> () const noexcept
| Dereferencing. More...
| operator bool () const noexcept
| Test whether the RefPtr<> points to any underlying instance. More...
void | clear () noexcept
| Set underlying instance to 0, decrementing reference count of existing instance appropriately. More...

## Static Public Member Functions
template<class T_CastFrom >
static RefPtr< T_CppObject > | cast_dynamic (const RefPtr< T_CastFrom > & src) noexcept
| Dynamic cast to derived class. More...
template<class T_CastFrom >
static RefPtr< T_CppObject > | cast_static (const RefPtr< T_CastFrom > & src) noexcept
| Static cast to derived class. More...
template<class T_CastFrom >
static RefPtr< T_CppObject > | cast_const (const RefPtr< T_CastFrom > & src) noexcept
| Cast to non-const. More...

## 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
  user-font.cc.

## Constructor & Destructor Documentation

## ◆ RefPtr() [1/7]

template <class T_CppObject >

Cairo::RefPtr< T_CppObject >::RefPtr | ( |  | ) |
| inlinenoexcept

Default constructor.

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

## ◆ ~RefPtr()

template <class T_CppObject >

Cairo::RefPtr< T_CppObject >::~RefPtr | ( |  | ) |
| inlinenoexcept

Destructor - decrements reference count.

## ◆ RefPtr() [2/7]

template <class T_CppObject >

Cairo::RefPtr< T_CppObject >::RefPtr | ( | T_CppObject * | pCppObject | ) |
| inlineexplicitnoexcept

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 @pCppObject 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.

## ◆ RefPtr() [3/7]

template <class T_CppObject >

Cairo::RefPtr< T_CppObject >::RefPtr | ( | T_CppObject * | pCppObject,
|  | int * | refcount
| ) |  |
| inlineexplicitnoexcept

For use only in the internal implementation of sharedptr.

## ◆ RefPtr() [4/7]

template <class T_CppObject >

Cairo::RefPtr< T_CppObject >::RefPtr | ( | RefPtr< T_CppObject > && | src | ) |
| inlinenoexcept

Move constructor.

## ◆ RefPtr() [5/7]

template <class T_CppObject >
template <class T_CastFrom >

Cairo::RefPtr< T_CppObject >::RefPtr | ( | RefPtr< T_CastFrom > && | src | ) |
| inlinenoexcept

Move constructor (from different, but castable type).

## ◆ RefPtr() [6/7]

template <class T_CppObject >

Cairo::RefPtr< T_CppObject >::RefPtr | ( | const RefPtr< T_CppObject > & | src | ) |
| inlinenoexcept

Copy constructor.

This increments the shared reference count.

## ◆ RefPtr() [7/7]

template <class T_CppObject >
template <class T_CastFrom >

Cairo::RefPtr< T_CppObject >::RefPtr | ( | const RefPtr< T_CastFrom > & | src | ) |
| inlinenoexcept

Copy constructor (from different, but castable type).

Increments the reference count.

## Member Function Documentation

## ◆ cast_const()

template <class T_CppObject >
template <class T_CastFrom >

static RefPtr< T_CppObject > Cairo::RefPtr< T_CppObject >::cast_const | ( | const RefPtr< T_CastFrom > & | src | ) |
| inlinestaticnoexcept

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);
Cairo::RefPtr::cast_const
static RefPtr< T_CppObject > cast_const(const RefPtr< T_CastFrom > &src) noexcept
Cast to non-const.

## ◆ cast_dynamic()

template <class T_CppObject >
template <class T_CastFrom >

static RefPtr< T_CppObject > Cairo::RefPtr< T_CppObject >::cast_dynamic | ( | const RefPtr< T_CastFrom > & | src | ) |
| inlinestaticnoexcept

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);
Cairo::RefPtr::cast_dynamic
static RefPtr< T_CppObject > cast_dynamic(const RefPtr< T_CastFrom > &src) noexcept
Dynamic cast to derived class.

## ◆ cast_static()

template <class T_CppObject >
template <class T_CastFrom >

static RefPtr< T_CppObject > Cairo::RefPtr< T_CppObject >::cast_static | ( | const RefPtr< T_CastFrom > & | src | ) |
| inlinestaticnoexcept

Static cast to derived class.

Like the dynamic cast; the notation is

ptr_derived = RefPtr<Derived>::cast_static(ptr_base);
Cairo::RefPtr::cast_static
static RefPtr< T_CppObject > cast_static(const RefPtr< T_CastFrom > &src) noexcept
Static cast to derived class.

## ◆ clear()

template <class T_CppObject >

void Cairo::RefPtr< T_CppObject >::clear | ( |  | ) |
| inlinenoexcept

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

## ◆ operator bool()

template <class T_CppObject >

Cairo::RefPtr< T_CppObject >::operator bool | ( |  | ) | const
| inlineexplicitnoexcept

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

Mimics usage of ordinary pointers:

if (ptr)
do_something();

## ◆ operator!=()

template <class T_CppObject >

bool Cairo::RefPtr< T_CppObject >::operator!= | ( | const RefPtr< T_CppObject > & | src | ) | const
| inlinenoexcept

See operator==().

## ◆ operator->()

template <class T_CppObject >

T_CppObject * Cairo::RefPtr< T_CppObject >::operator-> | ( |  | ) | const
| inlinenoexcept

Dereferencing.

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

## ◆ operator=() [1/4]

template <class T_CppObject >
template <class T_CastFrom >

RefPtr< T_CppObject > & Cairo::RefPtr< T_CppObject >::operator= | ( | const RefPtr< T_CastFrom > & | src | ) |
| inlinenoexcept

Copy from different, but castable type).

Increments the reference count.

## ◆ operator=() [2/4]

template <class T_CppObject >

RefPtr< T_CppObject > & Cairo::RefPtr< T_CppObject >::operator= | ( | const RefPtr< T_CppObject > & | src | ) |
| inlinenoexcept

Copy from another RefPtr:

## ◆ operator=() [3/4]

template <class T_CppObject >

RefPtr & Cairo::RefPtr< T_CppObject >::operator= | ( | RefPtr< T_CppObject > && | src | ) |
| inlinenoexcept

Move assignment operator:

## ◆ operator=() [4/4]

template <class T_CppObject >
template <class T_CastFrom >

RefPtr & Cairo::RefPtr< T_CppObject >::operator= | ( | RefPtr< T_CastFrom > && | src | ) |
| inlinenoexcept

Move assignment operator (from different, but castable type):

## ◆ operator==()

template <class T_CppObject >

bool Cairo::RefPtr< T_CppObject >::operator== | ( | const RefPtr< T_CppObject > & | src | ) | const
| inlinenoexcept

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

## ◆ swap()

template <class T_CppObject >

void Cairo::RefPtr< T_CppObject >::swap | ( | RefPtr< T_CppObject > & | other | ) |
| inlinenoexcept

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