libglom-1.24  1.24.0
Public Types | Public Member Functions | Static Public Member Functions | List of all members
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 >:
Inheritance graph
[legend]

Public Types

typedef size_t size_type
 
typedef T_obj object_type
 

Public Member Functions

 sharedptr ()
 
 sharedptr (T_obj* pobj)
 Take ownership. More...
 
 sharedptr (T_obj* pobj, size_type* refcount)
 Take ownership. More...
 
 sharedptr (const sharedptr& src)
 Share ownership. More...
 
void swap (sharedptr< T_obj >& other)
 Swap the contents of two sharedptr<>. More...
 
template<class T_CastFrom >
 sharedptr (const sharedptr< T_CastFrom >& src)
 Copy constructor (from different, but castable type). More...
 
sharedptroperator= (const sharedptr& src)
 Share ownership. More...
 
template<class T_CastFrom >
sharedptr< T_obj >& operator= (const sharedptr< T_CastFrom >& src)
 Copy from different, but castable type). More...
 
virtual ~sharedptr ()
 
bool operator== (const sharedptr< T_obj >& src) const
 
bool operator!= (const sharedptr< T_obj >& src) const
 
virtual void clear ()
 Forget the instance. More...
 
T_obj& operator* ()
 Dereferencing. More...
 
const T_obj& operator* () const
 Dereferencing. More...
 
T_obj* operator-> () const
 Dereferencing. More...
 
 operator bool () const
 Test whether the sharedptr<> points to any underlying instance. More...
 
bool operator! () const
 Test whether the sharedptr<> points to any underlying instance. More...
 
T_obj* obj ()
 Get the underlying instance: More...
 
const T_obj* obj () const
 Get the underlying instance: More...
 
template<class T_CastFrom >
sharedptr< T_obj > cast_dynamic (const sharedptr< T_CastFrom >& src)
 
template<class T_CastFrom >
sharedptr< T_obj > cast_static (const sharedptr< T_CastFrom >& src)
 
template<class T_CastFrom >
sharedptr< T_obj > cast_const (const sharedptr< T_CastFrom >& 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. More...
 
template<class T_CastFrom >
static sharedptr< T_obj > cast_static (const sharedptr< T_CastFrom >& src)
 Static cast to derived class. More...
 
template<class T_CastFrom >
static sharedptr< T_obj > cast_const (const sharedptr< T_CastFrom >& src)
 Cast to non-const. More...
 
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 <typename T_obj>
template <class T_CastFrom >
static sharedptr<T_obj> Glom::sharedptr< T_obj >::cast_const ( const sharedptr< T_CastFrom >&  src)
inlinestatic

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 <typename T_obj>
template <class T_CastFrom >
sharedptr<T_obj> Glom::sharedptr< T_obj >::cast_const ( const sharedptr< T_CastFrom >&  src)
inline
template <typename T_obj>
template <class T_CastFrom >
static sharedptr<T_obj> Glom::sharedptr< T_obj >::cast_dynamic ( const sharedptr< T_CastFrom >&  src)
inlinestatic

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 <typename T_obj>
template <class T_CastFrom >
sharedptr<T_obj> Glom::sharedptr< T_obj >::cast_dynamic ( const sharedptr< T_CastFrom >&  src)
inline
template <typename T_obj>
template <class T_CastFrom >
static sharedptr<T_obj> Glom::sharedptr< T_obj >::cast_static ( const sharedptr< T_CastFrom >&  src)
inlinestatic

Static cast to derived class.

Like the dynamic cast; the notation is

ptr_derived = sharedptr<Derived>::cast_static(ptr_base);
template <typename T_obj>
template <class T_CastFrom >
sharedptr<T_obj> Glom::sharedptr< T_obj >::cast_static ( const sharedptr< T_CastFrom >&  src)
inline
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 ( )
inlinestatic
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 >
T_obj& Glom::sharedptr< T_obj >::operator* ( )
inline

Dereferencing.

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-> ( ) const
inline

Dereferencing.

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

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

Share ownership.

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 <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: