00001 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE 00002 // 00003 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, 00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 00005 // 00006 // This library is free software; you can redistribute it and/or 00007 // modify it under the terms of the GNU Lesser General Public 00008 // License as published by the Free Software Foundation; either 00009 // version 2.1 of the License. 00010 // 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // Lesser General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public 00017 // License along with this library; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 // 00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com 00021 // 00022 // SALOME Utils : general SALOME's definitions and tools 00023 // File : Utils_DESTRUCTEUR_GENERIQUE.hxx 00024 // Author : Antoine YESSAYAN, EDF 00025 // Module : SALOME 00026 // $Header$ 00027 // 00028 # if !defined( __DESTRUCTEUR_GENERIQUE__H__ ) 00029 # define __DESTRUCTEUR_GENERIQUE__H__ 00030 00031 #include <SALOMEconfig.h> 00032 00033 #include "SALOME_Utils.hxx" 00034 00035 #include <list> 00036 #include <cassert> 00037 #include <omniORB4/CORBA.h> 00038 #include <iostream> 00039 //# include "utilities.h" 00040 00062 class UTILS_EXPORT DESTRUCTEUR_GENERIQUE_ 00063 { 00064 public : 00065 static std::list<DESTRUCTEUR_GENERIQUE_*> *Destructeurs; 00066 00067 virtual ~DESTRUCTEUR_GENERIQUE_() {} 00068 static const int Ajout( DESTRUCTEUR_GENERIQUE_ &objet ); 00069 virtual void operator()( void )=0 ; 00070 }; 00071 00072 00095 template <class TYPE> class DESTRUCTEUR_DE_ : public DESTRUCTEUR_GENERIQUE_ 00096 { 00097 public : 00098 /* Programs the destruction at the end of the process, of the object objet. 00099 This method records in _PtrObjet the address of an object to be destroyed 00100 at the end of the process 00101 */ 00102 DESTRUCTEUR_DE_(TYPE &objet): 00103 _PtrObjet( &objet ) 00104 { 00105 assert(DESTRUCTEUR_GENERIQUE_::Ajout( *this ) >= 0) ; 00106 } 00107 00108 /* Performs the destruction of the object. 00109 This method really destroys the object pointed by _PtrObjet. 00110 It should be called at the end of the process (i.e. at exit). 00111 */ 00112 virtual void operator()(void){ 00113 typedef PortableServer::ServantBase TServant; 00114 if(_PtrObjet){ 00115 if(dynamic_cast<TServant*>(_PtrObjet)){ 00116 // std::cerr << "WARNING: automatic destruction for servant is no more used. It's too late in exit. Use explicit call" << std::endl; 00117 /* 00118 if(TServant* aServant = dynamic_cast<TServant*>(_PtrObjet)){ 00119 PortableServer::POA_var aPOA = aServant->_default_POA(); 00120 PortableServer::ObjectId_var anObjectId = aPOA->servant_to_id(aServant); 00121 aPOA->deactivate_object(anObjectId.in()); 00122 aServant->_remove_ref(); 00123 */ 00124 }else{ 00125 //cerr << "DESTRUCTEUR_GENERIQUE_::operator() deleting _PtrObjet" << endl; 00126 TYPE* aPtr = static_cast<TYPE*>(_PtrObjet); 00127 delete aPtr; 00128 } 00129 _PtrObjet = NULL ; 00130 } 00131 } 00132 00133 virtual ~DESTRUCTEUR_DE_(){ 00134 assert(!_PtrObjet) ; 00135 } 00136 00137 private : 00138 TYPE *_PtrObjet ; 00139 }; 00140 00141 00142 # endif /* # if !defined( __DESTRUCTEUR_GENERIQUE__H__ ) */