From 8cddd264e57ab89fc4c6952b2b390457a4bfbedf Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 7 Sep 2018 18:47:28 +0200 Subject: Fixes for C++17 mode Close #180 --- cpp/src/Ice/ConnectionFactory.cpp | 98 ++++++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 11 deletions(-) (limited to 'cpp/src/Ice/ConnectionFactory.cpp') diff --git a/cpp/src/Ice/ConnectionFactory.cpp b/cpp/src/Ice/ConnectionFactory.cpp index 744e261e3cd..cc81ec65f12 100644 --- a/cpp/src/Ice/ConnectionFactory.cpp +++ b/cpp/src/Ice/ConnectionFactory.cpp @@ -53,14 +53,6 @@ IceUtil::Shared* IceInternal::upCast(IncomingConnectionFactory* p) { return p; } namespace { -struct RandomNumberGenerator : public std::unary_function -{ - ptrdiff_t operator()(ptrdiff_t d) - { - return IceUtilInternal::random(static_cast(d)); - } -}; - #ifdef ICE_CPP11_MAPPING template void remove(Map& m, const typename Map::key_type& k, const typename Map::mapped_type& v) @@ -178,10 +170,16 @@ IceInternal::OutgoingConnectionFactory::destroy() return; } +#ifdef ICE_CPP11_COMPILER + for(const auto& p : _connections) + { + p.second->destroy(ConnectionI::CommunicatorDestroyed); + } +#else for_each(_connections.begin(), _connections.end(), bind2nd(Ice::secondVoidMemFun1 (&ConnectionI::destroy), ConnectionI::CommunicatorDestroyed)); - +#endif _destroyed = true; _communicator = 0; @@ -192,8 +190,15 @@ void IceInternal::OutgoingConnectionFactory::updateConnectionObservers() { IceUtil::Monitor::Lock sync(*this); +#ifdef ICE_CPP11_COMPILER + for(const auto& p : _connections) + { + p.second->updateObserver(); + } +#else for_each(_connections.begin(), _connections.end(), Ice::secondVoidMemFun(&ConnectionI::updateObserver)); +#endif } void @@ -221,9 +226,15 @@ IceInternal::OutgoingConnectionFactory::waitUntilFinished() connections = _connections; } +#ifdef ICE_CPP11_COMPILER + for(const auto& p : _connections) + { + p.second->waitUntilFinished(); + } +#else for_each(connections.begin(), connections.end(), Ice::secondVoidMemFun(&ConnectionI::waitUntilFinished)); - +#endif { IceUtil::Monitor::Lock sync(*this); // Ensure all the connections are finished and reapable at this point. @@ -436,7 +447,15 @@ IceInternal::OutgoingConnectionFactory::findConnection(const vector::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) { +#ifdef ICE_CPP11_MAPPING + auto connection = find(_connectionsByEndpoint, *p, + [](const ConnectionIPtr& conn) + { + return conn->isActiveOrHolding(); + }); +#else ConnectionIPtr connection = find(_connectionsByEndpoint, *p, Ice::constMemFun(&ConnectionI::isActiveOrHolding)); +#endif if(connection) { if(defaultsAndOverrides->overrideCompress) @@ -466,7 +485,15 @@ IceInternal::OutgoingConnectionFactory::findConnection(const vectorconnector, + [](const ConnectionIPtr& conn) + { + return conn->isActiveOrHolding(); + }); +#else ConnectionIPtr connection = find(_connections, p->connector, Ice::constMemFun(&ConnectionI::isActiveOrHolding)); +#endif if(connection) { if(defaultsAndOverrides->overrideCompress) @@ -1193,7 +1220,14 @@ void IceInternal::IncomingConnectionFactory::updateConnectionObservers() { IceUtil::Monitor::Lock sync(*this); +#ifdef ICE_CPP11_COMPILER + for(const auto& conn : _connections) + { + conn->updateObserver(); + } +#else for_each(_connections.begin(), _connections.end(), Ice::voidMemFun(&ConnectionI::updateObserver)); +#endif } void @@ -1223,7 +1257,14 @@ IceInternal::IncomingConnectionFactory::waitUntilHolding() const // // Now we wait until each connection is in holding state. // +#ifdef ICE_CPP11_COMPILER + for(const auto& conn : connections) + { + conn->waitUntilHolding(); + } +#else for_each(connections.begin(), connections.end(), Ice::constVoidMemFun(&ConnectionI::waitUntilHolding)); +#endif } void @@ -1253,7 +1294,14 @@ IceInternal::IncomingConnectionFactory::waitUntilFinished() connections = _connections; } +#ifdef ICE_CPP11_COMPILER + for(const auto& conn : connections) + { + conn->waitUntilFinished(); + } +#else for_each(connections.begin(), connections.end(), Ice::voidMemFun(&ConnectionI::waitUntilFinished)); +#endif { IceUtil::Monitor::Lock sync(*this); @@ -1311,9 +1359,16 @@ IceInternal::IncomingConnectionFactory::connections() const // // Only copy connections which have not been destroyed. // +#ifdef ICE_CPP11_COMPILER + remove_copy_if(_connections.begin(), _connections.end(), back_inserter(result), + [](const ConnectionIPtr& conn) + { + return !conn->isActiveOrHolding(); + }); +#else remove_copy_if(_connections.begin(), _connections.end(), back_inserter(result), not1(Ice::constMemFun(&ConnectionI::isActiveOrHolding))); - +#endif return result; } @@ -1737,7 +1792,14 @@ IceInternal::IncomingConnectionFactory::setState(State state) } _adapter->getThreadPool()->_register(ICE_SHARED_FROM_THIS, SocketOperationRead); } +#ifdef ICE_CPP11_COMPILER + for(const auto& conn : _connections) + { + conn->activate(); + } +#else for_each(_connections.begin(), _connections.end(), Ice::voidMemFun(&ConnectionI::activate)); +#endif break; } @@ -1756,7 +1818,14 @@ IceInternal::IncomingConnectionFactory::setState(State state) } _adapter->getThreadPool()->unregister(ICE_SHARED_FROM_THIS, SocketOperationRead); } +#ifdef ICE_CPP11_COMPILER + for(const auto& conn : _connections) + { + conn->hold(); + } +#else for_each(_connections.begin(), _connections.end(), Ice::voidMemFun(&ConnectionI::hold)); +#endif break; } @@ -1781,8 +1850,15 @@ IceInternal::IncomingConnectionFactory::setState(State state) state = StateFinished; } +#ifdef ICE_CPP11_COMPILER + for(const auto& conn : _connections) + { + conn->destroy(ConnectionI::ObjectAdapterDeactivated); + } +#else for_each(_connections.begin(), _connections.end(), bind2nd(Ice::voidMemFun1(&ConnectionI::destroy), ConnectionI::ObjectAdapterDeactivated)); +#endif break; } -- cgit v1.2.3