build: switch to C++17
Change-Id: Id6217b5c993f3e4726e89773128b565e5f136bb6
diff --git a/tools/dump/main.cpp b/tools/dump/main.cpp
index 49ea5b0..033ffc4 100644
--- a/tools/dump/main.cpp
+++ b/tools/dump/main.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2011-2021, Regents of the University of California.
+ * Copyright (c) 2011-2022, Regents of the University of California.
*
* This file is part of ndn-tools (Named Data Networking Essential Tools).
* See AUTHORS.md for complete list of ndn-tools authors and contributors.
@@ -28,15 +28,14 @@
#include <sstream>
-namespace ndn {
-namespace dump {
+namespace ndn::dump {
namespace po = boost::program_options;
static void
-usage(std::ostream& os, const std::string& appName, const po::options_description& options)
+usage(std::ostream& os, std::string_view progName, const po::options_description& options)
{
- os << "Usage: " << appName << " [options] [pcap-filter]\n"
+ os << "Usage: " << progName << " [options] [pcap-filter]\n"
<< "\n"
<< "Default pcap-filter:\n"
<< " '" << NdnDump::getDefaultPcapFilter() << "'\n"
@@ -142,8 +141,7 @@
return 0;
}
-} // namespace dump
-} // namespace ndn
+} // namespace ndn::dump
int
main(int argc, char* argv[])
diff --git a/tools/dump/ndndump.cpp b/tools/dump/ndndump.cpp
index cb1583f..4b28c63 100644
--- a/tools/dump/ndndump.cpp
+++ b/tools/dump/ndndump.cpp
@@ -39,8 +39,7 @@
#include <boost/endian/conversion.hpp>
-namespace ndn {
-namespace dump {
+namespace ndn::dump {
namespace endian = boost::endian;
@@ -517,9 +516,7 @@
}
out.addDelimiter();
- bool isOk = false;
- Block block;
- std::tie(isOk, block) = Block::fromBuffer({pkt, len});
+ auto [isOk, block] = Block::fromBuffer({pkt, len});
if (!isOk) {
// if packet is incomplete, we will not be able to process it
out << "NDN truncated packet, length " << len;
@@ -539,15 +536,12 @@
return true;
}
- Buffer::const_iterator begin, end;
- if (lpPacket.has<lp::FragmentField>()) {
- std::tie(begin, end) = lpPacket.get<lp::FragmentField>();
- }
- else {
+ if (!lpPacket.has<lp::FragmentField>()) {
out << " idle";
return true;
}
+ auto [begin, end] = lpPacket.get<lp::FragmentField>();
std::tie(isOk, netPacket) = Block::fromBuffer({begin, end});
if (!isOk) {
// if network packet is fragmented, we will not be able to process it
@@ -610,5 +604,4 @@
return std::regex_match(name.toUri(), *nameFilter);
}
-} // namespace dump
-} // namespace ndn
+} // namespace ndn::dump
diff --git a/tools/dump/ndndump.hpp b/tools/dump/ndndump.hpp
index 47a455a..9d786e7 100644
--- a/tools/dump/ndndump.hpp
+++ b/tools/dump/ndndump.hpp
@@ -37,8 +37,7 @@
#define UH_LEN len
#endif
-namespace ndn {
-namespace dump {
+namespace ndn::dump {
class OutputFormatter;
@@ -59,7 +58,7 @@
void
printPacket(const pcap_pkthdr* pkthdr, const uint8_t* payload) const;
- static constexpr const char*
+ static constexpr std::string_view
getDefaultPcapFilter() noexcept
{
return "(ether proto 0x8624) or (tcp port 6363) or (udp port 6363) or (udp port 56363)";
@@ -99,13 +98,13 @@
bool
printNdn(OutputFormatter& out, const uint8_t* pkt, size_t len) const;
- bool
+ [[nodiscard]] bool
matchesFilter(const Name& name) const;
public: // options
std::string interface;
std::string inputFile;
- std::string pcapFilter = getDefaultPcapFilter();
+ std::string pcapFilter{getDefaultPcapFilter()};
optional<std::regex> nameFilter;
bool wantPromisc = true;
bool wantTimestamp = true;
@@ -118,7 +117,6 @@
int m_dataLinkType = -1;
};
-} // namespace dump
-} // namespace ndn
+} // namespace ndn::dump
#endif // NDN_TOOLS_DUMP_NDNDUMP_HPP