Browse Source

[2053] Add operator<< to dns::LabelSequence

Mukund Sivaraman 13 years ago
parent
commit
36d3b72708

+ 6 - 0
src/lib/dns/labelsequence.cc

@@ -117,5 +117,11 @@ LabelSequence::toText() const {
     return (name_.toText(!isAbsolute(), first_label_, last_label_));
 }
 
+std::ostream&
+operator<<(std::ostream& os, const LabelSequence& label_sequence) {
+    os << label_sequence.toText();
+    return (os);
+}
+
 } // end namespace dns
 } // end namespace isc

+ 17 - 0
src/lib/dns/labelsequence.h

@@ -187,6 +187,23 @@ private:
 };
 
 
+///
+/// \brief Insert the label sequence as a string into stream.
+///
+/// This method convert the \c label_sequence 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 LabelSequence objects.
+///
+/// \param os A \c std::ostream object on which the insertion operation is
+/// performed.
+/// \param name The \c LabelSequence 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 LabelSequence& label_sequence);
+
 } // end namespace dns
 } // end namespace isc
 

+ 6 - 0
src/lib/dns/tests/labelsequence_unittest.cc

@@ -394,4 +394,10 @@ TEST_F(LabelSequenceTest, getHash) {
     hashDistributionCheck(ca_servers);
 }
 
+// test operator<<.  We simply confirm it appends the result of toText().
+TEST_F(LabelSequenceTest, LeftShiftOperator) {
+    ostringstream oss;
+    oss << ls1;
+    EXPECT_EQ(ls1.toText(), oss.str());
+}
 }