diff options
Diffstat (limited to 'cpp/include/Ice/ProxyHandle.h')
-rw-r--r-- | cpp/include/Ice/ProxyHandle.h | 90 |
1 files changed, 63 insertions, 27 deletions
diff --git a/cpp/include/Ice/ProxyHandle.h b/cpp/include/Ice/ProxyHandle.h index eb0880a01fb..ea428e7c7e8 100644 --- a/cpp/include/Ice/ProxyHandle.h +++ b/cpp/include/Ice/ProxyHandle.h @@ -11,8 +11,8 @@ #ifndef ICE_PROXY_HANDLE_H #define ICE_PROXY_HANDLE_H +#include <IceUtil/Handle.h> #include <Ice/Config.h> -#include <algorithm> namespace IceInternal { @@ -23,23 +23,40 @@ namespace IceInternal // dynamicCast(). // template<typename T> -class ProxyHandle +class ProxyHandle : public ::IceUtil::HandleBase<T> { public: ProxyHandle(T* p = 0) - : _ptr(p) { + _ptr = p; + if (_ptr) + { incRef(_ptr); + } } template<typename Y> ProxyHandle(const ProxyHandle<Y>& r) - : _ptr(r._ptr) { + _ptr = r._ptr; + + if (_ptr) + { + incRef(_ptr); + } + } + + template<typename Y> + ProxyHandle(const ::IceUtil::Handle<Y>& r) + { + _ptr = r._ptr; + if (_ptr) + { incRef(_ptr); + } } #ifdef WIN32 // COMPILERBUG: Is VC++ or GNU C++ right here??? @@ -48,16 +65,21 @@ public: #else ProxyHandle(const ProxyHandle& r) #endif - : _ptr(r._ptr) { + _ptr = r._ptr; + if (_ptr) + { incRef(_ptr); + } } ~ProxyHandle() { if (_ptr) + { decRef(_ptr); + } } ProxyHandle& operator=(T* p) @@ -65,10 +87,14 @@ public: if (_ptr != p) { if (p) + { incRef(p); + } if (_ptr) + { decRef(_ptr); + } _ptr = p; } @@ -81,10 +107,34 @@ public: if (_ptr != r._ptr) { if (r._ptr) + { incRef(r._ptr); + } if (_ptr) + { decRef(_ptr); + } + + _ptr = r._ptr; + } + return *this; + } + + template<typename Y> + ProxyHandle& operator=(const ::IceUtil::Handle<Y>& r) + { + if (_ptr != r._ptr) + { + if (r._ptr) + { + incRef(r._ptr); + } + + if (_ptr) + { + decRef(_ptr); + } _ptr = r._ptr; } @@ -101,10 +151,14 @@ public: if (_ptr != r._ptr) { if (r._ptr) + { incRef(r._ptr); + } if (_ptr) + { decRef(_ptr); + } _ptr = r._ptr; } @@ -112,38 +166,20 @@ public: } template<class Y> - static ProxyHandle checkedCast(const ProxyHandle<Y>& r) + static ProxyHandle checkedCast(const ProxyHandle<Y>& r, const std::string& f = "") { T* p; - ::IceInternal::checkedCast(r._ptr, p); + ::IceInternal::checkedCast(r._ptr, f, p); return ProxyHandle(p); } template<class Y> - static ProxyHandle uncheckedCast(const ProxyHandle<Y>& r) + static ProxyHandle uncheckedCast(const ProxyHandle<Y>& r, const std::string& f = "") { T* p; - ::IceInternal::uncheckedCast(r._ptr, p); + ::IceInternal::uncheckedCast(r._ptr, f, p); return ProxyHandle(p); } - - typedef T element_type; - - T* get() const { return _ptr; } - T* operator->() const { return _ptr; } - operator bool() const { return _ptr ? true : false; } - - void swap(ProxyHandle& other) { std::swap(_ptr, other._ptr); } - -#ifndef WIN32 // COMPILERBUG: VC++ 6.0 doesn't understand this - - template<typename Y> friend class ProxyHandle; - -protected: - -#endif - - T* _ptr; }; template<typename T, typename U> |