From 27ac6aeea5f9e730aec83ce3d61d8a4f485b02e5 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Wed, 21 Jun 2017 09:44:52 +0200 Subject: [PATCH] added operator<< to write a amqp address to a stream --- include/address.h | 24 ++++++++++++++++++++++++ include/login.h | 12 ++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/address.h b/include/address.h index 2117995..c2e9f21 100644 --- a/include/address.h +++ b/include/address.h @@ -236,6 +236,30 @@ public: // the opposite of operator== return !operator==(that); } + + /** + * Friend function to allow writing the address to a stream + * @param stream + * @param address + * @return std::ostream + */ + friend std::ostream &operator<<(std::ostream &stream, const Address &address) + { + // start with the protocol and login + stream << "amqp://" << address._login; + + // do we need a special portnumber? + if (address._port != 5672) stream << ":" << address._port; + + // append default vhost + stream << "/"; + + // do we have a special vhost? + if (address._vhost != "/") stream << address._vhost; + + // done + return stream; + } }; /** diff --git a/include/login.h b/include/login.h index f68f1aa..d4599d9 100644 --- a/include/login.h +++ b/include/login.h @@ -120,6 +120,18 @@ public: return !operator==(that); } + /** + * Friend function to allow writing the login to a stream + * @param stream + * @param login + * @return std::ostream + */ + friend std::ostream &operator<<(std::ostream &stream, const Login &login) + { + // write username and password + return stream << login._user << "@" << login._password; + } + }; /**