]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1283] Define operator<< for IOAddress
authorMukund Sivaraman <muks@isc.org>
Tue, 7 Jan 2014 05:03:24 +0000 (10:33 +0530)
committerMukund Sivaraman <muks@isc.org>
Tue, 7 Jan 2014 05:03:24 +0000 (10:33 +0530)
src/lib/asiolink/io_address.cc
src/lib/asiolink/io_address.h
src/lib/asiolink/tests/io_address_unittest.cc

index 90bdf57d2949156be0c690405c7561fb72e9ebd5..798672503c1ece805c9d50e59d131cb9fdbfd48b 100644 (file)
@@ -114,5 +114,11 @@ IOAddress::operator uint32_t() const {
     }
 }
 
+std::ostream&
+operator<<(std::ostream& os, const IOAddress& address) {
+    os << address.toText();
+    return (os);
+}
+
 } // namespace asiolink
 } // namespace isc
index 5b11b8784c2310a0125afe5a1688a38c203b3a09..8b18bf65d31897b664c217053cb367dc9973fb19 100644 (file)
@@ -232,6 +232,22 @@ private:
     asio::ip::address asio_address_;
 };
 
+/// \brief Insert the IOAddress as a string into stream.
+///
+/// This method converts the \c address into a string and inserts it
+/// into the output stream \c os.
+///
+/// This function overloads the global operator<< to behave as described
+/// in ostream::operator<< but applied to \c IOAddress objects.
+///
+/// \param os A \c std::ostream object on which the insertion operation is
+/// performed.
+/// \param address The \c IOAddress object output by the operation.
+/// \return A reference to the same \c std::ostream object referenced by
+/// parameter \c os after the insertion operation.
+std::ostream&
+operator<<(std::ostream& os, const IOAddress& address);
+
 } // namespace asiolink
 } // namespace isc
 #endif // IO_ADDRESS_H
index 4bd7626df3c999b82f9b0a78e8e32f224431bc21..eea10e9ef02880d487321aea9d8527a82c1872cf 100644 (file)
@@ -21,6 +21,7 @@
 #include <algorithm>
 #include <cstring>
 #include <vector>
+#include <sstream>
 
 using namespace isc::asiolink;
 
@@ -172,3 +173,12 @@ TEST(IOAddressTest, lessThanEqual) {
 
     EXPECT_TRUE(addr6 <= addr7);
 }
+
+// test operator<<.  We simply confirm it appends the result of toText().
+TEST(IOAddressTest, LeftShiftOperator) {
+    const IOAddress addr("192.0.2.5");
+
+    std::ostringstream oss;
+    oss << addr;
+    EXPECT_EQ(addr.toText(), oss.str());
+}