1 // SALOME Utils : general SALOME's definitions and tools
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : Utils_DESTRUCTEUR_GENERIQUE.hxx
25 // Author : Antoine YESSAYAN, EDF
29 # if !defined( __DESTRUCTEUR_GENERIQUE__H__ )
30 # define __DESTRUCTEUR_GENERIQUE__H__
32 # include "utilities.h"
34 /*!\class DESTRUCTEUR_GENERIQUE_
38 * The DESTRUCTEUR_GENERIQUE_ abstract class describes the comportement of any destruction object.
39 * Tis type is used to create a list of miscellaneous destruction object.
43 * The only way to use the DESTRUCTEUR_GENERIQUE_ class is inheritance :
44 * class DESTRUCTEUR_SPECIFIQUE_ : public DESTRUCTEUR_GENERIQUE_
46 * <B>Design description</B>
48 * A generic destructor supply two functionalities :
49 * -# a static method to add a destruction (objetct) to be performed DESTRUCTEUR_GENERIQUE_::Ajout(
50 * DESTRUCTEUR_GENERIQUE_ &objet) ;
51 * The Destruction object is stored in a list of pointer to DESTRUCTEUR_GENERIQUE_ objects.
52 * -# an object method to execute the destruction : operator()().
55 class DESTRUCTEUR_GENERIQUE_
58 virtual ~DESTRUCTEUR_GENERIQUE_() {}//!< virtual destructor
59 static const int Ajout( DESTRUCTEUR_GENERIQUE_ &objet );//!< adds a destruction object to the list of destructions
60 virtual void operator()( void )=0 ;//!< performs the destruction
68 /*!\class DESTRUCTEUR_DE_
72 * The DESTRUCTEUR_DE_ class allows the user to program - at any moment - the destruction of an object
73 * at the end of the process.
77 * In this example the POINT_ ptrPoint will be destroyed at the end of the process (atexit).
79 * POINT_ *ptrPoint = new POINT_ ;<BR>
80 * DESTRUCTEUR_DE_<POINT_> *ptrDestruction = new DESTRUCTEUR_DE_<POINT_>( *ptrPoint ) ;
82 * Note that neither ptrPoint, nor ptrDestruction should be destroyed by the user.
84 * <B>Design description</B>
86 * The destruction object must be created dynamicaly because it suscribes himself in the list of
87 * destruction to be performed at the end of the process.
91 template <class TYPE> class DESTRUCTEUR_DE_ : public DESTRUCTEUR_GENERIQUE_
95 inline DESTRUCTEUR_DE_( TYPE &objet ); //! programs the destruction at the end of the process, of the object objet
96 virtual void operator()( void ) ; //!< performs the destruction of the object
97 virtual ~DESTRUCTEUR_DE_() ;
99 const TYPE *_PtrObjet ;
108 This method records in _PtrObjet the address of an object to be destroyed at the end of the process
110 template <class TYPE> DESTRUCTEUR_DE_<TYPE>::DESTRUCTEUR_DE_( TYPE &objet ): _PtrObjet( &objet )
112 int k = DESTRUCTEUR_GENERIQUE_::Ajout( *this ) ;
116 template <class TYPE> DESTRUCTEUR_DE_<TYPE>::~DESTRUCTEUR_DE_()
118 ASSERT(_PtrObjet==NULL) ;
122 This method really destroys the object pointed by _PtrObjet. It should be called at the end of the process
125 template <class TYPE> void DESTRUCTEUR_DE_<TYPE>::operator()( void )
129 MESSAGE("deleting _PtrObjet") ;
130 delete (TYPE*)_PtrObjet ;
135 # endif /* # if !defined( __SINGLETON__H__ ) */