tools: simplify on/off attribute printing

refs #4004

Change-Id: Idb666ff4dbeddc37f1cb10710ba3d75f7fe8bdb5
This commit is contained in:
Junxiao Shi
2018-03-02 15:10:18 +00:00
committed by Alex Afanasyev
parent 6f09ab6cde
commit 8dc473a724
4 changed files with 26 additions and 2 deletions
+8
View File
@@ -118,6 +118,14 @@ BOOST_AUTO_TEST_CASE(ItemAttributesMultiLine)
BOOST_CHECK(os.is_equal(" id=500\nuri=udp4://192.0.2.1:6363\n"));
}
BOOST_AUTO_TEST_CASE(OnOff)
{
output_test_stream os;
os << 'A' << text::OnOff{true} << 'B' << text::OnOff{false} << 'C';
BOOST_CHECK(os.is_equal("AonBoffC"));
}
BOOST_AUTO_TEST_SUITE_END() // Text
BOOST_AUTO_TEST_SUITE_END() // TestFormatHelpers
+2 -2
View File
@@ -509,8 +509,8 @@ FaceModule::formatItemText(std::ostream& os, const FaceStatus& item, bool wantMu
void
FaceModule::printFaceParams(std::ostream& os, text::ItemAttributes& ia, const ControlParameters& resp)
{
os << ia("reliability") << (resp.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED) ? "on" : "off")
<< ia("congestion-marking") << (resp.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED) ? "on" : "off");
os << ia("reliability") << text::OnOff{resp.getFlagBit(ndn::nfd::BIT_LP_RELIABILITY_ENABLED)}
<< ia("congestion-marking") << text::OnOff{resp.getFlagBit(ndn::nfd::BIT_CONGESTION_MARKING_ENABLED)};
if (resp.hasBaseCongestionMarkingInterval()) {
os << ia("congestion-marking-interval")
<< text::formatDuration<time::milliseconds>(resp.getBaseCongestionMarkingInterval());
+6
View File
@@ -177,6 +177,12 @@ operator<<(std::ostream& os, const ItemAttributes::Attribute& attr)
return os << attr.attribute << '=';
}
std::ostream&
operator<<(std::ostream& os, OnOff v)
{
return os << (v.flag ? "on" : "off");
}
std::string
formatTimestamp(time::system_clock::TimePoint t)
{
+10
View File
@@ -165,6 +165,16 @@ private:
std::ostream&
operator<<(std::ostream& os, const ItemAttributes::Attribute& attr);
/** \brief print boolean as 'on' or 'off'
*/
struct OnOff
{
bool flag;
};
std::ostream&
operator<<(std::ostream& os, OnOff v);
namespace detail {
template<typename DurationT>