Skip to content

Commit

Permalink
C++17 support (VS2022)
Browse files Browse the repository at this point in the history
  • Loading branch information
willamowius committed Nov 22, 2023
2 parents 7f7236a + 34a3cbe commit 7d1fa75
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 91 deletions.
12 changes: 12 additions & 0 deletions GkClient.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@
#include <ptclib/pdns.h>
#endif

#include <functional>

using std::vector;
using std::multimap;
using std::make_pair;
using std::for_each;
#if (__cplusplus < 201703L) // before C++17
using std::mem_fun;
using std::bind1st;
#endif
using Routing::Route;

namespace {
Expand Down Expand Up @@ -2503,7 +2507,11 @@ void GkClient::Unregister()
m_natClient->Stop();
m_natClient = NULL;
}
#if (__cplusplus >= 201703L) // C++17
for_each(m_handlers, m_handlers + 4, std::bind(std::mem_fn(&RasServer::UnregisterHandler), m_rasSrv, std::placeholders::_1));
#else
for_each(m_handlers, m_handlers + 4, bind1st(mem_fun(&RasServer::UnregisterHandler), m_rasSrv));
#endif
m_registered = false;
}

Expand Down Expand Up @@ -2758,7 +2766,11 @@ void GkClient::OnRCF(RasMsg *ras)
if (m_useAdditiveRegistration)
RegistrationTable::Instance()->UpdateTable();

#if (__cplusplus >= 201703L) // C++17
for_each(m_handlers, m_handlers + 4, bind(std::mem_fn(&RasServer::RegisterHandler), m_rasSrv, std::placeholders::_1));
#else
for_each(m_handlers, m_handlers + 4, bind1st(mem_fun(&RasServer::RegisterHandler), m_rasSrv));
#endif
}

// Not all RCF contain TTL, in that case keep old value
Expand Down
41 changes: 40 additions & 1 deletion Neighbor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
using std::multimap;
using std::make_pair;
using std::find_if;
#if (__cplusplus < 201703L) // before C++17
using std::mem_fun;
using std::bind2nd;
#endif
using std::equal_to;
using std::mem_fun;
using Routing::Route;

