commore  1.0.6-SNAPSHOT
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
commore::AutoRef< E > Class Template Reference

AutoRef is a smart pointer on RefObject objects. AutoRef is templatized with the type of the pointed object (a class which publicly inherits from RefObject). In Commore, an AutoRef<MyType> is usually typedefed as PMyType. An AutoRef can be used in many ways. More...

#include <AutoRef.h>

+ Inheritance diagram for commore::AutoRef< E >:

Public Member Functions

 AutoRef ()
 
 AutoRef (const AChar *s)
 
 AutoRef (bool)
 
 AutoRef (E *p)
 
 AutoRef (RefObject *p)
 
 AutoRef (const AutoRef &a)
 
 AutoRef (const AutoRefBase &a)
 
AutoRefoperator= (const AutoRef &a)
 
AutoRefoperator= (const AutoRefBase &a)
 
AutoRefoperator= (RefObject *p)
 
 operator bool () const
 
bool create (const AChar *s)
 
bool create ()
 
bool bind (const AChar *s)
 
bool bind ()
 
E * get () const
 
E & operator* () const
 
E * operator-> () const
 
 operator E * () const
 
bool operator== (const AutoRef &a) const
 
bool operator!= (const AutoRef &a) const
 
bool operator< (const AutoRef &a) const
 
bool is_bound () const
 
void unbind ()
 
- Public Member Functions inherited from commore::AutoRefBase
 AutoRefBase ()
 
 AutoRefBase (RefObject *p)
 
 AutoRefBase (const AutoRefBase &a)
 
AutoRefBaseoperator= (const AutoRefBase &a)
 
 ~AutoRefBase ()
 
RefObjectget_ () const
 
void set_ (RefObject *p)
 
void clear ()
 

Detailed Description

template<class E>
class commore::AutoRef< E >

AutoRef is a smart pointer on RefObject objects. AutoRef is templatized with the type of the pointed object (a class which publicly inherits from RefObject). In Commore, an AutoRef<MyType> is usually typedefed as PMyType. An AutoRef can be used in many ways.

It can be used as a pointer to a RefObject, for reference counting : class A : public RefObject; typedef AutoRef PA; A a; PA pa(a);

It can be used as an way to instantiate its pointed object, implicitly using a factory under the hood : class A : public RefObject { static AChar* factory_name() {return "A";} } typedef AutoRef PA; class AFactory : public RefFactory { AutoRefBase create(AChar* s) const { // instantiate an A object, based on the // specification given by s. Return NULL if // this factory is not the right one for this task. const AChar* factory_name() const {return "A";} }; static AFactory a_factory_; // instantiate this factory and add it to the list of global factories

It is used in this way : PA pa; pa.create("instantiation specification, understandable by the factory");

This is useful when many factories claim to instantiate the same type of object (ie, factories which factory_name is the same as RefObject's factory_name). Each of these factories being able to instantiate an object depending on the demanded spec : each one will be tested until one accepts to perform the instantiation.

The template class E must have the static methods auto_create, create, bind and factory_name.

Examples:
/examples/coding/Logs.cpp.

Constructor & Destructor Documentation

template<class E>
commore::AutoRef< E >::AutoRef ( )
inline

Create an AutoRef for E object Not empty if E::auto_create is defined and return a bound autoref

template<class E>
commore::AutoRef< E >::AutoRef ( const AChar s)
inline

Try create an AutoRef bound to a new object using the RefObject factories if defined

template<class E>
commore::AutoRef< E >::AutoRef ( bool  )
inlineexplicit

Try create a bound AutoRef by calling explicitely E::create method.

template<class E>
commore::AutoRef< E >::AutoRef ( E *  p)
inline

Create AutoRef with expilcit bound

template<class E>
commore::AutoRef< E >::AutoRef ( RefObject p)
inline

Create AutoRef with expilcit bound

template<class E>
commore::AutoRef< E >::AutoRef ( const AutoRef< E > &  a)
inline

Copy constructor

template<class E>
commore::AutoRef< E >::AutoRef ( const AutoRefBase a)
inline

Generic Copy constructor

Member Function Documentation

template<class E>
bool commore::AutoRef< E >::bind ( const AChar s)
inline

Tri bind autoref to an objet using the RefObject factory look_up

Todo:
is functionality this useful ??
template<class E>
bool commore::AutoRef< E >::bind ( )
inline

Tri bind autoref to an objet using the RefObject factory look_up

Todo:
is functionality this useful ??
template<class E>
bool commore::AutoRef< E >::create ( const AChar s)
inline

Try create a new E objet using the factories or E::create static method

template<class E>
bool commore::AutoRef< E >::create ( )
inline

Try create a new objet using the E::create static method

template<class E>
E* commore::AutoRef< E >::get ( ) const
inline
Returns
a pointer to the managed object
template<class E>
bool commore::AutoRef< E >::is_bound ( ) const
inline

Check if autoref is bound to a valid object

template<class E>
commore::AutoRef< E >::operator bool ( ) const
inline

Check atoref is bound

template<class E>
commore::AutoRef< E >::operator E * ( ) const
inline

Implict cast

template<class E>
bool commore::AutoRef< E >::operator!= ( const AutoRef< E > &  a) const
inline
template<class E>
E& commore::AutoRef< E >::operator* ( ) const
inline
Returns
a reference to the managed object
Warning
predictable behaviour if atoref not bound
template<class E>
E* commore::AutoRef< E >::operator-> ( ) const
inline
Returns
a pointer to the managed object in order to call a method
template<class E>
bool commore::AutoRef< E >::operator< ( const AutoRef< E > &  a) const
inline
template<class E>
AutoRef& commore::AutoRef< E >::operator= ( const AutoRef< E > &  a)
inline

Assignment operator

template<class E>
AutoRef& commore::AutoRef< E >::operator= ( const AutoRefBase a)
inline

Gereneric assignement operator (type check is done dynamicaly)

template<class E>
AutoRef& commore::AutoRef< E >::operator= ( RefObject p)
inline

Generic assignement with pointer

template<class E>
bool commore::AutoRef< E >::operator== ( const AutoRef< E > &  a) const
inline

Compare autoref content pointer

template<class E>
void commore::AutoRef< E >::unbind ( )
inline

Unbind autoref.


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