diff --git a/tests/tools/nfdc/format-helpers.t.cpp b/tests/tools/nfdc/format-helpers.t.cpp index a94d2ba7..5de002bc 100644 --- a/tests/tools/nfdc/format-helpers.t.cpp +++ b/tests/tools/nfdc/format-helpers.t.cpp @@ -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 diff --git a/tools/nfdc/face-module.cpp b/tools/nfdc/face-module.cpp index 93a6563c..85673a80 100644 --- a/tools/nfdc/face-module.cpp +++ b/tools/nfdc/face-module.cpp @@ -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(resp.getBaseCongestionMarkingInterval()); diff --git a/tools/nfdc/format-helpers.cpp b/tools/nfdc/format-helpers.cpp index 6d5a9834..a329102d 100644 --- a/tools/nfdc/format-helpers.cpp +++ b/tools/nfdc/format-helpers.cpp @@ -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) { diff --git a/tools/nfdc/format-helpers.hpp b/tools/nfdc/format-helpers.hpp index c0f8fd1b..0d131f16 100644 --- a/tools/nfdc/format-helpers.hpp +++ b/tools/nfdc/format-helpers.hpp @@ -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