namespace Neighbors {
Expand Down Expand Up @@ -1719,8 +1721,13 @@ void NeighborList::OnReload()
type = "ClarentGK";
if (PCaselessString(type) == "GlonetGK")
type = "GlonetGK";
#if (__cplusplus >= 201703L) // C++17
iter = find_if(m_neighbors.begin(), m_neighbors.end(),
compose1(bind(equal_to<PString>(), std::placeholders::_1, nbid), mem_fn(&Neighbor::GetId)));
#else
iter = find_if(m_neighbors.begin(), m_neighbors.end(),
compose1(bind2nd(equal_to<PString>(), nbid), mem_fun(&Neighbor::GetId)));
#endif
bool newnb = (iter == m_neighbors.end());
Neighbor *nb = newnb ? Factory<Neighbor>::Create(type) : *iter;
if (nb && nb->SetProfile(nbid, type, !newnb)) {
Expand Down Expand Up @@ -1749,24 +1756,40 @@ bool NeighborList::CheckLRQ(RasMsg *ras) const

bool NeighborList::CheckIP(const PIPSocket::Address & addr) const
{
#if (__cplusplus >= 201703L) // C++17
return find_if(m_neighbors.begin(), m_neighbors.end(), bind(mem_fn(&Neighbor::IsFrom), std::placeholders::_1, &addr)) != m_neighbors.end();
#else
return find_if(m_neighbors.begin(), m_neighbors.end(), bind2nd(mem_fun(&Neighbor::IsFrom), &addr)) != m_neighbors.end();
#endif
}

bool NeighborList::IsTraversalClient(const PIPSocket::Address & addr) const
{
#if (__cplusplus >= 201703L) // C++17
return find_if(m_neighbors.begin(), m_neighbors.end(), bind(mem_fn(&Neighbor::IsTraversalClient), std::placeholders::_1, &addr)) != m_neighbors.end();
#else
return find_if(m_neighbors.begin(), m_neighbors.end(), bind2nd(mem_fun(&Neighbor::IsTraversalClient), &addr)) != m_neighbors.end();
#endif
}

bool NeighborList::IsTraversalServer(const PIPSocket::Address & addr) const
{
#if (__cplusplus >= 201703L) // C++17
return find_if(m_neighbors.begin(), m_neighbors.end(), bind(mem_fn(&Neighbor::IsTraversalServer), std::placeholders::_1, &addr)) != m_neighbors.end();
#else
return find_if(m_neighbors.begin(), m_neighbors.end(), bind2nd(mem_fun(&Neighbor::IsTraversalServer), &addr)) != m_neighbors.end();
#endif
}

// is IP a neighbor and is it not disabled ?
bool NeighborList::IsAvailable(const PIPSocket::Address & ip)
{
// Attempt to find the neighbor in the list
#if (__cplusplus >= 201703L) // C++17
List::iterator findNeighbor = find_if(m_neighbors.begin(), m_neighbors.end(), bind(mem_fn(&Neighbor::IsFrom), std::placeholders::_1, &ip));
#else
List::iterator findNeighbor = find_if(m_neighbors.begin(), m_neighbors.end(), bind2nd(mem_fun(&Neighbor::IsFrom), &ip));
#endif
if (findNeighbor == m_neighbors.end())
{
return false;
Expand All @@ -1790,7 +1813,11 @@ PString NeighborList::GetNeighborIdBySigAdr(const H225_TransportAddress & sigAd)
PString NeighborList::GetNeighborIdBySigAdr(const PIPSocket::Address & sigAd)
{
// Attempt to find the neighbor in the list
#if (__cplusplus >= 201703L) // C++17
List::iterator findNeighbor = find_if(m_neighbors.begin(), m_neighbors.end(), bind(mem_fn(&Neighbor::IsFrom), std::placeholders::_1, &sigAd));
#else
List::iterator findNeighbor = find_if(m_neighbors.begin(), m_neighbors.end(), bind2nd(mem_fun(&Neighbor::IsFrom), &sigAd));
#endif
if (findNeighbor == m_neighbors.end())
{
return PString::Empty();
Expand All @@ -1801,7 +1828,11 @@ PString NeighborList::GetNeighborIdBySigAdr(const PIPSocket::Address & sigAd)
PString NeighborList::GetNeighborGkIdBySigAdr(const PIPSocket::Address & sigAd)
{
// Attempt to find the neighbor in the list
#if (__cplusplus >= 201703L) // C++17
List::iterator findNeighbor = find_if(m_neighbors.begin(), m_neighbors.end(), bind(mem_fn(&Neighbor::IsFrom), std::placeholders::_1, &sigAd));
#else
List::iterator findNeighbor = find_if(m_neighbors.begin(), m_neighbors.end(), bind2nd(mem_fun(&Neighbor::IsFrom), &sigAd));
#endif

if (findNeighbor == m_neighbors.end())
{
Expand All @@ -1814,7 +1845,11 @@ PString NeighborList::GetNeighborGkIdBySigAdr(const PIPSocket::Address & sigAd)
bool NeighborList::GetNeighborTLSBySigAdr(const PIPSocket::Address & sigAd)
{
// Attempt to find the neighbor in the list
#if (__cplusplus >= 201703L) // C++17
List::iterator findNeighbor = find_if(m_neighbors.begin(), m_neighbors.end(), bind(mem_fn(&Neighbor::IsFrom), std::placeholders::_1, &sigAd));
#else
List::iterator findNeighbor = find_if(m_neighbors.begin(), m_neighbors.end(), bind2nd(mem_fun(&Neighbor::IsFrom), &sigAd));
#endif
if (findNeighbor == m_neighbors.end())
{
return false;
Expand Down Expand Up @@ -2035,7 +2070,11 @@ bool NeighborPolicy::OnRequest(AdmissionRequest & arq_obj)
bool NeighborPolicy::OnRequest(LocationRequest & lrq_obj)
{
RasMsg * ras = lrq_obj.GetWrapper();
#if (__cplusplus >= 201703L) // C++17
List::iterator iter = find_if(m_neighbors.begin(), m_neighbors.end(), bind(mem_fn(&Neighbor::IsAcceptable), std::placeholders::_1, ras));
#else
List::iterator iter = find_if(m_neighbors.begin(), m_neighbors.end(), bind2nd(mem_fun(&Neighbor::IsAcceptable), ras));
#endif
Neighbor * requester = (iter != m_neighbors.end()) ? *iter : NULL;
int hopCount = 0;
if (requester) {
Expand Down
Loading

0 comments on commit 7d1fa75

Please sign in to comment.