Salome HOME
Boost of expression evaluator DataArrayDouble::applyFunc* + DataArrayDouble::applyFun...
[modules/med.git] / src / INTERP_KERNEL / Bases / InterpKernelAutoPtr.hxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (CEA/DEN)
20
21 #ifndef __INTERPKERNELAUTOPTR_HXX__
22 #define __INTERPKERNELAUTOPTR_HXX__
23
24 namespace INTERP_KERNEL
25 {
26   template<class T>
27   class AutoPtr
28   {
29   public:
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; }
39   private:
40     void destroyPtr() { delete [] _ptr; }
41   private:
42     T *_ptr;
43   };
44
45   template<class T>
46   class AutoCppPtr
47   {
48   public:
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   private:
59     void destroyPtr() { delete _ptr; }
60   private:
61     T *_ptr;
62   };
63
64   template<class T>
65   class AutoCPtr
66   {
67   public:
68     AutoCPtr(T *ptr=0):_ptr(ptr) {  }
69     ~AutoCPtr() { destroyPtr(); }
70     AutoCPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; }
71     T *operator->() { return _ptr ; }
72     const T *operator->() const { return _ptr; }
73     T& operator*() { return *_ptr; }
74     const T& operator*() const { return *_ptr; }
75     operator T *() { return _ptr; }
76     operator const T *() const { return _ptr; }
77   private:
78     void destroyPtr() { free(_ptr); }
79   private:
80     T *_ptr;
81   };
82 }
83
84 #endif