libglom-1.20  1.19.14
Public Types | Public Member Functions | Static Public Member Functions
Glom::sharedptr Class Reference

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

Inheritance diagram for Glom::sharedptr:
Inheritance graph
[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).
sharedptroperator= (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:
template<typename T_obj >
 sharedptr (const sharedptr< T_obj >& src)
template<typename T_obj >
sharedptr< T_obj >& operator= (const sharedptr< T_obj >& src)

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

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


Constructor & Destructor Documentation

Glom::sharedptr::sharedptr ( )
Glom::sharedptr::sharedptr ( T_obj *  pobj) [explicit]

Take ownership.

Glom::sharedptr::sharedptr ( T_obj *  pobj,
size_type refcount 
) [explicit]

Take ownership.

This is only for internal use.

Glom::sharedptr::sharedptr ( const sharedptr src)

Share ownership.

template <class T_CastFrom >
Glom::sharedptr::sharedptr ( const sharedptr< T_CastFrom >&  src) [inline]

Copy constructor (from different, but castable type).

Increments the reference count.

Glom::sharedptr::~sharedptr ( ) [virtual]
template <typename T_obj >
Glom::sharedptr::sharedptr ( const sharedptr< T_obj >&  src)

Member Function Documentation

template <class T_CastFrom >
sharedptr< T_obj > Glom::sharedptr::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_CastFrom >
sharedptr< T_obj > Glom::sharedptr::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_CastFrom >
sharedptr< T_obj > Glom::sharedptr::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);
void Glom::sharedptr::clear ( ) [virtual]

Forget the instance.

static sharedptr<T_obj> Glom::sharedptr::create ( ) [inline, static]
T_obj * Glom::sharedptr::obj ( ) [inline]

Get the underlying instance:

const T_obj * Glom::sharedptr::obj ( ) const [inline]

Get the underlying instance:

Glom::sharedptr::operator bool ( ) const [inline]

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

Mimics usage of ordinary pointers:

 if(ptr)
     do_something();
bool Glom::sharedptr::operator! ( ) const [inline]

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

Mimics usage of ordinary pointers:

 if(!ptr)
     do_something();
bool Glom::sharedptr::operator!= ( const sharedptr< T_obj >&  src) const [inline]
T_obj & Glom::sharedptr::operator* ( ) [inline]

Dereferencing.

const T_obj & Glom::sharedptr::operator* ( ) const [inline]

Dereferencing.

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

Dereferencing.

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

sharedptr& Glom::sharedptr::operator= ( const sharedptr src)

Share ownership.

template <class T_CastFrom >
sharedptr< T_obj >& Glom::sharedptr::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::operator= ( const sharedptr< T_obj >&  src)
bool Glom::sharedptr::operator== ( const sharedptr< T_obj >&  src) const [inline]
void Glom::sharedptr::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: