map/das-dn/third_party/AdsLib/AdsDef.cpp
2024-12-09 09:41:04 +08:00

50 lines
1.1 KiB
C++

// SPDX-License-Identifier: MIT
/**
Copyright (c) 2015 - 2022 Beckhoff Automation GmbH & Co. KG
*/
#include "AdsDef.h"
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string.h>
namespace Beckhoff
{
namespace Ads
{
bool operator<(const AmsNetId& lhs, const AmsNetId& rhs)
{
for (unsigned int i = 0; i < sizeof(rhs.b); ++i) {
if (lhs.b[i] != rhs.b[i]) {
return lhs.b[i] < rhs.b[i];
}
}
return false;
}
bool operator==(const AmsNetId& lhs, const AmsNetId& rhs)
{
return 0 == memcmp(&lhs, &rhs, sizeof(lhs));
}
bool operator<(const AmsAddr& lhs, const AmsAddr& rhs)
{
if (memcmp(&lhs.netId, &rhs.netId, sizeof(lhs.netId))) {
return lhs.netId < rhs.netId;
}
return lhs.port < rhs.port;
}
bool operator==(const AmsAddr& lhs, const AmsAddr& rhs)
{
return 0 == memcmp(&lhs, &rhs, sizeof(lhs));
}
std::ostream& operator<<(std::ostream& os, const AmsNetId& netId)
{
return os << std::dec << (int)netId.b[0] << '.' << (int)netId.b[1] << '.' << (int)netId.b[2] << '.' <<
(int)netId.b[3] << '.' << (int)netId.b[4] << '.' << (int)netId.b[5];
}
}
}