1 //=============================================================================
2 // File : Utils_DESTRUCTEUR_GENERIQUE.hxx
3 // Created : Mon Nov 5 17:01:47 CET 2001
4 // Author : Antoine YESSAYAN, EDF
6 // Copyright : EDF 2001
8 //=============================================================================
10 # if !defined( __DESTRUCTEUR_GENERIQUE__H__ )
11 # define __DESTRUCTEUR_GENERIQUE__H__
13 # include "utilities.h"
15 /*!\class DESTRUCTEUR_GENERIQUE_
19 * The DESTRUCTEUR_GENERIQUE_ abstract class describes the comportement of any destruction object.
20 * Tis type is used to create a list of miscellaneous destruction object.
24 * The only way to use the DESTRUCTEUR_GENERIQUE_ class is inheritance :
25 * class DESTRUCTEUR_SPECIFIQUE_ : public DESTRUCTEUR_GENERIQUE_
27 * <B>Design description</B>
29 * A generic destructor supply two functionalities :
30 * -# a static method to add a destruction (objetct) to be performed DESTRUCTEUR_GENERIQUE_::Ajout(
31 * DESTRUCTEUR_GENERIQUE_ &objet) ;
32 * The Destruction object is stored in a list of pointer to DESTRUCTEUR_GENERIQUE_ objects.
33 * -# an object method to execute the destruction : operator()().
36 class DESTRUCTEUR_GENERIQUE_
39 virtual ~DESTRUCTEUR_GENERIQUE_() {}//!< virtual destructor
40 static const int Ajout( DESTRUCTEUR_GENERIQUE_ &objet );//!< adds a destruction object to the list of destructions
41 virtual void operator()( void )=0 ;//!< performs the destruction
49 /*!\class DESTRUCTEUR_DE_
53 * The DESTRUCTEUR_DE_ class allows the user to program - at any moment - the destruction of an object
54 * at the end of the process.
58 * In this example the POINT_ ptrPoint will be destroyed at the end of the process (atexit).
60 * POINT_ *ptrPoint = new POINT_ ;<BR>
61 * DESTRUCTEUR_DE_<POINT_> *ptrDestruction = new DESTRUCTEUR_DE_<POINT_>( *ptrPoint ) ;
63 * Note that neither ptrPoint, nor ptrDestruction should be destroyed by the user.
65 * <B>Design description</B>
67 * The destruction object must be created dynamicaly because it suscribes himself in the list of
68 * destruction to be performed at the end of the process.
72 template <class TYPE> class DESTRUCTEUR_DE_ : public DESTRUCTEUR_GENERIQUE_
76 inline DESTRUCTEUR_DE_( TYPE &objet ); //! programs the destruction at the end of the process, of the object objet
77 virtual void operator()( void ) ; //!< performs the destruction of the object
78 virtual ~DESTRUCTEUR_DE_() ;
80 const TYPE *_PtrObjet ;
89 This method records in _PtrObjet the address of an object to be destroyed at the end of the process
91 template <class TYPE> DESTRUCTEUR_DE_<TYPE>::DESTRUCTEUR_DE_( TYPE &objet ): _PtrObjet( &objet )
93 int k = DESTRUCTEUR_GENERIQUE_::Ajout( *this ) ;
97 template <class TYPE> DESTRUCTEUR_DE_<TYPE>::~DESTRUCTEUR_DE_()
99 ASSERT(_PtrObjet==NULL) ;
103 This method really destroys the object pointed by _PtrObjet. It should be called at the end of the process
106 template <class TYPE> void DESTRUCTEUR_DE_<TYPE>::operator()( void )
110 MESSAGE("deleting _PtrObjet") ;
111 delete (TYPE*)_PtrObjet ;
116 # endif /* # if !defined( __SINGLETON__H__ ) */