// ********************************************************************** // // Copyright (c) 2001 // Mutable Realms, Inc. // Huntsville, AL, USA // // All Rights Reserved // // ********************************************************************** #ifndef ICE_PROXY_HANDLE_H #define ICE_PROXY_HANDLE_H #include #include namespace IceInternal { // // Like IceInternal::Handle, but specifically for proxies, with // support for checkedCast() and uncheckedCast() instead of // dynamicCast(). // template class ProxyHandle : public ::IceUtil::HandleBase { public: ProxyHandle(T* p = 0) { _ptr = p; if(_ptr) { incRef(_ptr); } } template ProxyHandle(const ProxyHandle& r) { _ptr = r._ptr; if(_ptr) { incRef(_ptr); } } template ProxyHandle(const ::IceUtil::Handle& r) { _ptr = r._ptr; if(_ptr) { incRef(_ptr); } } #ifdef _WIN32 // COMPILERBUG: Is VC++ or GNU C++ right here??? template<> ProxyHandle(const ProxyHandle& r) #else ProxyHandle(const ProxyHandle& r) #endif { _ptr = r._ptr; 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 ProxyHandle& operator=(const ProxyHandle& r) { if(_ptr != r._ptr) { if(r._ptr) { incRef(r._ptr); } if(_ptr) { decRef(_ptr); } _ptr = r._ptr; } return *this; } template ProxyHandle& operator=(const ::IceUtil::Handle& r) { if(_ptr != r._ptr) { if(r._ptr) { incRef(r._ptr); } if(_ptr) { decRef(_ptr); } _ptr = r._ptr; } return *this; } #ifdef _WIN32 // COMPILERBUG: Is VC++ or GNU C++ right here??? template<> ProxyHandle& operator=(const ProxyHandle& 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 static ProxyHandle checkedCast(const ProxyHandle& r, const std::string& f = "") { ProxyHandle p; ::IceInternal::checkedCast(r, f, p); return p; } template static ProxyHandle uncheckedCast(const ProxyHandle& r, const std::string& f = "") { ProxyHandle p; ::IceInternal::uncheckedCast(r, f, p); return p; } }; } #endif