1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #ifndef __INTERPKERNELAUTOPTR_HXX__
22 #define __INTERPKERNELAUTOPTR_HXX__
24 namespace INTERP_KERNEL
30 AutoPtr(T *ptr=0):_ptr(ptr) { }
31 ~AutoPtr() { destroyPtr(); }
32 bool isNull() const { return _ptr==0; }
33 bool isNotNull() const { return !isNull(); }
34 AutoPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; }
35 T *operator->() { return _ptr ; }
36 const T *operator->() const { return _ptr; }
37 T& operator*() { return *_ptr; }
38 const T& operator*() const { return *_ptr; }
39 operator T *() { return _ptr; }
40 operator const T *() const { return _ptr; }
42 void destroyPtr() { delete [] _ptr; }
51 AutoCppPtr(T *ptr=0):_ptr(ptr) { }
52 ~AutoCppPtr() { destroyPtr(); }
53 bool isNull() const { return _ptr==0; }
54 bool isNotNull() const { return !isNull(); }
55 AutoCppPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; }
56 T *operator->() { return _ptr ; }
57 const T *operator->() const { return _ptr; }
58 T& operator*() { return *_ptr; }
59 const T& operator*() const { return *_ptr; }
60 operator T *() { return _ptr; }
61 operator const T *() const { return _ptr; }
63 void destroyPtr() { delete _ptr; }
72 AutoCPtr(T *ptr=0):_ptr(ptr) { }
73 ~AutoCPtr() { destroyPtr(); }
74 bool isNull() const { return _ptr==0; }
75 bool isNotNull() const { return !isNull(); }
76 AutoCPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; }
77 T *operator->() { return _ptr ; }
78 const T *operator->() const { return _ptr; }
79 T& operator*() { return *_ptr; }
80 const T& operator*() const { return *_ptr; }
81 operator T *() { return _ptr; }
82 operator const T *() const { return _ptr; }
84 void destroyPtr() { free(_ptr); }