Use more C++17 features
Mainly structured bindings, inline variables, and class template
argument deduction, plus many more smaller things.
Change-Id: I810d17e0adb470426e4e30c898e03b3140ad052f
diff --git a/daemon/fw/unsolicited-data-policy.hpp b/daemon/fw/unsolicited-data-policy.hpp
index 5d562a1..486903a 100644
--- a/daemon/fw/unsolicited-data-policy.hpp
+++ b/daemon/fw/unsolicited-data-policy.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2021, Regents of the University of California,
+ * Copyright (c) 2014-2022, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -31,7 +31,8 @@
namespace nfd {
namespace fw {
-/** \brief a decision made by UnsolicitedDataPolicy
+/**
+ * \brief Decision made by UnsolicitedDataPolicy
*/
enum class UnsolicitedDataDecision {
DROP, ///< the Data should be dropped
@@ -41,11 +42,12 @@
std::ostream&
operator<<(std::ostream& os, UnsolicitedDataDecision d);
-/** \brief determines how to process an unsolicited Data
+/**
+ * \brief Determines how to process an unsolicited Data packet
*
- * An incoming Data is unsolicited if it does not match any PIT entry.
- * This class assists forwarding pipelines to decide whether to drop an unsolicited Data
- * or admit it into the ContentStore.
+ * An incoming Data packet is *unsolicited* if it does not match any PIT entry.
+ * This class assists forwarding pipelines to decide whether to drop an unsolicited Data
+ * or admit it into the ContentStore.
*/
class UnsolicitedDataPolicy : noncopyable
{
@@ -61,9 +63,9 @@
static void
registerPolicy(const std::string& policyName = P::POLICY_NAME)
{
- Registry& registry = getRegistry();
- BOOST_ASSERT(registry.count(policyName) == 0);
- registry[policyName] = [] { return make_unique<P>(); };
+ BOOST_ASSERT(!policyName.empty());
+ auto r = getRegistry().insert_or_assign(policyName, [] { return make_unique<P>(); });
+ BOOST_VERIFY(r.second);
}
/** \return an UnsolicitedDataPolicy identified by \p policyName,
@@ -78,14 +80,15 @@
getPolicyNames();
private:
- typedef std::function<unique_ptr<UnsolicitedDataPolicy>()> CreateFunc;
- typedef std::map<std::string, CreateFunc> Registry; // indexed by policy name
+ using CreateFunc = std::function<unique_ptr<UnsolicitedDataPolicy>()>;
+ using Registry = std::map<std::string, CreateFunc>; // indexed by policy name
static Registry&
getRegistry();
};
-/** \brief drops all unsolicited Data
+/**
+ * \brief Drops all unsolicited Data
*/
class DropAllUnsolicitedDataPolicy final : public UnsolicitedDataPolicy
{
@@ -97,7 +100,8 @@
static const std::string POLICY_NAME;
};
-/** \brief admits unsolicited Data from local faces
+/**
+ * \brief Admits unsolicited Data from local faces
*/
class AdmitLocalUnsolicitedDataPolicy final : public UnsolicitedDataPolicy
{
@@ -109,7 +113,8 @@
static const std::string POLICY_NAME;
};
-/** \brief admits unsolicited Data from non-local faces
+/**
+ * \brief Admits unsolicited Data from non-local faces
*/
class AdmitNetworkUnsolicitedDataPolicy final : public UnsolicitedDataPolicy
{
@@ -121,7 +126,8 @@
static const std::string POLICY_NAME;
};
-/** \brief admits all unsolicited Data
+/**
+ * \brief Admits all unsolicited Data
*/
class AdmitAllUnsolicitedDataPolicy final : public UnsolicitedDataPolicy
{
@@ -133,16 +139,18 @@
static const std::string POLICY_NAME;
};
-/** \brief The default UnsolicitedDataPolicy
+/**
+ * \brief The default UnsolicitedDataPolicy
*/
using DefaultUnsolicitedDataPolicy = DropAllUnsolicitedDataPolicy;
} // namespace fw
} // namespace nfd
-/** \brief registers an unsolicited data policy
- * \param P a subclass of nfd::fw::UnsolicitedDataPolicy;
- * P::POLICY_NAME must be a string that contains policy name
+/**
+ * \brief Registers an unsolicited data policy
+ * \param P A subclass of nfd::fw::UnsolicitedDataPolicy. \p P must have a static data
+ * member `POLICY_NAME` convertible to std::string that contains the policy name.
*/
#define NFD_REGISTER_UNSOLICITED_DATA_POLICY(P) \
static class NfdAuto ## P ## UnsolicitedDataPolicyRegistrationClass \