X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FUtils%2FUtils_SINGLETON.hxx;h=1a9228903899a6b23b83912976f4ef594884ecab;hb=13bcfc46055d1da4629579b437304a0016e75438;hp=4e06560a00cad19cb745ea2c2ea89974da4f9360;hpb=e016b7585c279113f84350c12ed1afdc898a47a3;p=modules%2Fkernel.git diff --git a/src/Utils/Utils_SINGLETON.hxx b/src/Utils/Utils_SINGLETON.hxx index 4e06560a0..1a9228903 100644 --- a/src/Utils/Utils_SINGLETON.hxx +++ b/src/Utils/Utils_SINGLETON.hxx @@ -1,34 +1,36 @@ -// SALOME Utils : general SALOME's definitions and tools +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// 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 -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // +// 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 +// Lesser General Public License for more details. // +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// SALOME Utils : general SALOME's definitions and tools // File : Utils_SINGLETON.hxx // Author : Antoine YESSAYAN, EDF // Module : SALOME // $Header$ - +// # if !defined( __SINGLETON__H__ ) # define __SINGLETON__H__ +#include "SALOME_Utils.hxx" + # include "Utils_DESTRUCTEUR_GENERIQUE.hxx" # include @@ -50,21 +52,21 @@ * To create a single instance a POINT_ object : * * # include "Utils_SINGLETON.hxx" - * ... - * ptrPoint = SINGLETON_::Instance() ; + * ... + * ptrPoint = SINGLETON_::Instance() ; * * * Design description * - * -# the user creates an object of class TYPE By using a class method : SINGLETON_::Instance() which - * returns a pointer to the single object ; - * -# this class method uses the default constructor to create an object ; - * -# at the same time, this class method reate a destructor object which is added to the generic list - * of destructors objects to be executed at the end of the application (atexit) ; - * -# at the end of the application process all the deletions are performed by the Nettoyage() C function - * which execute the destructions objects then deletes the destructions objects themselves ; - * -# the Nettoyage() C function is recorded using atexit() C function through the creation of a static - * single object ATEXIT_(). + * -# the user creates an object of class TYPE By using a class method : SINGLETON_::Instance() which + * returns a pointer to the single object ; + * -# this class method uses the default constructor to create an object ; + * -# at the same time, this class method reate a destructor object which is added to the generic list + * of destructors objects to be executed at the end of the application (atexit) ; + * -# at the end of the application process all the deletions are performed by the Nettoyage() C function + * which execute the destructions objects then deletes the destructions objects themselves ; + * -# the Nettoyage() C function is recorded using atexit() C function through the creation of a static + * single object ATEXIT_(). */ @@ -73,19 +75,19 @@ template class SINGLETON_ public : - static TYPE *Instance( void ); //!< Singleton dynamic creation using the default builder - static bool IsAlreadyExisting( void ); //!< returns True if the singleton is already existing - static int Destruction( void ); //!< destroys the Singleton before the end of the application process + static TYPE *Instance( void ); //!< Singleton dynamic creation using the default builder + static bool IsAlreadyExisting( void ); //!< returns True if the singleton is already existing + static int Destruction( void ); //!< destroys the Singleton before the end of the application process private : - TYPE _Instance ; - static SINGLETON_ *PtrSingleton ; + TYPE _Instance ; + static SINGLETON_ *PtrSingleton ; - SINGLETON_( void ); - ~SINGLETON_(); + SINGLETON_( void ); + ~SINGLETON_(); -} ; /* class SINGLETON_ */ +} ; /* class SINGLETON_ */ @@ -105,19 +107,19 @@ template SINGLETON_ *SINGLETON_::PtrSingleton=NULL ; */ template TYPE *SINGLETON_::Instance( void ) { - if ( ! PtrSingleton ) - { - //MESSAGE("SINGLETON_::Instance( void )") ; - PtrSingleton = new SINGLETON_ ; - new DESTRUCTEUR_DE_( PtrSingleton->_Instance ) ; - } - return &PtrSingleton->_Instance ; + if ( ! PtrSingleton ) + { + //MESSAGE("SINGLETON_::Instance( void )") ; + PtrSingleton = new SINGLETON_ ; + new DESTRUCTEUR_DE_( PtrSingleton->_Instance ) ; + } + return &PtrSingleton->_Instance ; } template bool SINGLETON_::IsAlreadyExisting( void ) { - return PtrSingleton ? true : false ; + return PtrSingleton ? true : false ; } @@ -125,47 +127,47 @@ template bool SINGLETON_::IsAlreadyExisting( void ) template SINGLETON_::SINGLETON_( void ) { - //MESSAGE("CREATION d'un SINGLETON_") ; + //MESSAGE("CREATION d'un SINGLETON_") ; } /*! - The method SINGLETON_::Destruction can be called by the user. If it is not - the function nettoyage() calls it atexit. + The method SINGLETON_::Destruction can be called by the user. If it is not + the function nettoyage() calls it atexit. - N.B. : the singleton objects are destroyed in the reverse order of there creation. + N.B. : the singleton objects are destroyed in the reverse order of there creation. */ template int SINGLETON_::Destruction( void ) { - int k = - 1 ; - BEGIN_OF("SINGLETON_::Destruction( void )") ; - if ( PtrSingleton ) - { - MESSAGE("Destruction du SINGLETON_") ; - - - list::iterator k ; - for( k=DESTRUCTEUR_GENERIQUE_::Destructeurs.begin() ; k!=DESTRUCTEUR_GENERIQUE_::Destructeurs.end();k++) - { - if ( *k == PtrSingleton->_Instance ) - { - DESTRUCTEUR_GENERIQUE_::Destructeurs.erase( k ) ; - break ; - } - } - delete PtrSingleton ; - PtrSingleton = NULL ; - } - END_OF("SINGLETON_::Destruction( void )") ; - return k ; + int k = - 1 ; + //BEGIN_OF("SINGLETON_::Destruction( void )") ; + if ( PtrSingleton ) + { + //MESSAGE("Destruction du SINGLETON_") ; + + + std::list::iterator k ; + for( k=DESTRUCTEUR_GENERIQUE_::Destructeurs->begin() ; k!=DESTRUCTEUR_GENERIQUE_::Destructeurs->end();k++) + { + if ( *k == PtrSingleton->_Instance ) + { + DESTRUCTEUR_GENERIQUE_::Destructeurs->erase( k ) ; + break ; + } + } + delete PtrSingleton ; + PtrSingleton = NULL ; + } + //END_OF("SINGLETON_::Destruction( void )") ; + return k ; } template SINGLETON_::~SINGLETON_() { - MESSAGE("passage dans SINGLETON_::~SINGLETON_( void )") ; + //MESSAGE("passage dans SINGLETON_::~SINGLETON_( void )") ; } -# endif /* # if !defined( __SINGLETON__H__ ) */ +# endif /* # if !defined( __SINGLETON__H__ ) */