Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
elm::Initializer< T > Class Template Reference

#include <elm/util/Initializer.h>

Public Member Functions

 Initializer (bool start=true)
 
 ~Initializer (void)
 
void record (T *object)
 
void startup (void)
 

Detailed Description

template<class T>
class elm::Initializer< T >

This class is a partial solution to the problem of the initialization order of static variables at the start time of a program in C++. This class solve the following problem at initialization. A set of static object embedded in different sources shares a common datastructure whose initialization time may be happen after some of these objects.

Whatever, the static object initialization is split in two phases. First, the object initialize itself but not the part using the shared data. Instead, they record themselves to the initializer that will, when the shared data will be initialized, call the "void initialize(void)" method of each recorded object ensuring final initialization after the shared data item.
To achieve this goal, either the shared data item must inherit from the Initializer class or an Initializer static instance must be declared after the shared data item.
This class has very small footprint on the memory and, except the Initializer object itself, all memory used will be returned to the system after the initialization stage.
Parameters
TType of the objects to give an order to. Must contain a method named initialize() that is called to perform the real initialization of the object.

Constructor & Destructor Documentation

template<class T >
elm::Initializer< T >::Initializer ( bool  start = true)

Simple constructor.

Parameters
startIf set to true, the initialization takes place at construction else the initialization is delayed until the startup() method call from an external source.
template<class T >
elm::Initializer< T >::~Initializer ( void  )

Member Function Documentation

template<class T>
void elm::Initializer< T >::record ( T *  object)

Record the given object to be initialized after the shared data item.

Parameters
objectObject to initialize.

Referenced by elm::TestCase::TestCase().

template<class T >
void elm::Initializer< T >::startup ( void  )

Cause the initializer to start to initializer recorded objects.


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