~hikiko/nux/arb-srgba-shader

« back to all changes in this revision

Viewing changes to NuxCore/NGlobalInitializer.h

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-01 19:25:37 UTC
  • Revision ID: neil.patel@canonical.com-20100901192537-mfz7rm6q262pewg6
Import and build NuxCore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef NGLOBALINITIALIZER_H
 
2
#define NGLOBALINITIALIZER_H
 
3
 
 
4
#ifdef _WIN32
 
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);
 
17
 
 
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);
 
38
#endif
 
39
 
 
40
NAMESPACE_BEGIN
 
41
 
 
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()
 
46
//       
 
47
// You may also create NGlobalSingletonInitializer in this way:
 
48
//      main()
 
49
//      {
 
50
//          NGlobalSingletonInitializer GlobalInitializer;
 
51
//      }
 
52
//
 
53
//
 
54
 
 
55
class NGlobalSingletonInitializer
 
56
{
 
57
    INL_DISABLE_OBJECT_COPY(NGlobalSingletonInitializer);
 
58
    NGlobalSingletonInitializer* operator & ();
 
59
    const NGlobalSingletonInitializer* operator & () const;
 
60
 
 
61
public:
 
62
    NGlobalSingletonInitializer();
 
63
    ~NGlobalSingletonInitializer();
 
64
 
 
65
    static bool Ready();
 
66
private:
 
67
    static bool m_bGlobalObjectsReady;
 
68
 
 
69
    INL_GLOBAL_OBJECT_INIT_SEQUENCE();
 
70
};
 
71
 
 
72
// Hide these functions
 
73
// extern INL_DLL_ENTRY void SystemStart();
 
74
// extern INL_DLL_ENTRY void SystemShutdown();
 
75
 
 
76
 
 
77
 
 
78
// Nifty Counter idiom. See http://www-d0.fnal.gov/KAI/doc/tutorials/static_initialization.html
 
79
class NGlobalInitializer
 
80
{
 
81
public:
 
82
    NGlobalInitializer();
 
83
    ~NGlobalInitializer();
 
84
private:
 
85
    static int m_Count;
 
86
};
 
87
 
 
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.
 
93
 
 
94
static NGlobalInitializer sGlobalInitializer;
 
95
 
 
96
 
 
97
NAMESPACE_END
 
98
 
 
99
#endif // NGLOBALINITIALIZER_H
 
100