added operator< to AMQP::Address

This commit is contained in:
Emiel Bruijntjes 2017-12-29 19:27:40 +01:00
parent 5c002774de
commit b25bd583a3
2 changed files with 38 additions and 1 deletions

View File

@ -216,7 +216,7 @@ public:
// logins must match
if (_login != that._login) return false;
// hostname must match, but are nt case sensitive
// hostname must match, but are not case sensitive
if (strcasecmp(_hostname.data(), that._hostname.data()) != 0) return false;
// portnumber must match
@ -237,6 +237,29 @@ public:
return !operator==(that);
}
/**
* Comparison operator that is useful if addresses have to be ordered
* @param that
* @return bool
*/
bool operator<(const Address &that) const
{
// compare logins
if (_login != that._login) return _login < that._login;
// hostname must match, but are not case sensitive
int result = strcasecmp(_hostname.data(), that._hostname.data());
// if hostnames are not equal, we know the result
if (result != 0) return result < 0;
// portnumber must match
if (_port != that._port) return _port < that._port;
// and finally compare the vhosts
return _vhost < that._vhost;
}
/**
* Friend function to allow writing the address to a stream
* @param stream

View File

@ -119,6 +119,20 @@ public:
// the opposite of operator==
return !operator==(that);
}
/**
* Comparison operator
* @param that
* @return bool
*/
bool operator<(const Login &that) const
{
// compare users
if (_user != that._user) return _user < that._user;
// compare passwords
return _password < that._password;
}
/**
* Friend function to allow writing the login to a stream