Version: 9.16.0
Utils_DESTRUCTEUR_GENERIQUE.hxx
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, OPEN CASCADE
2//
3// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5//
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, or (at your option) any later version.
10//
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.
15//
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
19//
20// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21//
22
23// SALOME Utils : general SALOME's definitions and tools
24// File : Utils_DESTRUCTEUR_GENERIQUE.hxx
25// Author : Antoine YESSAYAN, EDF
26// Module : SALOME
27// $Header$
28//
29# if !defined( __DESTRUCTEUR_GENERIQUE__H__ )
30# define __DESTRUCTEUR_GENERIQUE__H__
31
32#include <SALOMEconfig.h>
33
34#include "SALOME_Utils.hxx"
35
36#include <list>
37#include <cassert>
38#include <omniORB4/CORBA.h>
39#include <iostream>
40//# include "utilities.h"
41
64{
65public :
66 static std::list<DESTRUCTEUR_GENERIQUE_*> *Destructeurs;
67
69 static int Ajout( DESTRUCTEUR_GENERIQUE_ &objet );
70 virtual void operator()( void )=0 ;
71};
72
73
96template <class TYPE> class DESTRUCTEUR_DE_ : public DESTRUCTEUR_GENERIQUE_
97{
98public :
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
102 */
103 DESTRUCTEUR_DE_(TYPE &objet):
104 _PtrObjet( &objet )
105 {
106 assert(DESTRUCTEUR_GENERIQUE_::Ajout( *this ) >= 0) ;
107 }
108
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).
112 */
113 virtual void operator()(void){
114 typedef PortableServer::ServantBase TServant;
115 if(_PtrObjet){
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;
118 /*
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();
124 */
125 }else{
126 //cerr << "DESTRUCTEUR_GENERIQUE_::operator() deleting _PtrObjet" << endl;
127 TYPE* aPtr = static_cast<TYPE*>(_PtrObjet);
128 delete aPtr;
129 }
130 _PtrObjet = NULL ;
131 }
132 }
133
135 assert(!_PtrObjet) ;
136 }
137
138private :
139 TYPE *_PtrObjet ;
140};
141
142
143# endif /* # if !defined( __DESTRUCTEUR_GENERIQUE__H__ ) */
#define UTILS_EXPORT
Definition: SALOME_Utils.hxx:37
Purpose
Definition: Utils_DESTRUCTEUR_GENERIQUE.hxx:97
virtual ~DESTRUCTEUR_DE_()
Definition: Utils_DESTRUCTEUR_GENERIQUE.hxx:134
TYPE * _PtrObjet
Definition: Utils_DESTRUCTEUR_GENERIQUE.hxx:139
DESTRUCTEUR_DE_(TYPE &objet)
Definition: Utils_DESTRUCTEUR_GENERIQUE.hxx:103
virtual void operator()(void)
performs the destruction
Definition: Utils_DESTRUCTEUR_GENERIQUE.hxx:113
Definition
Definition: Utils_DESTRUCTEUR_GENERIQUE.hxx:64
virtual void operator()(void)=0
performs the destruction
static int Ajout(DESTRUCTEUR_GENERIQUE_ &objet)
adds a destruction object to the list of destructions
Definition: Utils_DESTRUCTEUR_GENERIQUE.cxx:147
static std::list< DESTRUCTEUR_GENERIQUE_ * > * Destructeurs
Definition: Utils_DESTRUCTEUR_GENERIQUE.hxx:66
virtual ~DESTRUCTEUR_GENERIQUE_()
virtual destructor
Definition: Utils_DESTRUCTEUR_GENERIQUE.hxx:68