Skip to content

Commit

Permalink
Merge branch 'main' into csharp-property-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
externl authored Oct 7, 2024
2 parents 83d8372 + dfbdfb3 commit e690357
Show file tree
Hide file tree
Showing 33 changed files with 516 additions and 647 deletions.
162 changes: 93 additions & 69 deletions cpp/include/Ice/Comparable.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#ifndef ICE_COMPARABLE_H
#define ICE_COMPARABLE_H

#include <functional>
#include <tuple>
#include <type_traits>

namespace Ice
{
Expand Down Expand Up @@ -113,80 +114,103 @@ namespace Ice
}
};

//
// Relational operators for generated structs and classes
//

/**
* Relational operator for generated structs and classes.
* @param lhs The left-hand side.
* @param rhs The right-hand side.
* @return True if the left-hand side compares less than the right-hand side, false otherwise.
*/
template<class C, typename = std::enable_if<std::is_member_function_pointer<decltype(&C::ice_tuple)>::value>>
bool operator<(const C& lhs, const C& rhs)
namespace Tuple
{
return lhs.ice_tuple() < rhs.ice_tuple();
}
/**
* Relational operator for generated structs.
* @param lhs The left-hand side.
* @param rhs The right-hand side.
* @return True if the left-hand side compares less than the right-hand side, false otherwise.
*/
template<
class C,
std::enable_if_t<
std::is_member_function_pointer<decltype(&C::ice_tuple)>::value && !std::is_polymorphic_v<C>,
bool> = true>
bool operator<(const C& lhs, const C& rhs)
{
return lhs.ice_tuple() < rhs.ice_tuple();
}

/**
* Relational operator for generated structs and classes.
* @param lhs The left-hand side.
* @param rhs The right-hand side.
* @return True if the left-hand side compares less than or equal to the right-hand side, false otherwise.
*/
template<class C, typename = std::enable_if<std::is_member_function_pointer<decltype(&C::ice_tuple)>::value>>
bool operator<=(const C& lhs, const C& rhs)
{
return lhs.ice_tuple() <= rhs.ice_tuple();
}
/**
* Relational operator for generated structs.
* @param lhs The left-hand side.
* @param rhs The right-hand side.
* @return True if the left-hand side compares less than or equal to the right-hand side, false otherwise.
*/
template<
class C,
std::enable_if_t<
std::is_member_function_pointer<decltype(&C::ice_tuple)>::value && !std::is_polymorphic_v<C>,
bool> = true>
bool operator<=(const C& lhs, const C& rhs)
{
return lhs.ice_tuple() <= rhs.ice_tuple();
}

/**
* Relational operator for generated structs and classes.
* @param lhs The left-hand side.
* @param rhs The right-hand side.
* @return True if the left-hand side compares greater than the right-hand side, false otherwise.
*/
template<class C, typename = std::enable_if<std::is_member_function_pointer<decltype(&C::ice_tuple)>::value>>
bool operator>(const C& lhs, const C& rhs)
{
return lhs.ice_tuple() > rhs.ice_tuple();
}
/**
* Relational operator for generated structs.
* @param lhs The left-hand side.
* @param rhs The right-hand side.
* @return True if the left-hand side compares greater than the right-hand side, false otherwise.
*/
template<
class C,
std::enable_if_t<
std::is_member_function_pointer<decltype(&C::ice_tuple)>::value && !std::is_polymorphic_v<C>,
bool> = true>
bool operator>(const C& lhs, const C& rhs)
{
return lhs.ice_tuple() > rhs.ice_tuple();
}

/**
* Relational operator for generated structs and classes.
* @param lhs The left-hand side.
* @param rhs The right-hand side.
* @return True if the left-hand side compares greater than or equal to the right-hand side, false otherwise.
*/
template<class C, typename = std::enable_if<std::is_member_function_pointer<decltype(&C::ice_tuple)>::value>>
bool operator>=(const C& lhs, const C& rhs)
{
return lhs.ice_tuple() >= rhs.ice_tuple();
}
/**
* Relational operator for generated structs.
* @param lhs The left-hand side.
* @param rhs The right-hand side.
* @return True if the left-hand side compares greater than or equal to the right-hand side, false otherwise.
*/
template<
class C,
std::enable_if_t<
std::is_member_function_pointer<decltype(&C::ice_tuple)>::value && !std::is_polymorphic_v<C>,
bool> = true>
bool operator>=(const C& lhs, const C& rhs)
{
return lhs.ice_tuple() >= rhs.ice_tuple();
}

