1 // **********************************************************************
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
8 // **********************************************************************
13 #include <IceUtil/Handle.h>
14 #include <Ice/Config.h>
17 // We include ProxyHandle.h here to make sure that the Ice::ProxyHandle
18 // template is defined before any definition of upCast().
20 // See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25495 for information
21 // on why this is necessary.
23 #include <Ice/ProxyHandle.h>
26 // "Handle" or "smart pointer" template for classes derived from
27 // IceInternal::GCShared, IceUtil::Shared, or IceUtil::SimpleShared.
29 // In constrast to IceUtil::Handle, IceInternal::Handle<T> can be used
30 // for a type T that has been declared but not defined. The only
31 // requirement is a declaration of the following function:
33 // namespace IceInternal
38 // Where X is (or derives from) IceUtil::Shared or IceUtil::SimpleShared.
45 class Handle
: public ::IceUtil::HandleBase
<T
>
49 #if defined(__BCPLUSPLUS__) && (__BCPLUSPLUS__ >= 0x0600)
51 // C++Builder 2009 does not allow setting Ptr to 0.
66 upCast(this->_ptr
)->__incRef();
71 Handle(const Handle
<Y
>& r
)
77 upCast(this->_ptr
)->__incRef();
82 Handle(const ::IceUtil::Handle
<Y
>& r
)
88 upCast(this->_ptr
)->__incRef();
92 Handle(const Handle
& r
)
98 upCast(this->_ptr
)->__incRef();
106 upCast(this->_ptr
)->__decRef();
110 Handle
& operator=(T
* p
)
116 upCast(p
)->__incRef();
124 upCast(ptr
)->__decRef();
131 Handle
& operator=(const Handle
<Y
>& r
)
133 if(this->_ptr
!= r
._ptr
)
137 upCast(r
._ptr
)->__incRef();
145 upCast(ptr
)->__decRef();
152 Handle
& operator=(const ::IceUtil::Handle
<Y
>& r
)
154 if(this->_ptr
!= r
._ptr
)
158 upCast(r
._ptr
)->__incRef();
166 upCast(ptr
)->__decRef();
172 Handle
& operator=(const Handle
& r
)
174 if(this->_ptr
!= r
._ptr
)
178 upCast(r
._ptr
)->__incRef();
186 upCast(ptr
)->__decRef();
193 static Handle
dynamicCast(const ::IceUtil::HandleBase
<Y
>& r
)
195 #ifdef __BCPLUSPLUS__
196 return Handle
<T
>(dynamic_cast<T
*>(r
._ptr
));
198 return Handle(dynamic_cast<T
*>(r
._ptr
));
203 static Handle
dynamicCast(Y
* p
)
205 #ifdef __BCPLUSPLUS__
206 return Handle
<T
>(dynamic_cast<T
*>(p
));
208 return Handle(dynamic_cast<T
*>(p
));
212 void __clearHandleUnsafe()