Back to index

salome-kernel  6.5.0
Utils_DESTRUCTEUR_GENERIQUE.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  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 
00023 //  SALOME Utils : general SALOME's definitions and tools
00024 //  File   : Utils_DESTRUCTEUR_GENERIQUE.hxx
00025 //  Author : Antoine YESSAYAN, EDF
00026 //  Module : SALOME
00027 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.hxx,v 1.7.2.1.10.2.12.1 2012-04-12 14:05:32 vsr Exp $
00028 //
00029 # if !defined( __DESTRUCTEUR_GENERIQUE__H__ )
00030 # define __DESTRUCTEUR_GENERIQUE__H__
00031 
00032 #include <SALOMEconfig.h>
00033 
00034 #include "SALOME_Utils.hxx"
00035 
00036 #include <list>
00037 #include <cassert>
00038 #include <omniORB4/CORBA.h>
00039 #include <iostream>
00040 //# include "utilities.h"
00041 
00063 class UTILS_EXPORT DESTRUCTEUR_GENERIQUE_
00064 {
00065 public :
00066   static std::list<DESTRUCTEUR_GENERIQUE_*> *Destructeurs;
00067 
00068   virtual ~DESTRUCTEUR_GENERIQUE_() {}
00069   static const int Ajout( DESTRUCTEUR_GENERIQUE_ &objet );
00070   virtual void operator()( void )=0 ;
00071 };
00072 
00073 
00096 template <class TYPE> class DESTRUCTEUR_DE_ : public DESTRUCTEUR_GENERIQUE_
00097 {
00098 public :
00099   /* Programs the destruction at the end of the process, of the object objet.
00100      This method records in _PtrObjet the address of an object to be destroyed 
00101      at the end of the process
00102   */
00103   DESTRUCTEUR_DE_(TYPE &objet):
00104     _PtrObjet( &objet )
00105   {
00106     assert(DESTRUCTEUR_GENERIQUE_::Ajout( *this ) >= 0) ;
00107   }
00108 
00109   /* Performs the destruction of the object.
00110      This method really destroys the object pointed by _PtrObjet. 
00111      It should be called at the end of the process (i.e. at exit).
00112   */
00113   virtual void operator()(void){
00114     typedef PortableServer::ServantBase TServant;
00115     if(_PtrObjet){
00116       if(dynamic_cast<TServant*>(_PtrObjet)){
00117        // std::cerr << "WARNING: automatic destruction for servant is no more used. It's too late in exit. Use explicit call" << std::endl;
00118   /*
00119       if(TServant* aServant = dynamic_cast<TServant*>(_PtrObjet)){
00120         PortableServer::POA_var aPOA = aServant->_default_POA();
00121         PortableServer::ObjectId_var anObjectId = aPOA->servant_to_id(aServant);
00122         aPOA->deactivate_object(anObjectId.in());
00123         aServant->_remove_ref();
00124   */
00125       }else{
00126         //cerr << "DESTRUCTEUR_GENERIQUE_::operator() deleting _PtrObjet" << endl;
00127         TYPE* aPtr = static_cast<TYPE*>(_PtrObjet);
00128         delete aPtr;
00129       }
00130       _PtrObjet = NULL ;
00131     }
00132   } 
00133 
00134   virtual ~DESTRUCTEUR_DE_(){
00135     assert(!_PtrObjet) ;
00136   }
00137 
00138 private :
00139   TYPE *_PtrObjet ;
00140 };
00141 
00142 
00143 # endif         /* # if !defined( __DESTRUCTEUR_GENERIQUE__H__ ) */