Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
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

◆ Initializer()

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.

◆ ~Initializer()

~Initializer ( void  )

Member Function Documentation

◆ record()

void record ( T *  object)

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

Parameters
objectObject to initialize.

◆ startup()

void startup ( void  )

Cause the initializer to start to initializer recorded objects.


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