nux-1.14.0
NuxGlobalInitializer.cpp
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 #include "Nux.h"
00024 #include "NuxGlobalInitializer.h"
00025 
00026 namespace nux
00027 {
00028 
00029   static NuxGlobalSingletonInitializer *GNuxGlobalInitializer   = 0;
00030 
00031   static void SystemStart()
00032   {
00033     static t_u8 StaticBuffer[sizeof (NuxGlobalSingletonInitializer) ];
00034     // Placement new in our reserved buffer.
00035     GNuxGlobalInitializer =  new (StaticBuffer) NuxGlobalSingletonInitializer();
00036 
00037     //GLogDevice.AddOutputDevice( &NUX_GLOBAL_OBJECT_INSTANCE(NOutputLogFile) );
00038     //GLogDevice.AddOutputDevice( &NUX_GLOBAL_OBJECT_INSTANCE(NOutputVisualDebugConsole) );
00039   }
00040 
00041   static void SystemShutdown()
00042   {
00043     // Manually destroy initializer
00044     if (GNuxGlobalInitializer)
00045       GNuxGlobalInitializer->~NuxGlobalSingletonInitializer();
00046 
00047     GNuxGlobalInitializer = 0;
00048 
00049   }
00050 
00051   bool NuxGlobalSingletonInitializer::m_NuxGlobalObjectsReady = false;
00052   NuxGlobalSingletonInitializer::NuxGlobalSingletonInitializer()
00053   {
00054     m_NuxGlobalObjectsReady = true;
00055   }
00056 
00057   NuxGlobalSingletonInitializer::~NuxGlobalSingletonInitializer()
00058   {
00059     m_NuxGlobalObjectsReady = false;
00060   }
00061 
00062   bool NuxGlobalSingletonInitializer::Ready()
00063   {
00064     return m_NuxGlobalObjectsReady;
00065   }
00066 
00067   int NuxGlobalInitializer::m_Count = 0;
00068   NuxGlobalInitializer::NuxGlobalInitializer()
00069   {
00070     if (m_Count++ == 0)
00071     {
00072       SystemStart();
00073     }
00074   }
00075 
00076   NuxGlobalInitializer::~NuxGlobalInitializer()
00077   {
00078     if (--m_Count == 0)
00079     {
00080       SystemShutdown();
00081     }
00082   }
00083 
00084 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends