1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME Utils : general SALOME's definitions and tools
24 // File : Utils_DESTRUCTEUR_GENERIQUE.hxx
25 // Author : Antoine YESSAYAN, EDF
29 # if !defined( __DESTRUCTEUR_GENERIQUE__H__ )
30 # define __DESTRUCTEUR_GENERIQUE__H__
32 #include <SALOMEconfig.h>
34 #include "SALOME_Utils.hxx"
38 #include <omniORB4/CORBA.h>
40 //# include "utilities.h"
42 /*!\class DESTRUCTEUR_GENERIQUE_
46 * The DESTRUCTEUR_GENERIQUE_ abstract class describes the comportement of any destruction object.
47 * Tis type is used to create a list of miscellaneous destruction object.
51 * The only way to use the DESTRUCTEUR_GENERIQUE_ class is inheritance :
52 * class DESTRUCTEUR_SPECIFIQUE_ : public DESTRUCTEUR_GENERIQUE_
54 * <B>Design description</B>
56 * A generic destructor supply two functionalities :
57 * -# a static method to add a destruction (objetct) to be performed DESTRUCTEUR_GENERIQUE_::Ajout(
58 * DESTRUCTEUR_GENERIQUE_ &objet) ;
59 * The Destruction object is stored in a list of pointer to DESTRUCTEUR_GENERIQUE_ objects.
60 * -# an object method to execute the destruction : operator()().
63 class UTILS_EXPORT DESTRUCTEUR_GENERIQUE_
66 static std::list<DESTRUCTEUR_GENERIQUE_*> *Destructeurs;
68 virtual ~DESTRUCTEUR_GENERIQUE_() {}//!< virtual destructor
69 static const int Ajout( DESTRUCTEUR_GENERIQUE_ &objet );//!< adds a destruction object to the list of destructions
70 virtual void operator()( void )=0 ;//!< performs the destruction
74 /*!\class DESTRUCTEUR_DE_
78 * The DESTRUCTEUR_DE_ class allows the user to program - at any moment - the destruction of an object
79 * at the end of the process.
83 * In this example the POINT_ ptrPoint will be destroyed at the end of the process (atexit).
85 * POINT_ *ptrPoint = new POINT_ ;<BR>
86 * DESTRUCTEUR_DE_<POINT_> *ptrDestruction = new DESTRUCTEUR_DE_<POINT_>( *ptrPoint ) ;
88 * Note that neither ptrPoint, nor ptrDestruction should be destroyed by the user.
90 * <B>Design description</B>
92 * The destruction object must be created dynamicaly because it suscribes himself in the list of
93 * destruction to be performed at the end of the process.
96 template <class TYPE> class DESTRUCTEUR_DE_ : public DESTRUCTEUR_GENERIQUE_
99 /* Programs the destruction at the end of the process, of the object objet.
100 This method records in _PtrObjet the address of an object to be destroyed
101 at the end of the process
103 DESTRUCTEUR_DE_(TYPE &objet):
106 assert(DESTRUCTEUR_GENERIQUE_::Ajout( *this ) >= 0) ;
109 /* Performs the destruction of the object.
110 This method really destroys the object pointed by _PtrObjet.
111 It should be called at the end of the process (i.e. at exit).
113 virtual void operator()(void){
114 typedef PortableServer::ServantBase TServant;
116 if(dynamic_cast<TServant*>(_PtrObjet)){
117 // std::cerr << "WARNING: automatic destruction for servant is no more used. It's too late in exit. Use explicit call" << std::endl;
119 if(TServant* aServant = dynamic_cast<TServant*>(_PtrObjet)){
120 PortableServer::POA_var aPOA = aServant->_default_POA();
121 PortableServer::ObjectId_var anObjectId = aPOA->servant_to_id(aServant);
122 aPOA->deactivate_object(anObjectId.in());
123 aServant->_remove_ref();
126 //cerr << "DESTRUCTEUR_GENERIQUE_::operator() deleting _PtrObjet" << endl;
127 TYPE* aPtr = static_cast<TYPE*>(_PtrObjet);
134 virtual ~DESTRUCTEUR_DE_(){
143 # endif /* # if !defined( __DESTRUCTEUR_GENERIQUE__H__ ) */