// ********************************************************************** // // Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved. // // This copy of Ice is licensed to you under the terms described in the // ICE_LICENSE file included in this distribution. // // ********************************************************************** #ifndef ICE_PROXY_HANDLE_H #define ICE_PROXY_HANDLE_H #include #include namespace IceInternal { template class ProxyHandle; template class Handle; } namespace IceProxy { namespace Ice { class Object; } } namespace Ice { typedef ::IceInternal::ProxyHandle< ::IceProxy::Ice::Object> ObjectPrx; class ObjectAdapter; typedef ::IceInternal::Handle< ::Ice::ObjectAdapter> ObjectAdapterPtr; typedef ::std::map< ::std::string, ::std::string> Context; } namespace IceInternal { template P checkedCastImpl(const ::Ice::ObjectPrx&); template P checkedCastImpl(const ::Ice::ObjectPrx&, const std::string&); template P checkedCastImpl(const ::Ice::ObjectPrx&, const ::Ice::Context&); template P checkedCastImpl(const ::Ice::ObjectPrx&, const std::string&, const ::Ice::Context&); template P uncheckedCastImpl(const ::Ice::ObjectPrx&); template P uncheckedCastImpl(const ::Ice::ObjectPrx&, const std::string&); // // Upcast // template inline ProxyHandle checkedCastHelper(const ::IceInternal::ProxyHandle& b, T*) { return b; } template inline ProxyHandle checkedCastHelper(const ::IceInternal::ProxyHandle& b, T*, const ::Ice::Context&) { return b; } template inline ProxyHandle uncheckedCastHelper(const ::IceInternal::ProxyHandle& b, T*) { return b; } // // Downcast // template inline ProxyHandle checkedCastHelper(const ::IceInternal::ProxyHandle& b, void*) { return checkedCastImpl >(b); } template inline ProxyHandle checkedCastHelper(const ::IceInternal::ProxyHandle& b, const ::Ice::Context& ctx) { return checkedCastImpl >(b, ctx); } template inline ProxyHandle checkedCastHelper(const ::IceInternal::ProxyHandle& b, void*, const ::Ice::Context& ctx) { return checkedCastImpl >(b, ctx); } template inline ProxyHandle uncheckedCastHelper(const ::IceInternal::ProxyHandle& b, void*) { return uncheckedCastImpl >(b); } // // 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) { this->_ptr = p; if(this->_ptr) { incRef(this->_ptr); } } template ProxyHandle(const ProxyHandle& r) { this->_ptr = r._ptr; if(this->_ptr) { incRef(this->_ptr); } } template ProxyHandle(const ::IceUtil::Handle& r) { this->_ptr = r._ptr; if(this->_ptr) { incRef(this->_ptr); } } #ifdef _WIN32 // COMPILERBUG: Is VC++ or GNU C++ right here??? template<> ProxyHandle(const ProxyHandle& r) #else ProxyHandle(const ProxyHandle& r) #endif { this->_ptr = r._ptr; if(this->_ptr) { incRef(this->_ptr); } } ~ProxyHandle() { if(this->_ptr) { decRef(this->_ptr); } } ProxyHandle& operator=(T* p) { if(this->_ptr != p) { if(p) { incRef(p); } if(this->_ptr) { decRef(this->_ptr); } this->_ptr = p; } return *this; } template ProxyHandle& operator=(const ProxyHandle& r) { if(this->_ptr != r._ptr) { if(r._ptr) { incRef(r._ptr); } if(this->_ptr) { decRef(this->_ptr); } this->_ptr = r._ptr; } return *this; } template ProxyHandle& operator=(const ::IceUtil::Handle& r) { if(this->_ptr != r._ptr) { if(r._ptr) { incRef(r._ptr); } if(this->_ptr) { decRef(this->_ptr); } this->_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(this->_ptr != r._ptr) { if(r._ptr) { incRef(r._ptr); } if(this->_ptr) { decRef(this->_ptr); } this->_ptr = r._ptr; } return *this; } template static ProxyHandle checkedCast(const ProxyHandle& r) { Y* tag = 0; return ::IceInternal::checkedCastHelper(r, tag); } template static ProxyHandle checkedCast(const ProxyHandle& r, const std::string& f) { return ::IceInternal::checkedCastImpl(r, f); } template static ProxyHandle checkedCast(const ProxyHandle& r, const ::Ice::Context& ctx) { return ::IceInternal::checkedCastHelper(r, ctx); } template static ProxyHandle checkedCast(const ProxyHandle& r, const std::string& f, const ::Ice::Context& ctx) { return ::IceInternal::checkedCastImpl(r, f, ctx); } template static ProxyHandle uncheckedCast(const ProxyHandle& r) { Y* tag = 0; return::IceInternal::uncheckedCastHelper(r, tag); } template static ProxyHandle uncheckedCast(const ProxyHandle& r, const std::string& f) { return ::IceInternal::uncheckedCastImpl(r, f); } }; } #endif