diff options
author | Marc Laukien <marc@zeroc.com> | 2001-06-17 01:04:03 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2001-06-17 01:04:03 +0000 |
commit | 6de01ee326dc82808ccbfbf41931da342f86acfd (patch) | |
tree | 67db470c6cf6c4ce2c49289d0223a4c9583d9c54 /cpp/include | |
parent | fixes (diff) | |
download | ice-6de01ee326dc82808ccbfbf41931da342f86acfd.tar.bz2 ice-6de01ee326dc82808ccbfbf41931da342f86acfd.tar.xz ice-6de01ee326dc82808ccbfbf41931da342f86acfd.zip |
many handle and other fixes
Diffstat (limited to 'cpp/include')
-rw-r--r-- | cpp/include/Ice/Handle.h | 81 | ||||
-rw-r--r-- | cpp/include/Ice/Proxy.h | 2 | ||||
-rw-r--r-- | cpp/include/Ice/ProxyF.h | 9 | ||||
-rw-r--r-- | cpp/include/Ice/ProxyHandle.h | 150 |
4 files changed, 195 insertions, 47 deletions
diff --git a/cpp/include/Ice/Handle.h b/cpp/include/Ice/Handle.h index 80373a47020..be337b38dcc 100644 --- a/cpp/include/Ice/Handle.h +++ b/cpp/include/Ice/Handle.h @@ -32,6 +32,8 @@ public: typedef T element_type; +// Handle() : ptr_(0) { } + Handle(T* p = 0) : ptr_(p) { @@ -39,7 +41,20 @@ public: incRef(ptr_); } + template<typename Y> + Handle(const Handle<Y>& r) + : ptr_(r.ptr_) + { + if(ptr_) + incRef(ptr_); + } + +#ifdef WIN32 // COMPILERBUG: Is VC++ or GNU C++ right here??? + template<> + Handle(const Handle<T>& r) +#else Handle(const Handle& r) +#endif : ptr_(r.ptr_) { if(ptr_) @@ -56,75 +71,81 @@ public: { if(ptr_ != p) { + if(p) + incRef(p); + if(ptr_) decRef(ptr_); ptr_ = p; - - if(ptr_) - incRef(ptr_); } return *this; } - Handle& operator=(const Handle& r) + template<typename Y> + Handle& operator=(const Handle<Y>& r) { if(ptr_ != r.ptr_) { + if(r.ptr_) + incRef(r.ptr_); + if(ptr_) decRef(ptr_); ptr_ = r.ptr_; - - if(ptr_) - incRef(ptr_); } return *this; } - -// -// Some compilers (like Visual C++ 6.0) do not support member -// templates :-( I therefore don't use them, otherwise Ice code could -// be non-portable. -// -/* - template<typename Y> - Handle(const Handle<Y>& r) - : ptr_(r.ptr_) - { - if(ptr_) - incRef(ptr_); - } - template<typename Y> - Handle& operator=(const Handle<Y>& r) +#ifdef WIN32 // COMPILERBUG: Is VC++ or GNU C++ right here??? + template<> + Handle& operator=(const Handle<T>& r) +#else + Handle& operator=(const Handle& r) +#endif { if(ptr_ != r.ptr_) { + if(r.ptr_) + incRef(r.ptr_); + if(ptr_) decRef(ptr_); ptr_ = r.ptr_; - - if(ptr_) - incRef(ptr_); } return *this; } + + template<class Y> + static Handle dynamicCast(const Handle<Y>& r) + { + return Handle(dynamic_cast<T*>(r.ptr_)); + } - template<typename Y> friend class Handle; -*/ + template<class Y> + static Handle dynamicCast(Y* p) + { + return Handle(dynamic_cast<T*>(p)); + } T* get() const { return ptr_; } T& operator*() const { return *ptr_; } T* operator->() const { return ptr_; } - operator T*() const { return ptr_; } + operator bool() const { return ptr_ ? true : false; } + + void swap(Handle& other) { std::swap(ptr_, other.ptr_); } - void swap(Handle<T>& other) { std::swap(ptr_, other.ptr_); } +#ifndef WIN32 // COMPILERBUG: VC++ 6.0 doesn't understand this + + template<typename Y> friend class Handle; protected: +#endif + T* ptr_; }; diff --git a/cpp/include/Ice/Proxy.h b/cpp/include/Ice/Proxy.h index 568c056e34b..8d3872498a5 100644 --- a/cpp/include/Ice/Proxy.h +++ b/cpp/include/Ice/Proxy.h @@ -45,7 +45,7 @@ public: ::Ice::Object_prx _timeout(int) const; ::__Ice::Reference_ptr __reference() const; - void __copyTo(Object*) const; + void __copyTo(::__IceProxy::Ice::Object*) const; protected: diff --git a/cpp/include/Ice/ProxyF.h b/cpp/include/Ice/ProxyF.h index 28bfcdab804..dfa04893d1d 100644 --- a/cpp/include/Ice/ProxyF.h +++ b/cpp/include/Ice/ProxyF.h @@ -11,7 +11,7 @@ #ifndef ICE_PROXY_F_H #define ICE_PROXY_F_H -#include <Ice/Handle.h> +#include <Ice/ProxyHandle.h> namespace __IceProxy { namespace Ice { class Object; } } namespace __IceDelegate { namespace Ice { class Object; } } @@ -29,12 +29,17 @@ void ICE_API decRef(::__IceDelegate::Ice::Object*); void ICE_API incRef(::__IceDelegateM::Ice::Object*); void ICE_API decRef(::__IceDelegateM::Ice::Object*); +void ICE_API checkedCast(::__IceProxy::Ice::Object*, + ::__IceProxy::Ice::Object*&); +void ICE_API uncheckedCast(::__IceProxy::Ice::Object*, + ::__IceProxy::Ice::Object*&); + } namespace Ice { -typedef __Ice::Handle< ::__IceProxy::Ice::Object> Object_prx; +typedef __Ice::ProxyHandle< ::__IceProxy::Ice::Object> Object_prx; } diff --git a/cpp/include/Ice/ProxyHandle.h b/cpp/include/Ice/ProxyHandle.h index f9bf8d61c7c..0ed202ade8a 100644 --- a/cpp/include/Ice/ProxyHandle.h +++ b/cpp/include/Ice/ProxyHandle.h @@ -11,40 +11,162 @@ #ifndef ICE_PROXY_HANDLE_H #define ICE_PROXY_HANDLE_H -#include <Ice/Proxy.h> +#include <Ice/Config.h> +#include <algorithm> namespace __Ice { +// +// Like Handle<>, but specifically for proxies, with support for +// checkedCast() and uncheckedCast(). +// template<typename T> -class ProxyHandle : public Handle<T> +class ProxyHandle { public: - ProxyHandle(T* p = 0) : Handle<T>(p) { } - ProxyHandle(const ProxyHandle& r) : Handle<T>(r) { } + typedef T element_type; + +// ProxyHandle() : ptr_(0) { } - ProxyHandle& operator=(const ProxyHandle& r) + ProxyHandle(T* p = 0) + : ptr_(p) + { + if(ptr_) + incRef(ptr_); + } + + template<typename Y> + ProxyHandle(const ProxyHandle<Y>& r) + : ptr_(r.ptr_) + { + if(ptr_) + incRef(ptr_); + } + +#ifdef WIN32 // COMPILERBUG: Is VC++ or GNU C++ right here??? + template<> + ProxyHandle(const ProxyHandle<T>& r) +#else + ProxyHandle(const ProxyHandle& r) +#endif + : ptr_(r.ptr_) { - Handle<T>::operator=(r); + if(ptr_) + incRef(ptr_); + } + + ~ProxyHandle() + { + if(ptr_) + decRef(ptr_); + } + + ProxyHandle& operator=(T* p) + { + if(ptr_ != p) + { + if(p) + incRef(p); + + if(ptr_) + decRef(ptr_); + + ptr_ = p; + } return *this; } + + template<typename Y> + ProxyHandle& operator=(const ProxyHandle<Y>& r) + { + if(ptr_ != r.ptr_) + { + if(r.ptr_) + incRef(r.ptr_); - static ProxyHandle<T> checkedCast(::__IceProxy::Ice::Object* from) + if(ptr_) + decRef(ptr_); + + ptr_ = r.ptr_; + } + return *this; + } + +#ifdef WIN32 // COMPILERBUG: Is VC++ or GNU C++ right here??? + template<> + ProxyHandle& operator=(const ProxyHandle<T>& r) +#else + ProxyHandle& operator=(const ProxyHandle& r) +#endif + { + if(ptr_ != r.ptr_) + { + if(r.ptr_) + incRef(r.ptr_); + + if(ptr_) + decRef(ptr_); + + ptr_ = r.ptr_; + } + return *this; + } + + template<class Y> + static ProxyHandle checkedCast(const ProxyHandle<Y>& r) { - T* to; - ::__Ice::checkedCast(from, to); - return ProxyHandle<T>(to); + T* p; + ::__Ice::checkedCast(r.ptr_, p); + return ProxyHandle(p); } - static ProxyHandle<T> uncheckedCast(::__IceProxy::Ice::Object* from) + template<class Y> + static ProxyHandle uncheckedCast(const ProxyHandle<Y>& r) { - T* to; - ::__Ice::uncheckedCast(from, to); - return ProxyHandle<T>(to); + T* p; + ::__Ice::checkedCast(r.ptr_, p); + return ProxyHandle(p); } + + T* get() const { return ptr_; } + + T& operator*() 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> +inline bool operator==(const ProxyHandle<T>& a, const ProxyHandle<U>& b) +{ + return *a.get() == *b.get(); +} + +template<typename T, typename U> +inline bool operator!=(const ProxyHandle<T>& a, const ProxyHandle<U>& b) +{ + return *a.get() != *b.get(); +} + +template<typename T, typename U> +inline bool operator<(const ProxyHandle<T>& a, const ProxyHandle<U>& b) +{ + return *a.get() < *b.get(); +} + } #endif |