libglom-1.20 1.19.12

- Main Page
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Static Public Member Functions

# Glom::sharedptr< T_obj > Class Template Reference

A ref-counting smart-pointer for the underlying C++ object. More...

Inheritance diagram for Glom::sharedptr< T_obj >:
[legend]

List of all members.

## Public Types
typedef size_t | size_type
typedef T_obj | object_type
## Public Member Functions
| sharedptr ()
| sharedptr (T_obj* pobj)
| Take ownership.
| sharedptr (T_obj* pobj, size_type* refcount)
| Take ownership.
| sharedptr (const sharedptr& src)
| Share ownership.
void | swap (sharedptr< T_obj >& other)
| Swap the contents of two sharedptr<>.
template<class T_CastFrom >
| sharedptr (const sharedptr< T_CastFrom >& src)
| Copy constructor (from different, but castable type).
sharedptr& | operator= (const sharedptr& src)
| Share ownership.
template<class T_CastFrom >
sharedptr< T_obj >& | operator= (const sharedptr< T_CastFrom >& src)
| Copy from different, but castable type).
virtual | ~sharedptr ()
bool | operator== (const sharedptr< T_obj >& src) const
bool | operator!= (const sharedptr< T_obj >& src) const
virtual void | clear ()
| Forget the instance.
T_obj& | operator* ()
| Dereferencing.
const T_obj& | operator* () const
| Dereferencing.
T_obj* | operator-> () const
| Dereferencing.
| operator bool () const
| Test whether the sharedptr<> points to any underlying instance.
bool | operator! () const
| Test whether the sharedptr<> points to any underlying instance.
T_obj* | obj ()
| Get the underlying instance:
const T_obj* | obj () const
| Get the underlying instance:
## Static Public Member Functions
template<class T_CastFrom >
static sharedptr< T_obj > | cast_dynamic (const sharedptr< T_CastFrom >& src)
| Dynamic cast to derived class.
template<class T_CastFrom >
static sharedptr< T_obj > | cast_static (const sharedptr< T_CastFrom >& src)
| Static cast to derived class.
template<class T_CastFrom >
static sharedptr< T_obj > | cast_const (const sharedptr< T_CastFrom >& src)
| Cast to non-const.
static sharedptr< T_obj > | create ()

## Detailed Description

### template<typename T_obj>
class Glom::sharedptr< T_obj >

A ref-counting smart-pointer for the underlying C++ object.

You can copy these smarpointers-of-C++-resources, and therefore the C++ classes can have simple copy constructors which just share the underlying resources.

## Member Typedef Documentation

template <typename T_obj>

typedef T_obj Glom::sharedptr< T_obj >::object_type

template <typename T_obj>

typedef size_t Glom::sharedptr< T_obj >::size_type

## Constructor & Destructor Documentation

template <typename T_obj >

Glom::sharedptr< T_obj >::sharedptr | ( |  | ) |

template <typename T_obj>

Glom::sharedptr< T_obj >::sharedptr | ( | T_obj * | pobj | ) | `[explicit]`

Take ownership.

template <typename T_obj>

Glom::sharedptr< T_obj >::sharedptr | ( | T_obj * | pobj,
|  | size_type* | refcount
| ) |  | `[explicit]`

Take ownership.

This is only for internal use.

template <typename T_obj>

Glom::sharedptr< T_obj >::sharedptr | ( | const sharedptr< T_obj >& | src | ) |

Share ownership.

template <class T_obj >
template <class T_CastFrom >

Glom::sharedptr< T_obj >::sharedptr | ( | const sharedptr< T_CastFrom >& | src | ) | `[inline]`

Copy constructor (from different, but castable type).

Increments the reference count.

template <typename T_obj >

Glom::sharedptr< T_obj >::~sharedptr | ( |  | ) | `[virtual]`

## Member Function Documentation

template <class T_obj >
template <class T_CastFrom >

sharedptr< T_obj > Glom::sharedptr< T_obj >::cast_const | ( | const sharedptr< T_CastFrom >& | src | ) | `[inline, static]`

Cast to non-const.

The sharedptr can't be cast with the usual notation so instead you can use

     ptr_unconst = sharedptr<UnConstType>::cast_const(ptr_const);

template <class T_obj >
template <class T_CastFrom >

sharedptr< T_obj > Glom::sharedptr< T_obj >::cast_dynamic | ( | const sharedptr< T_CastFrom >& | src | ) | `[inline, static]`

Dynamic cast to derived class.

The sharedptr can't be cast with the usual notation so instead you can use

     ptr_derived = sharedptr<Derived>::cast_dynamic(ptr_base);

template <class T_obj >
template <class T_CastFrom >

sharedptr< T_obj > Glom::sharedptr< T_obj >::cast_static | ( | const sharedptr< T_CastFrom >& | src | ) | `[inline, static]`

Static cast to derived class.

Like the dynamic cast; the notation is

     ptr_derived = sharedptr<Derived>::cast_static(ptr_base);

template <typename T_obj >

void Glom::sharedptr< T_obj >::clear | ( |  | ) | `[virtual]`

Forget the instance.

template <typename T_obj>

static sharedptr<T_obj> Glom::sharedptr< T_obj >::create | ( |  | ) | `[inline, static]`

template <typename T_obj >

T_obj* Glom::sharedptr< T_obj >::obj | ( |  | ) | `[inline]`

Get the underlying instance:

template <typename T_obj >

const T_obj* Glom::sharedptr< T_obj >::obj | ( |  | ) | const`[inline]`

Get the underlying instance:

template <class T_obj >

Glom::sharedptr< T_obj >::operator bool | ( |  | ) | const`[inline]`

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

Mimics usage of ordinary pointers:

     if(ptr)
         do_something();

template <class T_obj >

bool Glom::sharedptr< T_obj >::operator! | ( |  | ) | const`[inline]`

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

Mimics usage of ordinary pointers:

     if(!ptr)
         do_something();

template <class T_obj>

bool Glom::sharedptr< T_obj >::operator!= | ( | const sharedptr< T_obj >& | src | ) | const`[inline]`

template <typename T_obj >

const T_obj& Glom::sharedptr< T_obj >::operator* | ( |  | ) | const`[inline]`

Dereferencing.

template <typename T_obj >

T_obj& Glom::sharedptr< T_obj >::operator* | ( |  | ) | `[inline]`

Dereferencing.

template <typename T_obj >

T_obj* Glom::sharedptr< T_obj >::operator-> | ( |  | ) | const`[inline]`

Dereferencing.

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

template <class T_obj >
template <class T_CastFrom >

sharedptr< T_obj >& Glom::sharedptr< T_obj >::operator= | ( | const sharedptr< T_CastFrom >& | src | ) | `[inline]`

Copy from different, but castable type).

Increments the reference count.

template <typename T_obj >

sharedptr< T_obj >& Glom::sharedptr< T_obj >::operator= | ( | const sharedptr< T_obj >& | src | ) |

Share ownership.

template <class T_obj>

bool Glom::sharedptr< T_obj >::operator== | ( | const sharedptr< T_obj >& | src | ) | const`[inline]`

template <class T_obj>

void Glom::sharedptr< T_obj >::swap | ( | sharedptr< T_obj >& | other | ) | `[inline]`

Swap the contents of two sharedptr<>.

This method swaps the internal pointers. 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:

- libglom/sharedptr.h