/**
* Relational operator for generated structs and classes.
* @param lhs The left-hand side.
* @param rhs The right-hand side.
* @return True if the left-hand side compares equal to the right-hand side, false otherwise.
*/
template<class C, typename = std::enable_if<std::is_member_function_pointer<decltype(&C::ice_tuple)>::value>>
bool operator==(const C& lhs, const C& rhs)
{
return lhs.ice_tuple() == rhs.ice_tuple();
}
/**
* Relational operator for generated structs.
* @param lhs The left-hand side.
* @param rhs The right-hand side.
* @return True if the left-hand side compares equal to the right-hand side, false otherwise.
*/
template<
class C,
std::enable_if_t<
std::is_member_function_pointer<decltype(&C::ice_tuple)>::value && !std::is_polymorphic_v<C>,
bool> = true>
bool operator==(const C& lhs, const C& rhs)
{
return lhs.ice_tuple() == rhs.ice_tuple();
}

/**
* Relational operator for generated structs and classes.
* @param lhs The left-hand side.
* @param rhs The right-hand side.
* @return True if the left-hand side is not equal to the right-hand side, false otherwise.
*/
template<class C, typename = std::enable_if<std::is_member_function_pointer<decltype(&C::ice_tuple)>::value>>
bool operator!=(const C& lhs, const C& rhs)
{
return lhs.ice_tuple() != rhs.ice_tuple();
/**
* Relational operator for generated structs.
* @param lhs The left-hand side.
* @param rhs The right-hand side.
* @return True if the left-hand side is not equal to the right-hand side, false otherwise.
*/
template<
class C,
std::enable_if_t<
std::is_member_function_pointer<decltype(&C::ice_tuple)>::value && !std::is_polymorphic_v<C>,
bool> = true>
bool operator!=(const C& lhs, const C& rhs)
{
return lhs.ice_tuple() != rhs.ice_tuple();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions cpp/include/Ice/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ObjectF.h"
#include "OutgoingResponse.h"

#include <functional>
#include <string_view>

namespace Ice
Expand Down
1 change: 1 addition & 0 deletions cpp/include/Ice/Proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "RequestHandlerF.h"

#include <chrono>
#include <functional>
#include <future>
#include <iosfwd>
#include <optional>
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/Ice/ProxyFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ namespace Ice
return proxy ? checkedCast<Prx>(proxy->ice_facet(std::move(facet)), context) : std::nullopt;
}

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

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); }
Expand Down
17 changes: 2 additions & 15 deletions cpp/include/Ice/StreamHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,11 @@ namespace Ice
//

/**
* General reader. slice2cpp generates specializations as needed.
* Reader used/generated for structs. Always specialized.
* \headerfile Ice/Ice.h
*/
template<typename T> struct StreamReader
{
static void read(InputStream*, T&)
{
// Default is to read nothing
}
};

/**
* General writer. slice2cpp generates specializations as needed.
* \headerfile Ice/Ice.h
*/
template<typename T> struct StreamWriter
{
static void write(OutputStream* stream, const T& v) { stream->writeAll(v.ice_tuple()); }
};

/**
Expand All @@ -96,7 +83,7 @@ namespace Ice
*/
template<typename T> struct StreamHelper<T, StreamHelperCategoryStruct>
{
static void write(OutputStream* stream, const T& v) { StreamWriter<T>::write(stream, v); }
static void write(OutputStream* stream, const T& v) { stream->writeAll(v.ice_tuple()); }

static void read(InputStream* stream, T& v) { StreamReader<T>::read(stream, v); }
};
Expand Down
1 change: 1 addition & 0 deletions cpp/src/Ice/BatchRequestQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Ice/OutputStream.h"

