Skip to content

Commit

Permalink
Add noexcept to C++ proxy functions that don't throw (#2560)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Jul 24, 2024
1 parent 963c1d0 commit 8137e04
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 145 deletions.
51 changes: 27 additions & 24 deletions cpp/include/Ice/Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace Ice
* It's also aesthetically pleasing when making invocations: the proxy appears like a pointer to the remote
* object.
*/
const Prx* operator->() const { return &asPrx(); }
const Prx* operator->() const noexcept { return &asPrx(); }

// We don't provide the non-const operator-> because only the assignment operators can modify the proxy.

Expand Down Expand Up @@ -237,7 +237,7 @@ namespace Ice
return ref == self._reference ? self : Prx::_fromReference(std::move(ref));
}

const Prx& asPrx() const { return *static_cast<const Prx*>(this); }
const Prx& asPrx() const noexcept { return *static_cast<const Prx*>(this); }
};

/**
Expand Down Expand Up @@ -536,7 +536,7 @@ namespace Ice
* @return The cached connection for this proxy, or nil if the proxy does not have
* an established connection.
*/
Ice::ConnectionPtr ice_getCachedConnection() const;
Ice::ConnectionPtr ice_getCachedConnection() const noexcept;

/**
* Flushes any pending batched requests for this communicator. The call blocks until the flush is complete.
Expand Down Expand Up @@ -586,7 +586,7 @@ namespace Ice
* Obtains the facet for this proxy.
* @return The facet for this proxy. If the proxy uses the default facet, the return value is the empty string.
*/
const std::string& ice_getFacet() const;
std::string ice_getFacet() const;

/**
* Obtains a proxy that is identical to this proxy, except for the facet.
Expand Down Expand Up @@ -615,100 +615,100 @@ namespace Ice
* Obtains the locator cache timeout of this proxy.
* @return The locator cache timeout value (in seconds).
*/
std::int32_t ice_getLocatorCacheTimeout() const;
std::int32_t ice_getLocatorCacheTimeout() const noexcept;

/**
* Determines whether this proxy caches connections.
* @return True if this proxy caches connections, false otherwise.
*/
bool ice_isConnectionCached() const;
bool ice_isConnectionCached() const noexcept;

/**
* Obtains the endpoint selection policy for this proxy (randomly or ordered).
* @return The endpoint selection policy.
*/
Ice::EndpointSelectionType ice_getEndpointSelection() const;
Ice::EndpointSelectionType ice_getEndpointSelection() const noexcept;

/**
* Determines whether this proxy uses only secure endpoints.
* @return True if this proxy communicates only via secure endpoints, false otherwise.
*/
bool ice_isSecure() const;
bool ice_isSecure() const noexcept;

/**
* Obtains the encoding version used to marshal request parameters.
* @return The encoding version.
*/
Ice::EncodingVersion ice_getEncodingVersion() const;
Ice::EncodingVersion ice_getEncodingVersion() const noexcept;

/**
* Determines whether this proxy prefers secure endpoints.
* @return True if the proxy always attempts to invoke via secure endpoints before it
* attempts to use insecure endpoints, false otherwise.
*/
bool ice_isPreferSecure() const;
bool ice_isPreferSecure() const noexcept;

/**
* Obtains the router for this proxy.
* @return The router for the proxy. If no router is configured for the proxy, the return value
* is nullopt.
*/
std::optional<RouterPrx> ice_getRouter() const;
std::optional<RouterPrx> ice_getRouter() const noexcept;

/**
* Obtains the locator for this proxy.
* @return The locator for this proxy. If no locator is configured, the return value is nullopt.
*/
std::optional<LocatorPrx> ice_getLocator() const;
std::optional<LocatorPrx> ice_getLocator() const noexcept;

/**
* Determines whether this proxy uses collocation optimization.
* @return True if the proxy uses collocation optimization, false otherwise.
*/
bool ice_isCollocationOptimized() const;
bool ice_isCollocationOptimized() const noexcept;

/**
* Obtains the invocation timeout of this proxy.
* @return The invocation timeout value (in milliseconds).
*/
std::int32_t ice_getInvocationTimeout() const;
std::int32_t ice_getInvocationTimeout() const noexcept;

/**
* Determines whether this proxy uses twoway invocations.
* @return True if this proxy uses twoway invocations, false otherwise.
*/
bool ice_isTwoway() const;
bool ice_isTwoway() const noexcept;

/**
* Determines whether this proxy uses oneway invocations.
* @return True if this proxy uses oneway invocations, false otherwise.
*/
bool ice_isOneway() const;
bool ice_isOneway() const noexcept;

/**
* Determines whether this proxy uses batch oneway invocations.
* @return True if this proxy uses batch oneway invocations, false otherwise.
*/
bool ice_isBatchOneway() const;
bool ice_isBatchOneway() const noexcept;

/**
* Determines whether this proxy uses datagram invocations.
* @return True if this proxy uses datagram invocations, false otherwise.
*/
bool ice_isDatagram() const;
bool ice_isDatagram() const noexcept;

/**
* Determines whether this proxy uses batch datagram invocations.
* @return True if this proxy uses batch datagram invocations, false otherwise.
*/
bool ice_isBatchDatagram() const;
bool ice_isBatchDatagram() const noexcept;

/**
* Obtains the compression override setting of this proxy.
* @return The compression override setting. If nullopt is returned, no override is set. Otherwise, true
* if compression is enabled, false otherwise.
*/
std::optional<bool> ice_getCompress() const;
std::optional<bool> ice_getCompress() const noexcept;

/**
* Obtains the connection ID of this proxy.
Expand All @@ -720,7 +720,7 @@ namespace Ice
* Determines whether this proxy is a fixed proxy.
* @return True if this proxy is a fixed proxy, false otherwise.
*/
bool ice_isFixed() const;
bool ice_isFixed() const noexcept;

/**
* Returns the Slice type ID associated with this type.
Expand All @@ -732,7 +732,7 @@ namespace Ice
* Obtains the communicator that created this proxy.
* @return The communicator that created this proxy.
*/
Ice::CommunicatorPtr ice_getCommunicator() const;
Ice::CommunicatorPtr ice_getCommunicator() const noexcept;

/**
* Obtains a stringified version of this proxy.
Expand All @@ -745,8 +745,11 @@ namespace Ice

static ObjectPrx _fromReference(IceInternal::ReferencePtr ref) { return ObjectPrx(std::move(ref)); }

const IceInternal::ReferencePtr& _getReference() const { return _reference; }
const IceInternal::RequestHandlerCachePtr& _getRequestHandlerCache() const { return _requestHandlerCache; }
const IceInternal::ReferencePtr& _getReference() const noexcept { return _reference; }
const IceInternal::RequestHandlerCachePtr& _getRequestHandlerCache() const noexcept
{
return _requestHandlerCache;
}

void _checkTwowayOnly(std::string_view) const;

Expand Down
30 changes: 16 additions & 14 deletions cpp/include/Ice/ProxyFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ namespace Ice
return proxy ? checkedCast<Prx>(proxy->ice_facet(std::move(facet)), context) : std::nullopt;
}

ICE_API bool operator<(const ObjectPrx&, const ObjectPrx&);
ICE_API bool operator==(const ObjectPrx&, const ObjectPrx&);
ICE_API bool operator<(const ObjectPrx&, const ObjectPrx&) noexcept;
ICE_API bool operator==(const ObjectPrx&, const ObjectPrx&) noexcept;

inline bool operator>(const ObjectPrx& lhs, const ObjectPrx& rhs) { return rhs < lhs; }
inline bool operator<=(const ObjectPrx& lhs, const ObjectPrx& rhs) { return !(lhs > rhs); }
inline bool operator>=(const ObjectPrx& lhs, const ObjectPrx& rhs) { return !(lhs < rhs); }
inline bool operator!=(const ObjectPrx& lhs, const ObjectPrx& rhs) { return !(lhs == rhs); }
inline bool operator>(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept { return rhs < lhs; }
inline bool operator<=(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept { return !(lhs > rhs); }
inline bool operator>=(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept { return !(lhs < rhs); }
inline bool operator!=(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept { return !(lhs == rhs); }

ICE_API std::ostream& operator<<(std::ostream&, const ObjectPrx&);

Expand All @@ -190,15 +190,15 @@ namespace Ice
* @param rhs A proxy.
* @return True if the identity in lhs compares less than the identity in rhs, false otherwise.
*/
ICE_API bool proxyIdentityLess(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs);
ICE_API bool proxyIdentityLess(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) noexcept;

