Ice 3.7 C++98 API Reference
Loading...
Searching...
No Matches
ProxyHandle.h
Go to the documentation of this file.
1//
2// Copyright (c) ZeroC, Inc. All rights reserved.
3//
4
5#ifndef ICE_PROXY_HANDLE_H
6#define ICE_PROXY_HANDLE_H
7
8#ifndef ICE_CPP11_MAPPING // C++98 mapping
9
10#include <IceUtil/Handle.h>
11#include <Ice/Config.h>
12
13#include <iosfwd>
14
15namespace IceInternal
16{
17
18template<typename T> class ProxyHandle;
19template<typename T> class Handle;
20
21}
22
23namespace IceProxy
24{
25namespace Ice
26{
27
28class Object;
29
30}
31}
32
33namespace Ice
34{
35
37typedef ::IceInternal::ProxyHandle< ::IceProxy::Ice::Object> ObjectPrx;
38
39class ObjectAdapter;
40typedef ::IceInternal::Handle< ::Ice::ObjectAdapter> ObjectAdapterPtr;
41
48typedef ::std::map< ::std::string, ::std::string> Context;
49
52
53}
54
55namespace IceInternal
56{
57
58template<typename P> P
59checkedCastImpl(const ::Ice::ObjectPrx&, const ::Ice::Context&);
60
61template<typename P> P
62checkedCastImpl(const ::Ice::ObjectPrx&, const std::string&, const ::Ice::Context&);
63
64template<typename P> P
65uncheckedCastImpl(const ::Ice::ObjectPrx&);
66
67template<typename P> P
68uncheckedCastImpl(const ::Ice::ObjectPrx&, const std::string&);
69
70//
71// Upcast
72//
73template<typename T, typename Y> inline ProxyHandle<T>
74checkedCastHelper(const ::IceInternal::ProxyHandle<Y>& b, T*, const ::Ice::Context&)
75{
76 return b;
77}
78
79template<typename T, typename Y> inline ProxyHandle<T>
80uncheckedCastHelper(const ::IceInternal::ProxyHandle<Y>& b, T*)
81{
82 return b;
83}
84
85//
86// Downcast
87//
88template<typename T, typename Y> inline ProxyHandle<T>
89checkedCastHelper(const ::IceInternal::ProxyHandle<Y>& b, void*, const ::Ice::Context& ctx)
90{
91#ifdef __SUNPRO_CC
92 //
93 // Sun CC bug introduced in version 5.10
94 //
95 const ::Ice::ObjectPrx& o = b;
96 return checkedCastImpl<ProxyHandle<T> >(o, ctx);
97#else
98 return checkedCastImpl<ProxyHandle<T> >(b, ctx);
99#endif
100}
101
102template<typename T, typename Y> inline ProxyHandle<T>
103uncheckedCastHelper(const ::IceInternal::ProxyHandle<Y>& b, void*)
104{
105#ifdef __SUNPRO_CC
106 //
107 // Sun CC bug introduced in version 5.10
108 //
109 const ::Ice::ObjectPrx& o = b;
110 return uncheckedCastImpl<ProxyHandle<T> >(o);
111#else
112 return uncheckedCastImpl<ProxyHandle<T> >(b);
113#endif
114}
115
116//
117// Like IceInternal::Handle, but specifically for proxies, with
118// support for checkedCast() and uncheckedCast() instead of
119// dynamicCast().
120//
121template<typename T>
122class ProxyHandle : public ::IceUtil::HandleBase<T>
123{
124public:
125
126 ProxyHandle(T* p = 0)
127 {
128 this->_ptr = p;
129
130 if(this->_ptr)
131 {
132 upCast(this->_ptr)->__incRef();
133 }
134 }
135
136 template<typename Y>
137 ProxyHandle(const ProxyHandle<Y>& r)
138 {
139 this->_ptr = r._ptr;
140
141 if(this->_ptr)
142 {
143 upCast(this->_ptr)->__incRef();
144 }
145 }
146
147 template<typename Y>
148 ProxyHandle(const ::IceUtil::Handle<Y>& r)
149 {
150 this->_ptr = r._ptr;
151
152 if(this->_ptr)
153 {
154 upCast(this->_ptr)->__incRef();
155 }
156 }
157
158 ProxyHandle(const ProxyHandle& r)
159 {
160 this->_ptr = r._ptr;
161
162 if(this->_ptr)
163 {
164 upCast(this->_ptr)->__incRef();
165 }
166 }
167
168 ~ProxyHandle()
169 {
170 if(this->_ptr)
171 {
172 upCast(this->_ptr)->__decRef();
173 }
174 }
175
176 ProxyHandle& operator=(T* p)
177 {
178 if(this->_ptr != p)
179 {
180 if(p)
181 {
182 upCast(p)->__incRef();
183 }
184
185 if(this->_ptr)
186 {
187 upCast(this->_ptr)->__decRef();
188 }
189
190 this->_ptr = p;
191 }
192 return *this;
193 }
194
195 template<typename Y>
196 ProxyHandle& operator=(const ProxyHandle<Y>& r)
197 {
198 if(this->_ptr != r._ptr)
199 {
200 if(r._ptr)
201 {
202 upCast(r._ptr)->__incRef();
203 }
204
205 if(this->_ptr)
206 {
207 upCast(this->_ptr)->__decRef();
208 }
209
210 this->_ptr = r._ptr;
211 }
212 return *this;
213 }
214
215 template<typename Y>
216 ProxyHandle& operator=(const ::IceUtil::Handle<Y>& r)
217 {
218 if(this->_ptr != r._ptr)
219 {
220 if(r._ptr)
221 {
222 upCast(r._ptr)->__incRef();
223 }
224
225 if(this->_ptr)
226 {
227 upCast(this->_ptr)->__decRef();
228 }
229
230 this->_ptr = r._ptr;
231 }
232 return *this;
233 }
234
235 ProxyHandle& operator=(const ProxyHandle& r)
236 {
237 if(this->_ptr != r._ptr)
238 {
239 if(r._ptr)
240 {
241 upCast(r._ptr)->__incRef();
242 }
243
244 if(this->_ptr)
245 {
246 upCast(this->_ptr)->__decRef();
247 }
248
249 this->_ptr = r._ptr;
250 }
251 return *this;
252 }
253
254 ::IceProxy::Ice::Object* _upCast() const
255 {
256 return upCast(this->_ptr);
257 }
258
259 template<class Y>
260 static ProxyHandle checkedCast(const ProxyHandle<Y>& r, const ::Ice::Context& ctx = ::Ice::noExplicitContext)
261 {
262 Y* tag = 0;
263 return ::IceInternal::checkedCastHelper<T>(r, tag, ctx);
264 }
265
266 template<class Y>
267 static ProxyHandle checkedCast(const ProxyHandle<Y>& r, const std::string& f,
268 const ::Ice::Context& ctx = ::Ice::noExplicitContext)
269 {
270#ifdef __SUNPRO_CC
271 //
272 // Sun CC bug introduced in version 5.10
273 //
274 const ::Ice::ObjectPrx& o = r;
275 return ::IceInternal::checkedCastImpl<ProxyHandle>(o, f, ctx);
276#else
277 return ::IceInternal::checkedCastImpl<ProxyHandle>(r, f, ctx);
278#endif
279 }
280
281 template<class Y>
282 static ProxyHandle uncheckedCast(const ProxyHandle<Y>& r)
283 {
284 Y* tag = 0;
285 return::IceInternal::uncheckedCastHelper<T>(r, tag);
286 }
287
288 template<class Y>
289 static ProxyHandle uncheckedCast(const ProxyHandle<Y>& r, const std::string& f)
290 {
291#ifdef __SUNPRO_CC
292 //
293 // Sun CC bug introduced in version 5.10
294 //
295 const ::Ice::ObjectPrx& o = r;
296 return ::IceInternal::uncheckedCastImpl<ProxyHandle<T> >(o, f);
297#else
298 return ::IceInternal::uncheckedCastImpl<ProxyHandle>(r, f);
299#endif
300 }
301
302 static const std::string& ice_staticId()
303 {
304 return T::ice_staticId();
305 }
306};
307
308template<class Y>
309std::ostream& operator<<(std::ostream& os, ::IceInternal::ProxyHandle<Y> p)
310{
311 return os << (p ? p->ice_toString() : std::string(""));
312}
313
314}
315
316#endif
317
318#endif
#define ICE_API
Definition Config.h:197
Base class of all object proxies.
Definition Proxy.h:1757
T * _ptr
Definition Handle.h:74
virtual void __decRef()
virtual void __incRef()
The object adapter provides an up-call interface from the Ice run time to the implementation of Ice o...
Definition ObjectAdapter.h:651
Definition Locator.h:1000
Definition Metrics.h:211
Definition BuiltinSequences.h:113
const Context noExplicitContext
Marker value used to indicate that no explicit context was passed to a proxy invocation.
Definition ProxyHandle.h:51
::std::map< ::std::string, ::std::string > Context
A request context.
Definition Current.h:207
IceInternal::ProxyHandle< ::IceProxy::Ice::Object > ObjectPrx
Smart pointer for an object proxy.
Definition ProxyF.h:47
::IceInternal::Handle< ObjectAdapter > ObjectAdapterPtr
Definition ObjectAdapter.h:620
IceUtil::Shared * upCast(::Ice::AsyncResult *)