commore
1.0.6-SNAPSHOT
|
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>
Public Member Functions | |
AutoRef () | |
AutoRef (const AChar *s) | |
AutoRef (bool) | |
AutoRef (E *p) | |
AutoRef (RefObject *p) | |
AutoRef (const AutoRef &a) | |
AutoRef (const AutoRefBase &a) | |
AutoRef & | operator= (const AutoRef &a) |
AutoRef & | operator= (const AutoRefBase &a) |
AutoRef & | operator= (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 () |
![]() | |
AutoRefBase () | |
AutoRefBase (RefObject *p) | |
AutoRefBase (const AutoRefBase &a) | |
AutoRefBase & | operator= (const AutoRefBase &a) |
RefObject * | get_ () const |
void | set_ (RefObject *p) |
void | clear () |
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.
|
inline |
Create an AutoRef for E object Not empty if E::auto_create is defined and return a bound autoref
|
inline |
|
inlineexplicit |
Try create a bound AutoRef by calling explicitely E::create method.
|
inline |
Create AutoRef with expilcit bound
|
inline |
Create AutoRef with expilcit bound
|
inline |
Copy constructor
|
inline |
Generic Copy constructor
|
inline |
|
inline |
|
inline |
Try create a new E objet using the factories or E::create static method
|
inline |
Try create a new objet using the E::create static method
|
inline |
|
inline |
Check if autoref is bound to a valid object
|
inline |
Check atoref is bound
|
inline |
Implict cast
|
inline |
|
inline |
|
inline |
Assignment operator
|
inline |
Gereneric assignement operator (type check is done dynamicaly)
|
inline |
Generic assignement with pointer
|
inline |
Compare autoref content pointer
|
inline |
Unbind autoref.