diff options
author | Mikkel Krautz <mikkel@krautz.dk> | 2017-06-10 23:14:13 +0300 |
---|---|---|
committer | Mikkel Krautz <mikkel@krautz.dk> | 2017-06-10 23:14:13 +0300 |
commit | 332c371e4001913905ebce30e1d2b5c6ad405b25 (patch) | |
tree | 8ed1a91f6d3bdbea13bf15ba6e85b073b28766d9 /src/ServerAddress.cpp | |
parent | ac3405921d2df74836423a669457922e11c7a114 (diff) |
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.
Diffstat (limited to 'src/ServerAddress.cpp')
-rw-r--r-- | src/ServerAddress.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
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 <https://www.mumble.info/LICENSE>. + +#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); +} |