//================================================================================================== // S t a n d a r d Interface // I n i t i a l i z e r // By Bruno Bachelet //================================================================================================== // Copyright (c) 1999-2016 // Bruno Bachelet - bruno@nawouak.net - http://www.nawouak.net // // This file is part of the B++ Library. This library is free software; you can redistribute it // and/or modify it under the terms of the GNU Library General Public License as published by the // Free Software Foundation; either version 2 of the License, or (at your option) any later // version. // // This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See // the GNU Library General Public License for more details (http://www.gnu.org).
/*DESCRIPTION*/ /* This module provides facilities to manage the initialization and the termination of a module. */
// File Name //------------------------------------------------------------------------------------- #line __LINE__ "standard/initializer.hpp"
// Guardian //-------------------------------------------------------------------------------------- #ifndef guStandardInitializer #define guStandardInitializer
// Headers //--------------------------------------------------------------------------------------- #include <bpp/display.hpp> /*INCLUDE*/ #include <bpp/standard/thread.hpp> /*INCLUDE*/
namespace bpp {
// Importation/Exportation //----------------------------------------------------------------------- #ifdef STANDARD_DLL #define dll_export DLL_EXPORT #else #define dll_export DLL_IMPORT #endif
// Namespaces //------------------------------------------------------------------------------------ #define public_area standardInitializer #define private_area standardInitializer_private
namespace public_area { /*NAMESPACE*/ using namespace standardKeyword; } namespace private_area { using namespace public_area; }
// Initialization //--------------------------------------------------------------------------------
// Macrocommands //--------------------------------------------------------------------------------- /*MACROCOMMAND*/ /* Used to indicate that a module has an initializer. */ #define has_initializer \ namespace private_area { \ class clInitializer : public standardInitializer::clInitializer { \ private_property int atCounter; \ public_property void start(void); \ public_property void stop(void); \ public_property clInitializer(void) : standardInitializer::clInitializer(),atCounter(0) {} \ }; \ } \ extern_static_constant(private,private_area::clInitializer,goInitializer,?) \
/*MACROCOMMAND*/ /* Launches the initialization sequence of a module. */ #define start_module(prModuleName) ( prModuleName##_private::goInitializer.start() )
// Types & Classes //------------------------------------------------------------------------------- namespace public_area { //------------------------------------------------------------------------------------------Classes class clInitializer; }
namespace private_area {}
// Functions Interface //--------------------------------------------------------------------------- namespace public_area {} namespace private_area {}
// Errors //---------------------------------------------------------------------------------------- namespace public_area {}
// Constants & Variables //------------------------------------------------------------------------- namespace public_area {} namespace private_area {}
// I n i t i a l i z e r Interface //-------------------------------------------------------------- namespace public_area { /*CLASS clInitializer */ /* Abstract class capable of managing the initialization and the termination of a module. Each module has its own subclass inherited from this one. By this way, we manage to initialize each module before any module that needs it and terminate it after all of them. */ class clInitializer { //-----------------------------------------------------------------------------------------Private private_property static int atPhase; private_property static std_vector(clInitializer *) * atStartSequence; private_property static std_vector(clInitializer *) * atStopSequence;
private_property constructor clInitializer(const clInitializer &); private_property clInitializer & operator = (const clInitializer &);
private_property static void registerStart(clInitializer *); //------------------------------------------------------------------------------------------Public public_property constructor clInitializer(void); public_property virtual destructor clInitializer(void);
public_property static void startModules(display::clDisplay &); public_property static void stopModules(void);
/*AMETHOD clInitializer */ /* Initializes a module. When overridden, this method will contain the initialization steps of a module. It must check that it is the first call of the method before doing anything. For that a counter must be used in the derived class. Moreover, the module must be registered to be stopped by calling the method <CODE>registerStop</CODE>. Abstract method. */ public_property virtual void start(void) = 0;
/*AMETHOD clInitializer */ /* Terminates a module. When overridden, this method will contain the termination steps of a module. This method will be called only once. Abstract method. */ public_property virtual void stop(void) = 0;
public_property static void registerStop(clInitializer *); }; }
// Functions Inline //------------------------------------------------------------------------------ namespace public_area {} namespace private_area {}
// I n i t i a l i z e r Inline //----------------------------------------------------------------- namespace public_area { //--------------------------------------------------------------------------------------Constructor /*METHOD clInitializer */ /* Builds the initializer. */ inline clInitializer::clInitializer(void) { registerStart(this); } }
// End //------------------------------------------------------------------------------------------- } #undef dll_export #undef public_area #undef private_area #endif |
//================================================================================================== // S t a n d a r d Implementation // I n i t i a l i z e r // By Bruno Bachelet //================================================================================================== // Copyright (c) 1999-2016 // Bruno Bachelet - bruno@nawouak.net - http://www.nawouak.net // // This file is part of the B++ Library. This library is free software; you can redistribute it // and/or modify it under the terms of the GNU Library General Public License as published by the // Free Software Foundation; either version 2 of the License, or (at your option) any later // version. // // This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See // the GNU Library General Public License for more details (http://www.gnu.org).
// File Name //------------------------------------------------------------------------------------- #line __LINE__ "standard/initializer.cpp"
// DLL Belonging //--------------------------------------------------------------------------------- #define STANDARD_DLL
// Headers //--------------------------------------------------------------------------------------- #include <bpp/standard/environment.hpp> /*NEED*/ #include <bpp/standard/initializer.hpp> /*INTERFACE*/
namespace bpp {
// Namespaces //------------------------------------------------------------------------------------ #define public_area standardInitializer #define private_area standardInitializer_private #define dll_export DLL_EXPORT
namespace public_area {} namespace private_area {}
// Initialization //--------------------------------------------------------------------------------
// Errors //---------------------------------------------------------------------------------------- namespace public_area {}
// Constants & Variables //------------------------------------------------------------------------- namespace public_area {} namespace private_area {}
// Static Members //-------------------------------------------------------------------------------- namespace public_area { property int clInitializer::atPhase = 0; property std_vector(clInitializer *) * clInitializer::atStartSequence; property std_vector(clInitializer *) * clInitializer::atStopSequence; }
namespace private_area {}
// Functions Implementation //---------------------------------------------------------------------- namespace public_area {} namespace private_area {}
// I n i t i a l i z e r Implementation //--------------------------------------------------------- namespace public_area { //------------------------------------------------------------------------------------RegisterStart property void clInitializer::registerStart(clInitializer * agInitializer) { if (atPhase==0) { atStartSequence=new std_vector(clInitializer *); atPhase=1; }
if (atPhase==1) atStartSequence->push_back(agInitializer); } //---------------------------------------------------------------------------------------Destructor /*METHOD clInitializer */ /* Destructs the initializer. */ property clInitializer::~clInitializer(void) {} //-------------------------------------------------------------------------------------RegisterStop /*METHOD clInitializer */ /* Registers the initializer of a module to be stopped when terminating the whole library. Class method. */ property void clInitializer::registerStop(clInitializer * agInitializer) { if (atPhase==2) { atStopSequence=new std_vector(clInitializer *); atPhase=3; }
if (atPhase==3) atStopSequence->push_back(agInitializer); } //-------------------------------------------------------------------------------------StartModules /*METHOD clInitializer */ /* Initializes all the modules that have an initializer object. Class method. */ property void clInitializer::startModules(display::clDisplay & agDisplay) { typedef std_vector(clInitializer *)::const_iterator clIterator;
clIterator lcCurrentInitializer; clIterator lcLastInitializer;
environment_private::goDisplay=&agDisplay;
if (atPhase==1) { atPhase=2; lcCurrentInitializer=atStartSequence->begin(); lcLastInitializer=atStartSequence->end();
while (lcCurrentInitializer!=lcLastInitializer) { (*lcCurrentInitializer)->start(); ++lcCurrentInitializer; }
delete atStartSequence; } } //--------------------------------------------------------------------------------------StopModules /*METHOD clInitializer */ /* Terminates all the modules in the reverse order of registration of their initializer. Class method. */ property void clInitializer::stopModules(void) { typedef std_vector(clInitializer *)::reverse_iterator clIterator;
clIterator lcCurrentInitializer; clIterator lcLastInitializer;
if (atPhase==3) { lcCurrentInitializer=atStopSequence->rbegin(); lcLastInitializer=atStopSequence->rend();
while (lcCurrentInitializer!=lcLastInitializer) { (*lcCurrentInitializer)->stop(); ++lcCurrentInitializer; }
atPhase=4; delete atStopSequence; } } }
// End //------------------------------------------------------------------------------------------- } |
|