mumble/src/ServerAddress.cpp
Robert Adam 6c565689ae REFAC: Get rid of union in HostAddress
The way this union was accessed is not covered by the C++ standard and
was therefore undefined behavior. Therefore, the code was rewritten to
stick to standard C++.
2024-01-07 17:10:11 +01:00

37 lines
993 B
C++

// Copyright 2017-2023 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
#include "ServerAddress.h"
ServerAddress::ServerAddress(HostAddress host_, unsigned short port_) : host(host_), port(port_) {
}
bool ServerAddress::isValid() const {
return host.isValid() && port != 0;
}
bool operator==(const ServerAddress &lhs, const ServerAddress &rhs) {
return lhs.host == rhs.host && lhs.port == rhs.port;
}
bool operator!=(const ServerAddress &lhs, const ServerAddress &rhs) {
return !operator==(lhs, rhs);
}
bool operator<(const ServerAddress &lhs, const ServerAddress &rhs) {
if (lhs.host < rhs.host) {
return true;
} else if (lhs.host == rhs.host) {
if (lhs.port < rhs.port) {
return true;
}
}
return false;
}
uint qHash(const ServerAddress &key) {
return qHash(key.host) ^ uint(key.port);
}