gatb.core-API-1.4.2
ISmartPointer Class Referenceabstract

Tool for managing instances life cycle. More...

#include <ISmartPointer.hpp>

Inheritance diagram for ISmartPointer:
Inheritance graph

Public Member Functions

virtual ~ISmartPointer ()
 
virtual void use ()=0
 
virtual void forget ()=0
 

Detailed Description

Tool for managing instances life cycle.

The goal of this class is to share easily objects between clients.

This class has an integer attribute that acts as a reference counter, i.e. a token counting how many clients are interested by the instance.

This is useful for sharing instances; if a client is interested by using an instance 'obj', she/he may call 'obj->use()' which will increase the internal token number. When the client is no more interested by using the instance 'obj', she/he may call 'obj->forget()', which will decrease the internal token.

When the token becomes 0, the instance is automatically destroyed.

Note that use() and forget() are virtual; it may happen (for singleton management for instance) that some subclass needs to refine them.

This pattern is often known as Smart Pointer.

Note that the STL provides its own smart pointer mechanism, known as auto_ptr. Here, our approach relies on subclassing instead of template use. The interest of our approach is to ease methods prototypes writing; with STL approach, one needs to uses every time auto_ptr<T> instead of only T, which can lower the readability.

On the other hand, our approach may be a little more dangerous than the STL approach since one has to be sure to forget an instance when needed. In our case, we use Smart Pointers mainly for attributes in class, so only have to be careful in constructors and destructors. Moreover, one can use the SP_SETATTR macro which eases this process. Note also the LOCAL macro that eases the local usage of an instance.

See also
SP_SETATTR
LOCAL

Constructor & Destructor Documentation

virtual ~ISmartPointer ( )
inlinevirtual

Destructor.

Member Function Documentation

virtual void forget ( )
pure virtual

Forget an instance by releasing a token on it

Implemented in SmartPointer.

virtual void use ( )
pure virtual

Use an instance by taking a token on it

Implemented in SmartPointer.


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