#include <condition_variable>
#include <functional>
#include <mutex>

namespace IceInternal
Expand Down
112 changes: 2 additions & 110 deletions cpp/src/Ice/Proxy.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
// Copyright (c) ZeroC, Inc.

#include "Ice/Proxy.h"
#include "CheckIdentity.h"
#include "ConnectionI.h"
#include "EndpointI.h"
#include "Ice/Communicator.h"
#include "Ice/Comparable.h"
#include "Ice/Current.h"
#include "Ice/Initialize.h"
#include "Ice/LocalExceptions.h"
#include "Ice/ObjectAdapter.h"
#include "Instance.h"
#include "LocatorInfo.h"
#include "Reference.h"
#include "ReferenceFactory.h"
#include "RequestHandlerCache.h"
#include "RouterInfo.h"

#include <sstream>
#include <stdexcept>

using namespace std;
Expand Down Expand Up @@ -580,105 +574,3 @@ Ice::ObjectPrx::_twoway() const
return _reference->changeMode(Reference::ModeTwoway);
}
}

// TODO: move the code below to ProxyFunctions.cpp

void
IceInternal::throwNullProxyMarshalException(const char* file, int line, const Current& current)
{
ostringstream os;
os << "null proxy passed to " << current.operation << " on object "
<< current.adapter->getCommunicator()->identityToString(current.id);
throw MarshalException{file, line, os.str()};
}

namespace Ice
{
bool operator<(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept
{
return targetLess(lhs._getReference(), rhs._getReference());
}

bool operator==(const ObjectPrx& lhs, const ObjectPrx& rhs) noexcept
{
return targetEqualTo(lhs._getReference(), rhs._getReference());
}
}

bool
Ice::proxyIdentityLess(const optional<ObjectPrx>& lhs, const optional<ObjectPrx>& rhs) noexcept
{
return lhs && rhs ? lhs->ice_getIdentity() < rhs->ice_getIdentity()
: std::less<bool>()(static_cast<bool>(lhs), static_cast<bool>(rhs));
}

bool
Ice::proxyIdentityEqual(const optional<ObjectPrx>& lhs, const optional<ObjectPrx>& rhs) noexcept
{
return lhs && rhs ? lhs->ice_getIdentity() == rhs->ice_getIdentity()
: std::equal_to<bool>()(static_cast<bool>(lhs), static_cast<bool>(rhs));
}

bool
Ice::proxyIdentityAndFacetLess(const optional<ObjectPrx>& lhs, const optional<ObjectPrx>& rhs) noexcept
{
if (lhs && rhs)
{
Identity lhsIdentity = lhs->ice_getIdentity();
Identity rhsIdentity = rhs->ice_getIdentity();

if (lhsIdentity < rhsIdentity)
{
return true;
}
else if (rhsIdentity < lhsIdentity)
{
return false;
}

string lhsFacet = lhs->ice_getFacet();
string rhsFacet = rhs->ice_getFacet();

if (lhsFacet < rhsFacet)
{
return true;
}
else if (rhsFacet < lhsFacet)
{
return false;
}

return false;
}
else
{
return std::less<bool>()(static_cast<bool>(lhs), static_cast<bool>(rhs));
}
}

bool
Ice::proxyIdentityAndFacetEqual(const optional<ObjectPrx>& lhs, const optional<ObjectPrx>& rhs) noexcept
{
if (lhs && rhs)
{
Identity lhsIdentity = lhs->ice_getIdentity();
Identity rhsIdentity = rhs->ice_getIdentity();

if (lhsIdentity == rhsIdentity)
{
string lhsFacet = lhs->ice_getFacet();
string rhsFacet = rhs->ice_getFacet();

if (lhsFacet == rhsFacet)
{
return true;
}
}

return false;
}
else
{
return std::equal_to<bool>()(static_cast<bool>(lhs), static_cast<bool>(rhs));
}
}
Loading

0 comments on commit e690357

Please sign in to comment.