1
#ifndef NGLOBALINITIALIZER_H
2
#define NGLOBALINITIALIZER_H
5
#define INL_GLOBAL_OBJECT_INIT_SEQUENCE() \
6
INL_GLOBAL_OBJECT_VARIABLE(NGlobalData); \
7
INL_GLOBAL_OBJECT_VARIABLE(NCPU); \
8
INL_GLOBAL_OBJECT_VARIABLE(NProcess); \
9
INL_GLOBAL_OBJECT_VARIABLE(NNullOutput); \
10
INL_GLOBAL_OBJECT_VARIABLE(NUniqueIndex); \
11
INL_GLOBAL_OBJECT_VARIABLE(NFileManagerWindows); \
12
INL_GLOBAL_OBJECT_VARIABLE(NOutputVisualDebugConsole); \
13
INL_GLOBAL_OBJECT_VARIABLE(NOutputLogFile); \
14
INL_GLOBAL_OBJECT_VARIABLE(NOutputDeviceRedirector); \
15
INL_GLOBAL_OBJECT_VARIABLE(NDefaultMemoryAllocator); \
16
INL_GLOBAL_OBJECT_VARIABLE(MemHook);
18
#elif (defined INL_PS3)
19
#define INL_GLOBAL_OBJECT_INIT_SEQUENCE() \
20
INL_GLOBAL_OBJECT_VARIABLE(NNullOutput); \
21
INL_GLOBAL_OBJECT_VARIABLE(NUniqueIndex); \
22
INL_GLOBAL_OBJECT_VARIABLE(NFileManagerPS3); \
23
INL_GLOBAL_OBJECT_VARIABLE(NOutputLogFile); \
24
INL_GLOBAL_OBJECT_VARIABLE(NOutputDeviceRedirector); \
25
INL_GLOBAL_OBJECT_VARIABLE(NDefaultMemoryAllocator); \
26
INL_GLOBAL_OBJECT_VARIABLE(MemHook);
27
#elif (defined INL_OS_LINUX)
28
#define INL_GLOBAL_OBJECT_INIT_SEQUENCE() \
29
INL_GLOBAL_OBJECT_VARIABLE(NGlobalData); \
30
INL_GLOBAL_OBJECT_VARIABLE(NNullOutput); \
31
INL_GLOBAL_OBJECT_VARIABLE(NUniqueIndex); \
32
INL_GLOBAL_OBJECT_VARIABLE(NFileManagerGNU); \
33
INL_GLOBAL_OBJECT_VARIABLE(NOutputVisualDebugConsole); \
34
INL_GLOBAL_OBJECT_VARIABLE(NOutputLogFile); \
35
INL_GLOBAL_OBJECT_VARIABLE(NOutputDeviceRedirector); \
36
INL_GLOBAL_OBJECT_VARIABLE(NDefaultMemoryAllocator); \
37
INL_GLOBAL_OBJECT_VARIABLE(MemHook);
42
// This class initialize all inalogic singleton (global objects) in order. It also initialize memory allocators.
43
// Therefore, do not call new NGlobalSingletonInitializer as it will try to call inalogic memory allocator and fail.
44
// You may use the global placement new operator(it is not overwritten by inalogic) to create NGlobalSingletonInitializer
45
// inside the application data space by calling SystemInitializer(). At shutdown, call SystemShutdown()
47
// You may also create NGlobalSingletonInitializer in this way:
50
// NGlobalSingletonInitializer GlobalInitializer;
55
class NGlobalSingletonInitializer
57
INL_DISABLE_OBJECT_COPY(NGlobalSingletonInitializer);
58
NGlobalSingletonInitializer* operator & ();
59
const NGlobalSingletonInitializer* operator & () const;
62
NGlobalSingletonInitializer();
63
~NGlobalSingletonInitializer();
67
static bool m_bGlobalObjectsReady;
69
INL_GLOBAL_OBJECT_INIT_SEQUENCE();
72
// Hide these functions
73
// extern INL_DLL_ENTRY void SystemStart();
74
// extern INL_DLL_ENTRY void SystemShutdown();
78
// Nifty Counter idiom. See http://www-d0.fnal.gov/KAI/doc/tutorials/static_initialization.html
79
class NGlobalInitializer
83
~NGlobalInitializer();
88
// Every compilation unit that includes this file will have its own instance of sGlobalInitializer. sGlobalInitializer is initialized
89
// before the main function of the program is called. The first time sGlobalInitializer is initialized, it calls SystemStart() to create
90
// our global object singleton. In SystemStart() we have a change to create our singletons in any order we like.
91
// When the program exits, every instance of sGlobalInitializer will be destroyed. The last instance destroyed will call SystemShutdown().
92
// In SystemShutdown() we can destroy our global objects in any order we like.
94
static NGlobalInitializer sGlobalInitializer;
99
#endif // NGLOBALINITIALIZER_H