Version: 8.3.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
SINGLETON_< TYPE > Class Template Reference

Static Public Member Functions

static TYPE * Instance (void)
 Singleton dynamic creation using the default builder. More...
 
static bool IsAlreadyExisting (void)
 returns True if the singleton is already existing More...
 
static int Destruction (void)
 destroys the Singleton before the end of the application process More...
 

Detailed Description

template<class TYPE>
class SINGLETON_< TYPE >

Definition

A singleton is a data which is created and deleted only once in the application. The C++ compiler allow the user to create static data before the first executable statement. They are deleted after the last statement.statement.

The SINGLETON_ template class deals with dynamic singleton. It is useful for functor objects. For example, an object which, when created, connects the application to a system and disconnects the application at deletion.

Usage

To create a single instance a POINT_ object :

include "Utils_SINGLETON.hxx"

... ptrPoint = SINGLETON_<POINT_>::Instance() ;

Design description

 -# the user creates an object of class TYPE By using a class method : SINGLETON_<TYPE>::Instance() which
    returns a pointer to the single object ;
 -# this class method uses the default constructor to create an object ;
 -# at the same time, this class method reate a destructor object which is added to the generic list
    of destructors objects to be executed at the end of the application (atexit) ;
 -# at the end of the application process all the deletions are performed by the Nettoyage() C function
    which execute the destructions objects then deletes the destructions objects themselves ;
 -# the Nettoyage() C function is recorded using atexit() C function through the creation of a static
    single object ATEXIT_().

Member Function Documentation

template<class TYPE >
TYPE * SINGLETON_< TYPE >::Instance ( void  )
static

Singleton dynamic creation using the default builder.

The class method Instance :

  1. creates an object of class TYPE ;
  2. creates a destruction object DESTRUCTEUR_DE_<TYPE> which is appended to the list of destruction objects to be executed ;
  3. returns a pointer to the created object.

Note that the two created objects are deleted at the end of the process in the function Nettoyage().

template<class TYPE >
bool SINGLETON_< TYPE >::IsAlreadyExisting ( void  )
static

returns True if the singleton is already existing

template<class TYPE >
int SINGLETON_< TYPE >::Destruction ( void  )
static

destroys the Singleton before the end of the application process

The method SINGLETON_<TYPE>::Destruction can be called by the user. If it is not the function nettoyage() calls it atexit.

N.B. : the singleton objects are destroyed in the reverse order of there creation.