1 // Copyright (C) 2012-2016 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 (EDF R&D)
21 #ifndef __YACSEVALYFXAUTOPTR_HXX__
22 #define __YACSEVALYFXAUTOPTR_HXX__
30 AutoPtr(T *ptr=0):_ptr(ptr) { }
31 ~AutoPtr() { destroyPtr(); }
32 AutoPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; }
33 T *operator->() { return _ptr ; }
34 const T *operator->() const { return _ptr; }
35 T& operator*() { return *_ptr; }
36 const T& operator*() const { return *_ptr; }
37 operator T *() { return _ptr; }
38 operator const T *() const { return _ptr; }
40 void destroyPtr() { delete [] _ptr; }
49 AutoCppPtr(T *ptr=0):_ptr(ptr) { }
50 ~AutoCppPtr() { destroyPtr(); }
51 AutoCppPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; }
52 T *operator->() { return _ptr ; }
53 const T *operator->() const { return _ptr; }
54 T& operator*() { return *_ptr; }
55 const T& operator*() const { return *_ptr; }
56 operator T *() { return _ptr; }
57 operator const T *() const { return _ptr; }
58 T *dettach() { T *ret(_ptr); _ptr=0; return ret; }
60 void destroyPtr() { delete _ptr; }
69 AutoCPtr(T *ptr=0):_ptr(ptr) { }
70 ~AutoCPtr() { destroyPtr(); }
71 AutoCPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; }
72 T *operator->() { return _ptr ; }
73 const T *operator->() const { return _ptr; }
74 T& operator*() { return *_ptr; }
75 const T& operator*() const { return *_ptr; }
76 operator T *() { return _ptr; }
77 operator const T *() const { return _ptr; }
79 void destroyPtr() { free(_ptr); }