Ice 3.8
C++ API Reference
Loading...
Searching...
No Matches
ProxyFunctions.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef ICE_PROXY_FUNCTIONS_H
4#define ICE_PROXY_FUNCTIONS_H
5
6#include "Ice/Proxy.h"
7
8namespace IceInternal
9{
10 ICE_API void throwNullProxyMarshalException(const char* file, int line, const Ice::Current& current);
11}
12
13namespace Ice
14{
15 struct Current;
16
17 /// Verifies that a proxy received from the client is not null, and throws a MarshalException if it is.
18 /// @param prx The proxy to check.
19 /// @param file The source file name.
20 /// @param line The source line number.
21 /// @param current The Current object of the incoming request.
22 /// @throw MarshalException If the proxy is null.
23 template<typename Prx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
24 void checkNotNull(const std::optional<Prx>& prx, const char* file, int line, const Current& current)
25 {
26 if (!prx)
27 {
28 // Will be reported back to the client as an UnknownLocalException with an error message.
29 IceInternal::throwNullProxyMarshalException(file, line, current);
30 }
31 }
32
33 /// Creates a new proxy from an existing proxy.
34 /// @param proxy The source proxy.
35 /// @return A new proxy with the requested type.
36 /// @remark This is a purely local operation.
37 template<typename Prx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
38 Prx uncheckedCast(const ObjectPrx& proxy)
39 {
40 return Prx::_fromReference(proxy._getReference());
41 }
42
43 /// Creates a new proxy from an existing proxy.
44 /// @param proxy The source proxy (can be nullopt).
45 /// @return A new proxy with the requested type, or nullopt if the source proxy is nullopt.
46 /// @remark This is a purely local operation.
47 template<typename Prx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
48 std::optional<Prx> uncheckedCast(const std::optional<ObjectPrx>& proxy)
49 {
50 if (proxy)
51 {
52 return uncheckedCast<Prx>(proxy.value());
53 }
54 else
55 {
56 return std::nullopt;
57 }
58 }
59
60 /// Creates a new proxy from an existing proxy.
61 /// @param proxy The source proxy.
62 /// @param facet A facet name.
63 /// @return A new proxy with the requested type and facet.
64 /// @remark This is a purely local operation.
65 template<typename Prx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
66 Prx uncheckedCast(const ObjectPrx& proxy, std::string facet)
67 {
68 return uncheckedCast<Prx>(proxy->ice_facet(std::move(facet)));
69 }
70
71 /// Creates a new proxy from an existing proxy.
72 /// @param proxy The source proxy (can be nullopt).
73 /// @param facet A facet name.
74 /// @return A new proxy with the requested type and facet, or nullopt if the source proxy is nullopt.
75 /// @remark This is a purely local operation.
76 template<typename Prx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
77 std::optional<Prx> uncheckedCast(const std::optional<ObjectPrx>& proxy, std::string facet)
78 {
79 if (proxy)
80 {
81 return uncheckedCast<Prx>(proxy->ice_facet(std::move(facet)));
82 }
83 else
84 {
85 return std::nullopt;
86 }
87 }
88
89 /// Creates a new proxy from an existing proxy after confirming the target object's type via a remote invocation.
90 /// @param proxy The source proxy.
91 /// @param context The request context.
92 /// @return A new proxy with the requested type, or nullopt if the target object does not support the requested
93 /// type.
94 template<typename Prx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
95 std::optional<Prx> checkedCast(const ObjectPrx& proxy, const Context& context = noExplicitContext)
96 {
97 if (proxy->ice_isA(Prx::ice_staticId(), context))
98 {
99 return uncheckedCast<Prx>(proxy);
100 }
101 else
102 {
103 return std::nullopt;
104 }
105 }
106
107 /// Creates a new proxy from an existing proxy after confirming the target object's type via a remote invocation.
108 /// @param proxy The source proxy (can be nullopt).
109 /// @param context The request context.
110 /// @return A new proxy with the requested type, or nullopt if the target object does not support the requested
111 /// type.
112 template<typename Prx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
113 std::optional<Prx> checkedCast(const std::optional<ObjectPrx>& proxy, const Context& context = noExplicitContext)
114 {
115 return proxy ? checkedCast<Prx>(proxy.value(), context) : std::nullopt;
116 }
117
118 /// Creates a new proxy from an existing proxy after confirming the target object's type via a remote invocation.
119 /// @param proxy The source proxy.
120 /// @param facet A facet name.
121 /// @param context The request context.
122 /// @return A new proxy with the requested type and facet, or nullopt if the target facet is not of the requested
123 /// type.
124 template<typename Prx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
125 std::optional<Prx>
126 checkedCast(const ObjectPrx& proxy, std::string facet, const Context& context = noExplicitContext)
127 {
128 return checkedCast<Prx>(proxy->ice_facet(std::move(facet)), context);
129 }
130
131 /// Creates a new proxy from an existing proxy after confirming the target object's type via a remote invocation.
132 /// @param proxy The source proxy (can be nullopt).
133 /// @param facet A facet name.
134 /// @param context The request context.
135 /// @return A new proxy with the requested type and facet, or nullopt if the target facet is not of the requested
136 /// type.
137 template<typename Prx, std::enable_if_t<std::is_base_of_v<ObjectPrx, Prx>, bool> = true>
138 std::optional<Prx>
139 checkedCast(const std::optional<ObjectPrx>& proxy, std::string facet, const Context& context = noExplicitContext)
140 {
141 return proxy ? checkedCast<Prx>(proxy->ice_facet(std::move(facet)), context) : std::nullopt;
142 }
143
144 /// Operator less-than.
145 /// @param lhs The left-hand side proxy.
146 /// @param rhs The right-hand side proxy.
147 /// @return `true` if @p lhs is less than @p rhs, `false` otherwise.
148 ICE_API bool operator<(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept;
149
150 /// Operator equal to.
151 /// @param lhs The left-hand side proxy.
152 /// @param rhs The right-hand side proxy.
153 /// @return `true` if @p lhs is equal to @p rhs, `false` otherwise.
154 ICE_API bool operator==(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept;
155
156 /// Operator greater-than.
157 /// @param lhs The left-hand side proxy.
158 /// @param rhs The right-hand side proxy.
159 /// @return `true` if @p lhs is greater than @p rhs, `false` otherwise.
160 inline bool operator>(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept { return rhs < lhs; }
161
162 /// Operator less-than or equal to.
163 /// @param lhs The left-hand side proxy.
164 /// @param rhs The right-hand side proxy.
165 /// @return `true` if @p lhs is less than or equal to @p rhs, `false` otherwise.
166 inline bool operator<=(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept { return !(lhs > rhs); }
167
168 /// Operator greater-than or equal to.
169 /// @param lhs The left-hand side proxy.
170 /// @param rhs The right-hand side proxy.
171 /// @return `true` if @p lhs is greater than or equal to @p rhs, `false` otherwise.
172 inline bool operator>=(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept { return !(lhs < rhs); }
173
174 /// Operator not equal to.
175 /// @param lhs The left-hand side proxy.
176 /// @param rhs The right-hand side proxy.
177 /// @return `true` if @p lhs is not equal to @p rhs, `false` otherwise.
178 inline bool operator!=(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept { return !(lhs == rhs); }
179
180 /// Compares the object identities of two proxies.
181 /// @param lhs A proxy.
182 /// @param rhs A proxy.
183 /// @return `true` if the identity in lhs compares less than the identity in rhs, `false` otherwise.
184 ICE_API bool proxyIdentityLess(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) noexcept;
185
186 /// Compares the object identities of two proxies.
187 /// @param lhs A proxy.
188 /// @param rhs A proxy.
189 /// @return `true` if the identity in lhs compares equal to the identity in rhs, `false` otherwise.
190 ICE_API bool proxyIdentityEqual(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) noexcept;
191
192 /// Compares the object identities and facets of two proxies.
193 /// @param lhs A proxy.
194 /// @param rhs A proxy.
195 /// @return `true` if the identity and facet in lhs compare less than the identity and facet
196 /// in rhs, `false` otherwise.
197 ICE_API bool
198 proxyIdentityAndFacetLess(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) noexcept;
199
200 /// Compares the object identities and facets of two proxies.
201 /// @param lhs A proxy.
202 /// @param rhs A proxy.
203 /// @return `true` if the identity and facet in lhs compare equal to the identity and facet
204 /// in rhs, `false` otherwise.
205 ICE_API bool
206 proxyIdentityAndFacetEqual(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) noexcept;
207}
208
209#endif
bool ice_isA(std::string_view typeId, const Ice::Context &context=Ice::noExplicitContext) const
Tests whether this object supports a specific Slice interface.
Prx ice_facet(std::string facet) const
Creates a proxy that is identical to this proxy, except for the facet.
Definition Proxy.h:559
The base class for all Ice proxies.
Definition Proxy.h:232
bool proxyIdentityAndFacetEqual(const std::optional< ObjectPrx > &lhs, const std::optional< ObjectPrx > &rhs) noexcept
Compares the object identities and facets of two proxies.
bool proxyIdentityAndFacetLess(const std::optional< ObjectPrx > &lhs, const std::optional< ObjectPrx > &rhs) noexcept
Compares the object identities and facets of two proxies.
const Context noExplicitContext
Marker value used to indicate that no explicit request context was passed to a proxy invocation.
std::optional< Prx > checkedCast(const ObjectPrx &proxy, const Context &context=noExplicitContext)
Creates a new proxy from an existing proxy after confirming the target object's type via a remote inv...
bool operator==(const ObjectPrx &lhs, const ObjectPrx &rhs) noexcept
Operator equal to.
Prx uncheckedCast(const ObjectPrx &proxy)
Creates a new proxy from an existing proxy.
void checkNotNull(const std::optional< Prx > &prx, const char *file, int line, const Current &current)
Verifies that a proxy received from the client is not null, and throws a MarshalException if it is.
bool operator>=(const ObjectPrx &lhs, const ObjectPrx &rhs) noexcept
Operator greater-than or equal to.
bool operator<(const ObjectPrx &lhs, const ObjectPrx &rhs) noexcept
Operator less-than.
bool proxyIdentityLess(const std::optional< ObjectPrx > &lhs, const std::optional< ObjectPrx > &rhs) noexcept
Compares the object identities of two proxies.
bool operator!=(const ObjectPrx &lhs, const ObjectPrx &rhs) noexcept
Operator not equal to.
bool operator<=(const ObjectPrx &lhs, const ObjectPrx &rhs) noexcept
Operator less-than or equal to.
bool proxyIdentityEqual(const std::optional< ObjectPrx > &lhs, const std::optional< ObjectPrx > &rhs) noexcept
Compares the object identities of two proxies.
bool operator>(const ObjectPrx &lhs, const ObjectPrx &rhs) noexcept
Operator greater-than.
std::map< std::string, std::string, std::less<> > Context
Represents additional information carried by an Ice request.
Definition Context.h:28
The Ice RPC framework.
Definition SampleEvent.h:59
Provides information about an incoming request being dispatched.
Definition Current.h:18