// ********************************************************************** // // Copyright (c) 2003-2016 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 #ifndef ICE_CPP11_MAPPING // C++98 mapping #include #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; ICE_API extern const Context noExplicitContext; } namespace IceInternal { 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*, 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*, const ::Ice::Context& ctx) { #ifdef __SUNPRO_CC // // Sun CC bug introduced in version 5.10 // const ::Ice::ObjectPrx& o = b; return checkedCastImpl >(o, ctx); #else return checkedCastImpl >(b, ctx); #endif } template inline ProxyHandle uncheckedCastHelper(const ::IceInternal::ProxyHandle& b, void*) { #ifdef __SUNPRO_CC // // Sun CC bug introduced in version 5.10 // const ::Ice::ObjectPrx& o = b; return uncheckedCastImpl >(o); #else return uncheckedCastImpl >(b); #endif } // // 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) { upCast(this->_ptr)->__incRef(); } } template ProxyHandle(const ProxyHandle& r) { this->_ptr = r._ptr; if(this->_ptr) { upCast(this->_ptr)->__incRef(); } } template ProxyHandle(const ::IceUtil::Handle& r) { this->_ptr = r._ptr; if(this->_ptr) { upCast(this->_ptr)->__incRef(); } } ProxyHandle(const ProxyHandle& r) { this->_ptr = r._ptr; if(this->_ptr) { upCast(this->_ptr)->__incRef(); } } ~ProxyHandle() { if(this->_ptr) { upCast(this->_ptr)->__decRef(); } } ProxyHandle& operator=(T* p) { if(this->_ptr != p) { if(p) { upCast(p)->__incRef(); } if(this->_ptr) { upCast(this->_ptr)->__decRef(); } this->_ptr = p; } return *this; } template ProxyHandle& operator=(const ProxyHandle& r) { if(this->_ptr != r._ptr) { if(r._ptr) { upCast(r._ptr)->__incRef(); } if(this->_ptr) { upCast(this->_ptr)->__decRef(); } this->_ptr = r._ptr; } return *this; } template ProxyHandle& operator=(const ::IceUtil::Handle& r) { if(this->_ptr != r._ptr) { if(r._ptr) { upCast(r._ptr)->__incRef(); } if(this->_ptr) { upCast(this->_ptr)->__decRef(); } this->_ptr = r._ptr; } return *this; } ProxyHandle& operator=(const ProxyHandle& r) { if(this->_ptr != r._ptr) { if(r._ptr) { upCast(r._ptr)->__incRef(); } if(this->_ptr) { upCast(this->_ptr)->__decRef(); } this->_ptr = r._ptr; } return *this; } ::IceProxy::Ice::Object* _upCast() const { return upCast(this->_ptr); } template static ProxyHandle checkedCast(const ProxyHandle& r, const ::Ice::Context& ctx = ::Ice::noExplicitContext) { Y* tag = 0; return ::IceInternal::checkedCastHelper(r, tag, ctx); } template static ProxyHandle checkedCast(const ProxyHandle& r, const std::string& f, const ::Ice::Context& ctx = ::Ice::noExplicitContext) { #ifdef __SUNPRO_CC // // Sun CC bug introduced in version 5.10 // const ::Ice::ObjectPrx& o = r; return ::IceInternal::checkedCastImpl(o, f, ctx); #else return ::IceInternal::checkedCastImpl(r, f, ctx); #endif } 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) { #ifdef __SUNPRO_CC // // Sun CC bug introduced in version 5.10 // const ::Ice::ObjectPrx& o = r; return ::IceInternal::uncheckedCastImpl >(o, f); #else return ::IceInternal::uncheckedCastImpl(r, f); #endif } static const std::string& ice_staticId() { return T::ice_staticId(); } }; template std::ostream& operator<<(std::ostream& os, ::IceInternal::ProxyHandle p) { return os << (p ? p->ice_toString() : std::string("")); } } #endif #endif