Cosmetic rename SwigMovePointer -> SwigSmartPointer

This smart pointer doesn't really offer move semantics as is commonly
understood in C++11, so rename accordingly.
This commit is contained in:
William S Fulton 2022-06-16 07:47:44 +01:00
commit 4dd285fad7

View file

@ -653,8 +653,8 @@ namespace std {
* arg1 = Vector(1,2,3); // Assignment from a value
*
* The class offers a strong guarantee of exception safety.
* With regards to the implementation, the private SwigMovePointer nested class is
* a simple smart pointer with move semantics, much like std::auto_ptr.
* With regards to the implementation, the private SwigSmartPointer nested class is
* a simple smart pointer providing exception safety, much like std::auto_ptr.
*
* This wrapping technique was suggested by William Fulton and is henceforth
* known as the "Fulton Transform" :-).
@ -666,19 +666,19 @@ namespace std {
#include <utility>
/* SwigValueWrapper is described in swig.swg */
template<typename T> class SwigValueWrapper {
struct SwigMovePointer {
struct SwigSmartPointer {
T *ptr;
SwigMovePointer(T *p) : ptr(p) { }
~SwigMovePointer() { delete ptr; }
SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; }
SwigSmartPointer(T *p) : ptr(p) { }
~SwigSmartPointer() { delete ptr; }
SwigSmartPointer& operator=(SwigSmartPointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; }
} pointer;
SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs);
SwigValueWrapper(const SwigValueWrapper<T>& rhs);
public:
SwigValueWrapper() : pointer(0) { }
SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; }
SwigValueWrapper& operator=(const T& t) { SwigSmartPointer tmp(new T(t)); pointer = tmp; return *this; }
#if __cplusplus >= 201103L
SwigValueWrapper& operator=(T&& t) { SwigMovePointer tmp(new T(std::move(t))); pointer = tmp; return *this; }
SwigValueWrapper& operator=(T&& t) { SwigSmartPointer tmp(new T(std::move(t))); pointer = tmp; return *this; }
#endif
operator T&() const { return *pointer.ptr; }
T *operator&() { return pointer.ptr; }