Ice 3.7 C++11 API Reference
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 
15 namespace IceInternal
16 {
17 
18 template<typename T> class ProxyHandle;
19 template<typename T> class Handle;
20 
21 }
22 
23 namespace IceProxy
24 {
25 namespace Ice
26 {
27 
28 class Object;
29 
30 }
31 }
32 
33 namespace Ice
34 {
35 
37 typedef ::IceInternal::ProxyHandle< ::IceProxy::Ice::Object> ObjectPrx;
38 
39 class ObjectAdapter;
40 typedef ::IceInternal::Handle< ::Ice::ObjectAdapter> ObjectAdapterPtr;
41 
48 typedef ::std::map< ::std::string, ::std::string> Context;
49 
51 ICE_API extern const Context noExplicitContext;
52 
53 }
54 
55 namespace IceInternal
56 {
57 
58 template<typename P> P
59 checkedCastImpl(const ::Ice::ObjectPrx&, const ::Ice::Context&);
60 
61 template<typename P> P
62 checkedCastImpl(const ::Ice::ObjectPrx&, const std::string&, const ::Ice::Context&);
63 
64 template<typename P> P
65 uncheckedCastImpl(const ::Ice::ObjectPrx&);
66 
67 template<typename P> P
68 uncheckedCastImpl(const ::Ice::ObjectPrx&, const std::string&);
69 
70 //
71 // Upcast
72 //
73 template<typename T, typename Y> inline ProxyHandle<T>
74 checkedCastHelper(const ::IceInternal::ProxyHandle<Y>& b, T*, const ::Ice::Context&)
75 {
76  return b;
77 }
78 
79 template<typename T, typename Y> inline ProxyHandle<T>
80 uncheckedCastHelper(const ::IceInternal::ProxyHandle<Y>& b, T*)
81 {
82  return b;
83 }
84 
85 //
86 // Downcast
87 //
88 template<typename T, typename Y> inline ProxyHandle<T>
89 checkedCastHelper(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 
102 template<typename T, typename Y> inline ProxyHandle<T>
103 uncheckedCastHelper(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 //
121 template<typename T>
122 class ProxyHandle : public ::IceUtil::HandleBase<T>
123 {
124 public:
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,
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 
308 template<class Y>
309 std::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
IceUtil::Shared::__decRef
virtual void __decRef()
Ice::Context
::std::map<::std::string, ::std::string > Context
A request context.
Definition: Current.h:68
Ice::operator<<
std::ostream & operator<<(std::ostream &out, const ProtocolVersion &version)
Definition: Protocol.h:179
Handle.h
ICE_API
#define ICE_API
Definition: Config.h:197
IceUtil::HandleBase
Definition: Handle.h:20
Config.h
Ice
Definition: BuiltinSequences.h:56
IceUtil::Shared::__incRef
virtual void __incRef()
Ice::checkedCast
::std::shared_ptr< P > checkedCast(const ::std::shared_ptr< T > &b, const ::Ice::Context &context=Ice::noExplicitContext)
Downcasts a proxy after confirming the target object's type via a remote invocation.
Definition: Proxy.h:1596
Ice::uncheckedCast
::std::shared_ptr< P > uncheckedCast(const ::std::shared_ptr< T > &b)
Downcasts a proxy without confirming the target object's type via a remote invocation.
Definition: Proxy.h:1549
Ice::noExplicitContext
const Context noExplicitContext
Marker value used to indicate that no explicit context was passed to a proxy invocation.