Salome HOME
Improve swig generation process on Windows platform.
[tools/medcoupling.git] / src / INTERP_KERNEL / Bases / InterpKernelAutoPtr.hxx
index e49b4df14c60ffc6d7c99478e943cba6878ffda4..ea984a760b850b371262754b7321ae22b3a388df 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -29,7 +29,9 @@ namespace INTERP_KERNEL
   public:
     AutoPtr(T *ptr=0):_ptr(ptr) {  }
     ~AutoPtr() { destroyPtr(); }
-    AutoPtr &operator=(T *ptr) { destroyPtr(); _ptr=ptr; return *this; }
+    bool isNull() const { return _ptr==0; }
+    bool isNotNull() const { return !isNull(); }
+    AutoPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; }
     T *operator->() { return _ptr ; }
     const T *operator->() const { return _ptr; }
     T& operator*() { return *_ptr; }
@@ -42,13 +44,36 @@ namespace INTERP_KERNEL
     T *_ptr;
   };
 
+  template<class T>
+  class AutoCppPtr
+  {
+  public:
+    AutoCppPtr(T *ptr=0):_ptr(ptr) {  }
+    ~AutoCppPtr() { destroyPtr(); }
+    bool isNull() const { return _ptr==0; }
+    bool isNotNull() const { return !isNull(); }
+    AutoCppPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; }
+    T *operator->() { return _ptr ; }
+    const T *operator->() const { return _ptr; }
+    T& operator*() { return *_ptr; }
+    const T& operator*() const { return *_ptr; }
+    operator T *() { return _ptr; }
+    operator const T *() const { return _ptr; }
+  private:
+    void destroyPtr() { delete _ptr; }
+  private:
+    T *_ptr;
+  };
+
   template<class T>
   class AutoCPtr
   {
   public:
     AutoCPtr(T *ptr=0):_ptr(ptr) {  }
     ~AutoCPtr() { destroyPtr(); }
-    AutoCPtr &operator=(T *ptr) { destroyPtr(); _ptr=ptr; return *this; }
+    bool isNull() const { return _ptr==0; }
+    bool isNotNull() const { return !isNull(); }
+    AutoCPtr &operator=(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; }
     T *operator->() { return _ptr ; }
     const T *operator->() const { return _ptr; }
     T& operator*() { return *_ptr; }