Version: 9.12.0
BasicsGenericDestructor.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2023 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 Basics : general SALOME definitions and tools (C++ part - no CORBA)
24 // File : BasicGenericDestructor.hxx
25 // Author : Antoine YESSAYAN, Paul RASCLE, EDF
26 // Module : SALOME
27 // $Header$
28 //
29 #ifndef _BASICGENERICDESTRUCTOR_HXX_
30 #define _BASICGENERICDESTRUCTOR_HXX_
31 
32 #include "SALOME_Basics.hxx"
33 
34 #include <list>
35 #include <algorithm>
36 #include <cassert>
37 #include <typeinfo>
38 #include <iostream>
39 #include <cstdlib>
40 #include <pthread.h>
41 
42 //#define _DEVDEBUG_
43 
44 #ifdef _DEVDEBUG_
45 #define MYDEVTRACE {std::cerr << __FILE__ << " [" << __LINE__ << "] : ";}
46 #define DEVTRACE(msg) {MYDEVTRACE; std::cerr<<msg<<std::endl<<std::flush;}
47 #else
48 #define MYDEVTRACE
49 #define DEVTRACE(msg)
50 #endif
51 
52 #ifdef WIN32
53 #pragma warning(disable:4251) // Warning DLL Interface ...
54 #endif
55 
56 // ============================================================================
72 // ============================================================================
73 
75 {
76 public:
77  static void deleteInstance(PROTECTED_DELETE *anObject);
78  static void addObj(PROTECTED_DELETE *anObject);
79 
80 protected:
81  virtual ~PROTECTED_DELETE();
82  static std::list<PROTECTED_DELETE*> _objList;
83 
84 private:
85  static pthread_mutex_t _listMutex;
86 };
87 
88 // ============================================================================
104 // ============================================================================
105 
107 {
108 public :
109  static std::list<GENERIC_DESTRUCTOR*> *Destructors;
110 
111  virtual ~GENERIC_DESTRUCTOR() {};
112  static int Add(GENERIC_DESTRUCTOR &anObject);
113  virtual void operator()(void) = 0;
114 };
115 
116 // ============================================================================
133 // ============================================================================
134 
135 template <class TYPE> class DESTRUCTOR_OF : public GENERIC_DESTRUCTOR
136 {
137 public:
143  DESTRUCTOR_OF(TYPE &anObject):
144  _objectPtr(&anObject)
145  {
146  DEVTRACE(" DESTRUCTOR_OF " << typeid(anObject).name()
147  << " " << _objectPtr << " " << this );
149  assert(GENERIC_DESTRUCTOR::Add(*this) >= 0);
150  }
151 
157  virtual void operator()(void)
158  {
159  if (_objectPtr)
160  {
161  DEVTRACE("DESTRUCTOR_OF<>::operator() " << _objectPtr);
163  _objectPtr = NULL;
164  }
165  }
166 
167  virtual ~DESTRUCTOR_OF()
168  {
169  DEVTRACE("~DESTRUCTOR_OF() " << this);
170  assert(!_objectPtr);
171  }
172 
173 private:
174  TYPE *_objectPtr;
175 };
176 
177 # endif
#define DEVTRACE(msg)
Definition: BasicsGenericDestructor.hxx:49
#define BASICS_EXPORT
Definition: SALOME_Basics.hxx:37
The DESTRUCTOR_OF class allows the user to program - at any moment - the destruction of an object at ...
Definition: BasicsGenericDestructor.hxx:136
virtual ~DESTRUCTOR_OF()
Definition: BasicsGenericDestructor.hxx:167
TYPE * _objectPtr
Definition: BasicsGenericDestructor.hxx:174
DESTRUCTOR_OF(TYPE &anObject)
Programs the destruction at the end of the process, of the object anObject.
Definition: BasicsGenericDestructor.hxx:143
virtual void operator()(void)
Performs the destruction of the object.
Definition: BasicsGenericDestructor.hxx:157
The GENERIC_DESTRUCTOR abstract class describes the comportement of any destruction object.
Definition: BasicsGenericDestructor.hxx:107
virtual void operator()(void)=0
virtual ~GENERIC_DESTRUCTOR()
Definition: BasicsGenericDestructor.hxx:111
static std::list< GENERIC_DESTRUCTOR * > * Destructors
Definition: BasicsGenericDestructor.hxx:109
static int Add(GENERIC_DESTRUCTOR &anObject)
Adds a destruction object to the list of actions to be performed at the end of the process.
Definition: BasicsGenericDestructor.cxx:188
The PROTECTED_DELETE base class provides a protected destructor.
Definition: BasicsGenericDestructor.hxx:75
static void addObj(PROTECTED_DELETE *anObject)
To allow a further destruction of a PRTECTED_DELETE object, it must be added to the static list of PR...
Definition: BasicsGenericDestructor.cxx:82
static pthread_mutex_t _listMutex
Definition: BasicsGenericDestructor.hxx:85
static void deleteInstance(PROTECTED_DELETE *anObject)
deleteInstance deletes only once the object.
Definition: BasicsGenericDestructor.cxx:56
static std::list< PROTECTED_DELETE * > _objList
Definition: BasicsGenericDestructor.hxx:82
string name
Definition: pythfilter.py:56