Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Initializer.h
1
/*
2
* $Id$
3
* Copyright (c) 2006 - IRIT-UPS <casse@irit.fr>
4
*
5
* Initializer class interface.
6
*/
7
#ifndef ELM_UTIL_INITIALIZER_H
8
#define ELM_UTIL_INITIALIZER_H
9
10
namespace
elm
{
11
12
// Initializer class
13
template
<
class
T>
14
class
Initializer
{
15
typedef
struct
node_t {
16
struct
node_t *next;
17
T *object;
18
inline
node_t(T *_object,
struct
node_t *_next)
19
: next(_next), object(_object) { }
20
} node_t;
21
22
static
node_t *list;
23
static
bool
initialized;
24
public
:
25
Initializer
(
bool
start =
true
);
26
~Initializer
(
void
);
27
void
record
(T *
object
);
28
void
startup
(
void
);
29
};
30
31
// Statics
32
template
<
class
T>
typename
Initializer<T>::node_t
*
Initializer<T>::list
= 0;
33
template
<
class
T>
bool
Initializer<T>::initialized
=
false
;
34
35
// Initializer<T>::Initializer
36
template
<
class
T>
37
Initializer<T>::Initializer
(
bool
start) {
38
if
(start)
39
startup();
40
}
41
42
// Initializer<T>::~Initializer
43
template
<
class
T>
44
Initializer<T>::~Initializer
(
void
) {
45
for
(node_t *node =
list
, *next; node; node = next) {
46
next = node->next;
47
delete
node;
48
}
49
}
50
51
// Initializer<T>::record
52
template
<
class
T>
53
void
Initializer<T>::record
(T *
object
) {
54
if
(initialized)
55
object
->initialize();
56
else
{
57
list
=
new
node_t(
object
,
list
);
58
}
59
}
60
61
// Initializer<T>::startup()
62
template
<
class
T>
63
void
Initializer<T>::startup
(
void
) {
64
if
(!initialized) {
65
initialized =
true
;
66
for
(node_t *node =
list
, *next; node; node = next) {
67
next = node->next;
68
node->object->initialize();
69
delete
node;
70
}
71
list
= 0;
72
}
73
}
74
75
}
// elm
76
77
#endif // ELM_UTIL_INITIALIZER_H
78
elm::Initializer::~Initializer
~Initializer(void)
Definition:
Initializer.h:44
elm::Initializer::record
void record(T *object)
Definition:
Initializer.h:53
elm::io::list
ListPrinter< T > list(const T &l, cstring s="", typename ListPrinter< T >::fun_t f=ListPrinter< T >::asis)
Definition:
Output.h:321
elm
Definition:
adapter.h:26
elm::Initializer::startup
void startup(void)
Definition:
Initializer.h:63
elm::Initializer
Definition:
Initializer.h:14
elm::Initializer::Initializer
Initializer(bool start=true)
Definition:
Initializer.h:37
include
elm
util
Initializer.h
Generated on Fri Jul 23 2021 11:32:45 for Elm by
1.8.17