-// 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
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; }
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; }