diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2008-12-28 18:41:16 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2008-12-28 18:41:16 +0000 |
commit | b190c10bf290f99ee6b8b7400aec59e580b29494 (patch) | |
tree | ed430fa2296c87a445f7c0713b102fa0d8ddd6f0 /Lib/swig.swg | |
parent | 8ed7554802dcca93de72fdc35bfbbf825ded2fa8 (diff) | |
download | swig-b190c10bf290f99ee6b8b7400aec59e580b29494.tar.gz |
add strong exception guarantee to SwigValueWrapper
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11006 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Lib/swig.swg')
-rw-r--r-- | Lib/swig.swg | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/Lib/swig.swg b/Lib/swig.swg index 0c7bcd4c1..8e14ccfbb 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -633,6 +633,10 @@ namespace std { * arg1 = *inarg1; // Assignment from a pointer * 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 Pointer nested class is + * a simple smart pointer with move semantics, much like std::auto_ptr. + * * This wrapping technique was suggested by William Fulton and is henceforth * known as the "Fulton Transform" :-). */ @@ -640,18 +644,22 @@ namespace std { #ifdef __cplusplus %insert("runtime") %{ #ifdef __cplusplus +/* SwigValueWrapper is described in swig.swg */ template<typename T> class SwigValueWrapper { - T *tt; + struct Pointer { + T *ptr; + Pointer(T *p) : ptr(p) { } + ~Pointer() { delete ptr; } + Pointer& operator=(Pointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; } + } pointer; + SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs); public: - SwigValueWrapper() : tt(0) { } - SwigValueWrapper(const SwigValueWrapper<T>& rhs) : tt(new T(*rhs.tt)) { } - SwigValueWrapper(const T& t) : tt(new T(t)) { } - ~SwigValueWrapper() { delete tt; } - SwigValueWrapper& operator=(const T& t) { T *oldtt = tt; tt = 0; delete oldtt; tt = new T(t); return *this; } - operator T&() const { return *tt; } - T *operator&() { return tt; } -private: - SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs); + SwigValueWrapper() : pointer(0) { } + SwigValueWrapper(const SwigValueWrapper<T>& rhs) : pointer(new T(*rhs.pointer.ptr)) { } + SwigValueWrapper(const T& t) : pointer(new T(t)) { } + SwigValueWrapper& operator=(const T& t) { Pointer tmp(new T(t)); pointer = tmp; return *this; } + operator T&() const { return *pointer.ptr; } + T *operator&() { return pointer.ptr; } };%} /* |