From 332c371e4001913905ebce30e1d2b5c6ad405b25 Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Sat, 10 Jun 2017 22:14:13 +0200 Subject: ServerAddress: new struct for containing a HostAddress along with a port number. This is meant to replace the QPair-based qpAddress type used in ConnectDialog. --- src/ServerAddress.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/ServerAddress.cpp (limited to 'src/ServerAddress.cpp') diff --git a/src/ServerAddress.cpp b/src/ServerAddress.cpp new file mode 100644 index 000000000..98a6d5365 --- /dev/null +++ b/src/ServerAddress.cpp @@ -0,0 +1,42 @@ +// Copyright 2005-2017 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 . + +#include "murmur_pch.h" + +#include "ServerAddress.h" + +ServerAddress::ServerAddress() + : port(0) {} + +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 < lhs.port) { + return true; + } + } + return false; +} + +uint qHash(const ServerAddress &key) { + return qHash(key.host) ^ uint(key.port); +} -- cgit v1.2.3