Back to index

nux  3.0.0
NuxGlobalInitializer.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef NUXGLOBALINITIALIZER_H
00024 #define NUXGLOBALINITIALIZER_H
00025 
00026 #define NUX_NUX_GLOBAL_OBJECT_INIT_SEQUENCE()
00027 //
00028 //    NUX_GLOBAL_OBJECT_VARIABLE(RenderingStats);
00029 
00030 
00031 
00032 namespace nux
00033 {
00034 
00035   class NuxGlobalSingletonInitializer
00036   {
00037     NUX_DISABLE_OBJECT_COPY(NuxGlobalSingletonInitializer);
00038     NuxGlobalSingletonInitializer *operator & ();
00039     const NuxGlobalSingletonInitializer *operator & () const;
00040 
00041   public:
00042     NuxGlobalSingletonInitializer();
00043     ~NuxGlobalSingletonInitializer();
00044 
00045     static bool Ready();
00046   private:
00047     static bool m_NuxGlobalObjectsReady;
00048 
00049     NUX_NUX_GLOBAL_OBJECT_INIT_SEQUENCE();
00050   };
00051 
00052 
00053 // Nifty Counter idiom. See http://www-d0.fnal.gov/KAI/doc/tutorials/static_initialization.html
00054   class NuxGlobalInitializer
00055   {
00056   public:
00057     NuxGlobalInitializer();
00058     ~NuxGlobalInitializer();
00059   private:
00060     static int m_Count;
00061   };
00062 
00063 // Every compilation unit that includes this file will have its own instance of sGlobalInitializer. sGlobalInitializer is initialized
00064 // before the main function of the program is called. The first time sGlobalInitializer is initialized, it calls SystemStart() to create
00065 // our global object singleton. In SystemStart() we have a change to create our singletons in any order we like.
00066 // When the program exits, every instance of sGlobalInitializer will be destroyed. The last instance destroyed will call SystemShutdown().
00067 // In SystemShutdown() we can destroy our global objects in any order we like.
00068 
00069   static NuxGlobalInitializer sNuxGlobalInitializer;
00070 
00071 
00072 }
00073 
00074 #endif // NUXGLOBALINITIALIZER_H