/**
* Compares the object identities of two proxies.
* @param lhs A proxy.
* @param rhs A proxy.
* @return True if the identity in lhs compares equal to the identity in rhs, false otherwise.
*/
ICE_API bool proxyIdentityEqual(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs);
ICE_API bool proxyIdentityEqual(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) noexcept;

/**
* Compares the object identities and facets of two proxies.
Expand All @@ -207,7 +207,8 @@ namespace Ice
* @return True if the identity and facet in lhs compare less than the identity and facet
* in rhs, false otherwise.
*/
ICE_API bool proxyIdentityAndFacetLess(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs);
ICE_API bool
proxyIdentityAndFacetLess(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) noexcept;

/**
* Compares the object identities and facets of two proxies.
Expand All @@ -216,7 +217,8 @@ namespace Ice
* @return True if the identity and facet in lhs compare equal to the identity and facet
* in rhs, false otherwise.
*/
ICE_API bool proxyIdentityAndFacetEqual(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs);
ICE_API bool
proxyIdentityAndFacetEqual(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) noexcept;

/**
* A functor that compares the object identities of two proxies. Evaluates true if the identity in lhs
Expand All @@ -226,7 +228,7 @@ namespace Ice

struct ProxyIdentityLess
{
bool operator()(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) const
bool operator()(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) const noexcept
{
return proxyIdentityLess(lhs, rhs);
}
Expand All @@ -239,7 +241,7 @@ namespace Ice
*/
struct ProxyIdentityEqual
{
bool operator()(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) const
bool operator()(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) const noexcept
{
return proxyIdentityEqual(lhs, rhs);
}
Expand All @@ -252,7 +254,7 @@ namespace Ice
*/
struct ProxyIdentityAndFacetLess
{
bool operator()(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) const
bool operator()(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) const noexcept
{
return proxyIdentityAndFacetLess(lhs, rhs);
}
Expand All @@ -265,7 +267,7 @@ namespace Ice
*/
struct ProxyIdentityAndFacetEqual
{
bool operator()(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) const
bool operator()(const std::optional<ObjectPrx>& lhs, const std::optional<ObjectPrx>& rhs) const noexcept
{
return proxyIdentityAndFacetEqual(lhs, rhs);
}
Expand Down
8 changes: 2 additions & 6 deletions cpp/src/Ice/InstrumentationI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "Ice/LocalExceptions.h"
#include "Ice/LoggerUtil.h"
#include "Ice/ObjectAdapter.h"

#include "Ice/VersionFunctions.h"

using namespace std;
Expand All @@ -19,8 +18,6 @@ using namespace IceInternal;
using namespace Ice::Instrumentation;
using namespace IceMX;

#define ICE_OBJECT_PRX Ice::ObjectPrx

namespace
{
int ThreadMetrics::*getThreadStateMetric(ThreadState s)
Expand Down Expand Up @@ -294,11 +291,10 @@ namespace
{
add("parent", &InvocationHelper::getParent);
add("id", &InvocationHelper::getId);

add("operation", &InvocationHelper::getOperation);
add("identity", &InvocationHelper::getIdentity);
add("facet", &InvocationHelper::getProxy, &ICE_OBJECT_PRX::ice_getFacet);
add("encoding", &InvocationHelper::getProxy, &ICE_OBJECT_PRX::ice_getEncodingVersion);
add("facet", &InvocationHelper::getProxy, &Ice::ObjectPrx::ice_getFacet);
add("encoding", &InvocationHelper::getProxy, &Ice::ObjectPrx::ice_getEncodingVersion);
add("mode", &InvocationHelper::getMode);
add("proxy", &InvocationHelper::getProxy);

Expand Down
Loading

0 comments on commit 8137e04

Please sign in to comment.