From af6886be922d528de20c66aea38059cd9bd0bbe2 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Wed, 26 Apr 2017 09:00:01 +0200 Subject: [PATCH] added comparison operators to Address and Login classes --- include/address.h | 31 +++++++++++++++++++++++++++++++ include/login.h | 23 +++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/include/address.h b/include/address.h index fb7581d..870f699 100644 --- a/include/address.h +++ b/include/address.h @@ -186,6 +186,37 @@ public: // done return str; } + + /** + * Comparison operator + * @param that + * @return bool + */ + bool operator==(const Address &that) const + { + // logins must match + if (_login != that._login) return false; + + // hostname must match, but are nt case sensitive + if (strcasecmp(_hostname.data(), that._hostname.data()) != 0) return false; + + // portnumber must match + if (_port != that._port) return false; + + // and finally the vhosts, they must match too + return _vhost == that._vhost; + } + + /** + * Comparison operator + * @param that + * @return bool + */ + bool operator!=(const Address &that) const + { + // the opposite of operator== + return !operator==(that); + } }; /** diff --git a/include/login.h b/include/login.h index d3cc34e..f68f1aa 100644 --- a/include/login.h +++ b/include/login.h @@ -97,6 +97,29 @@ public: // append other elements return result.append(_user).append("\0",1).append(_password); } + + /** + * Comparison operator + * @param that + * @return bool + */ + bool operator==(const Login &that) const + { + // username and password must match + return _user == that._user && _password == that._password; + } + + /** + * Comparison operator + * @param that + * @return bool + */ + bool operator!=(const Login &that) const + { + // the opposite of operator== + return !operator==(that); + } + }; /**