table: code modernization
Change-Id: I9ca9a1905aea316726d0323f4537a2420890735f
diff --git a/daemon/table/dead-nonce-list.cpp b/daemon/table/dead-nonce-list.cpp
index a5bd9f8..720a415 100644
--- a/daemon/table/dead-nonce-list.cpp
+++ b/daemon/table/dead-nonce-list.cpp
@@ -33,16 +33,16 @@
const time::nanoseconds DeadNonceList::DEFAULT_LIFETIME = 6_s;
const time::nanoseconds DeadNonceList::MIN_LIFETIME = 1_ms;
-const size_t DeadNonceList::INITIAL_CAPACITY = (1 << 7);
-const size_t DeadNonceList::MIN_CAPACITY = (1 << 3);
-const size_t DeadNonceList::MAX_CAPACITY = (1 << 24);
+const size_t DeadNonceList::INITIAL_CAPACITY = 1 << 7;
+const size_t DeadNonceList::MIN_CAPACITY = 1 << 3;
+const size_t DeadNonceList::MAX_CAPACITY = 1 << 24;
const DeadNonceList::Entry DeadNonceList::MARK = 0;
const size_t DeadNonceList::EXPECTED_MARK_COUNT = 5;
const double DeadNonceList::CAPACITY_UP = 1.2;
const double DeadNonceList::CAPACITY_DOWN = 0.9;
-const size_t DeadNonceList::EVICT_LIMIT = (1 << 6);
+const size_t DeadNonceList::EVICT_LIMIT = 1 << 6;
-DeadNonceList::DeadNonceList(const time::nanoseconds& lifetime)
+DeadNonceList::DeadNonceList(time::nanoseconds lifetime)
: m_lifetime(lifetime)
, m_queue(m_index.get<0>())
, m_ht(m_index.get<1>())
@@ -133,14 +133,12 @@
auto equalRange = m_actualMarkCounts.equal_range(EXPECTED_MARK_COUNT);
if (equalRange.second == m_actualMarkCounts.begin()) {
// all counts are above expected count, adjust down
- m_capacity = std::max(MIN_CAPACITY,
- static_cast<size_t>(m_capacity * CAPACITY_DOWN));
+ m_capacity = std::max(MIN_CAPACITY, static_cast<size_t>(m_capacity * CAPACITY_DOWN));
NFD_LOG_TRACE("adjustCapacity DOWN capacity=" << m_capacity);
}
else if (equalRange.first == m_actualMarkCounts.end()) {
// all counts are below expected count, adjust up
- m_capacity = std::min(MAX_CAPACITY,
- static_cast<size_t>(m_capacity * CAPACITY_UP));
+ m_capacity = std::min(MAX_CAPACITY, static_cast<size_t>(m_capacity * CAPACITY_UP));
NFD_LOG_TRACE("adjustCapacity UP capacity=" << m_capacity);
}
diff --git a/daemon/table/dead-nonce-list.hpp b/daemon/table/dead-nonce-list.hpp
index 050da35..ccbf5a1 100644
--- a/daemon/table/dead-nonce-list.hpp
+++ b/daemon/table/dead-nonce-list.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -27,14 +27,15 @@
#define NFD_DAEMON_TABLE_DEAD_NONCE_LIST_HPP
#include "core/common.hpp"
-#include <boost/multi_index_container.hpp>
-#include <boost/multi_index/sequenced_index.hpp>
-#include <boost/multi_index/hashed_index.hpp>
#include "core/scheduler.hpp"
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/hashed_index.hpp>
+#include <boost/multi_index/sequenced_index.hpp>
+
namespace nfd {
-/** \brief represents the Dead Nonce list
+/** \brief Represents the Dead Nonce List
*
* The Dead Nonce List is a global table that supplements PIT for loop detection.
* When a Nonce is erased (dead) from PIT entry, the Nonce and the Interest Name is added to
@@ -54,7 +55,7 @@
class DeadNonceList : noncopyable
{
public:
- /** \brief constructs the Dead Nonce List
+ /** \brief Constructs the Dead Nonce List
* \param lifetime duration of the expected lifetime of each nonce,
* must be no less than MIN_LIFETIME.
* This should be set to the duration in which most loops would have occured.
@@ -62,17 +63,17 @@
* \throw std::invalid_argument if lifetime is less than MIN_LIFETIME
*/
explicit
- DeadNonceList(const time::nanoseconds& lifetime = DEFAULT_LIFETIME);
+ DeadNonceList(time::nanoseconds lifetime = DEFAULT_LIFETIME);
~DeadNonceList();
- /** \brief determines if name+nonce exists
+ /** \brief Determines if name+nonce exists
* \return true if name+nonce exists
*/
bool
has(const Name& name, uint32_t nonce) const;
- /** \brief records name+nonce
+ /** \brief Records name+nonce
*/
void
add(const Name& name, uint32_t nonce);
@@ -85,8 +86,11 @@
/** \return expected lifetime
*/
- const time::nanoseconds&
- getLifetime() const;
+ time::nanoseconds
+ getLifetime() const
+ {
+ return m_lifetime;
+ }
private: // Entry and Index
typedef uint64_t Entry;
@@ -108,17 +112,17 @@
typedef Index::nth_index<1>::type Hashtable;
private: // actual lifetime estimation and capacity control
- /** \return number of MARKs in the index
+ /** \brief Return the number of MARKs in the index
*/
size_t
countMarks() const;
- /** \brief add a MARK, then record number of MARKs in m_actualMarkCounts
+ /** \brief Add a MARK, then record number of MARKs in m_actualMarkCounts
*/
void
mark();
- /** \brief adjust capacity according to m_actualMarkCounts
+ /** \brief Adjust capacity according to m_actualMarkCounts
*
* If all counts are above EXPECTED_MARK_COUNT, reduce capacity to m_capacity * CAPACITY_DOWN.
* If all counts are below EXPECTED_MARK_COUNT, increase capacity to m_capacity * CAPACITY_UP.
@@ -126,16 +130,15 @@
void
adjustCapacity();
- /** \brief evict some entries if index is over capacity
+ /** \brief Evict some entries if index is over capacity
*/
void
evictEntries();
public:
- /// default entry lifetime
+ /// Default entry lifetime
static const time::nanoseconds DEFAULT_LIFETIME;
-
- /// minimum entry lifetime
+ /// Minimum entry lifetime
static const time::nanoseconds MIN_LIFETIME;
private:
@@ -148,7 +151,7 @@
// ---- current capacity and hard limits
- /** \brief current capacity of index
+ /** \brief Current capacity of index
*
* The index size is maintained to be near this capacity.
*
@@ -159,13 +162,13 @@
static const size_t INITIAL_CAPACITY;
- /** \brief minimum capacity
+ /** \brief Minimum capacity
*
* This is to ensure correct algorithm operations.
*/
static const size_t MIN_CAPACITY;
- /** \brief maximum capacity
+ /** \brief Maximum capacity
*
* This is to limit memory usage.
*/
@@ -173,7 +176,7 @@
// ---- actual entry lifetime estimation
- /** \brief the MARK for capacity
+ /** \brief The MARK for capacity
*
* The MARK doesn't have a distinct type.
* Entry is a hash. The hash function should have non-invertible property,
@@ -181,42 +184,31 @@
*/
static const Entry MARK;
- /** \brief expected number of MARKs in the index
+ /** \brief Expected number of MARKs in the index
*/
static const size_t EXPECTED_MARK_COUNT;
- /** \brief number of MARKs in the index after each MARK insertion
+ /** \brief Number of MARKs in the index after each MARK insertion
*
- * adjustCapacity uses this to determine whether and how to adjust capcity,
+ * adjustCapacity() uses this to determine whether and how to adjust capcity,
* and then clears this list.
*/
std::multiset<size_t> m_actualMarkCounts;
time::nanoseconds m_markInterval;
-
scheduler::EventId m_markEvent;
// ---- capacity adjustments
static const double CAPACITY_UP;
-
static const double CAPACITY_DOWN;
-
time::nanoseconds m_adjustCapacityInterval;
-
scheduler::EventId m_adjustCapacityEvent;
- /** \brief maximum number of entries to evict at each operation if index is over capacity
- */
+ /// Maximum number of entries to evict at each operation if index is over capacity
static const size_t EVICT_LIMIT;
};
-inline const time::nanoseconds&
-DeadNonceList::getLifetime() const
-{
- return m_lifetime;
-}
-
} // namespace nfd
#endif // NFD_DAEMON_TABLE_DEAD_NONCE_LIST_HPP
diff --git a/daemon/table/fib-entry.cpp b/daemon/table/fib-entry.cpp
index 53dd584..bb49979 100644
--- a/daemon/table/fib-entry.cpp
+++ b/daemon/table/fib-entry.cpp
@@ -30,7 +30,6 @@
Entry::Entry(const Name& prefix)
: m_prefix(prefix)
- , m_nameTreeEntry(nullptr)
{
}
diff --git a/daemon/table/fib-entry.hpp b/daemon/table/fib-entry.hpp
index 5571da3..e0edcc0 100644
--- a/daemon/table/fib-entry.hpp
+++ b/daemon/table/fib-entry.hpp
@@ -112,7 +112,7 @@
Name m_prefix;
NextHopList m_nextHops;
- name_tree::Entry* m_nameTreeEntry;
+ name_tree::Entry* m_nameTreeEntry = nullptr;
friend class name_tree::Entry;
};
diff --git a/daemon/table/fib-nexthop.cpp b/daemon/table/fib-nexthop.cpp
deleted file mode 100644
index 2b946c5..0000000
--- a/daemon/table/fib-nexthop.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2019, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "fib-nexthop.hpp"
-
-namespace nfd {
-namespace fib {
-
-NextHop::NextHop(Face& face, EndpointId endpointId)
- : m_face(&face)
- , m_endpointId(endpointId)
- , m_cost(0)
-{
-}
-
-} // namespace fib
-} // namespace nfd
diff --git a/daemon/table/fib-nexthop.hpp b/daemon/table/fib-nexthop.hpp
index e0cf599..80609ba 100644
--- a/daemon/table/fib-nexthop.hpp
+++ b/daemon/table/fib-nexthop.hpp
@@ -32,14 +32,16 @@
namespace nfd {
namespace fib {
-/** \class NextHop
- * \brief represents a nexthop record in FIB entry
+/** \brief Represents a nexthop record in a FIB entry
*/
class NextHop
{
public:
- explicit
- NextHop(Face& face, EndpointId endpointId);
+ NextHop(Face& face, EndpointId endpointId)
+ : m_face(&face)
+ , m_endpointId(endpointId)
+ {
+ }
Face&
getFace() const
@@ -66,9 +68,9 @@
}
private:
- Face* m_face;
+ Face* m_face; // pointer instead of reference so that NextHop is movable
EndpointId m_endpointId;
- uint64_t m_cost;
+ uint64_t m_cost = 0;
};
} // namespace fib
diff --git a/daemon/table/fib.cpp b/daemon/table/fib.cpp
index 4c74e3f..2f3deab 100644
--- a/daemon/table/fib.cpp
+++ b/daemon/table/fib.cpp
@@ -44,7 +44,6 @@
Fib::Fib(NameTree& nameTree)
: m_nameTree(nameTree)
- , m_nItems(0)
{
}
diff --git a/daemon/table/fib.hpp b/daemon/table/fib.hpp
index c7fb9cc..fc73a7d 100644
--- a/daemon/table/fib.hpp
+++ b/daemon/table/fib.hpp
@@ -44,7 +44,7 @@
namespace fib {
-/** \brief represents the Forwarding Information Base (FIB)
+/** \brief Represents the Forwarding Information Base (FIB)
*/
class Fib : noncopyable
{
@@ -59,26 +59,26 @@
}
public: // lookup
- /** \brief performs a longest prefix match
+ /** \brief Performs a longest prefix match
*/
const Entry&
findLongestPrefixMatch(const Name& prefix) const;
- /** \brief performs a longest prefix match
+ /** \brief Performs a longest prefix match
*
- * This is equivalent to .findLongestPrefixMatch(pitEntry.getName())
+ * This is equivalent to `findLongestPrefixMatch(pitEntry.getName())`
*/
const Entry&
findLongestPrefixMatch(const pit::Entry& pitEntry) const;
- /** \brief performs a longest prefix match
+ /** \brief Performs a longest prefix match
*
- * This is equivalent to .findLongestPrefixMatch(measurementsEntry.getName())
+ * This is equivalent to `findLongestPrefixMatch(measurementsEntry.getName())`
*/
const Entry&
findLongestPrefixMatch(const measurements::Entry& measurementsEntry) const;
- /** \brief performs an exact match lookup
+ /** \brief Performs an exact match lookup
*/
Entry*
findExactMatch(const Name& prefix);
@@ -92,8 +92,8 @@
return FIB_MAX_DEPTH;
}
- /** \brief find or insert a FIB entry
- * \param prefix FIB entry name; it must have no more than \c getMaxDepth() components.
+ /** \brief Find or insert a FIB entry
+ * \param prefix FIB entry name; it must not have more than \c getMaxDepth() components.
* \return the entry, and true for new entry or false for existing entry
*/
std::pair<Entry*, bool>
@@ -105,12 +105,12 @@
void
erase(const Entry& entry);
- /** \brief removes the NextHop record for \p face with a given \p endpointId
+ /** \brief Remove the NextHop record for the given \p face and \p endpointId
*/
void
removeNextHop(Entry& entry, const Face& face, EndpointId endpointId);
- /** \brief removes the NextHop record for \p face for any \p endpointId
+ /** \brief Remove all NextHop records for \p face
*/
void
removeNextHopByFace(Entry& entry, const Face& face);
@@ -120,9 +120,9 @@
typedef boost::range_iterator<Range>::type const_iterator;
/** \return an iterator to the beginning
- * \note Iteration order is implementation-defined.
+ * \note The iteration order is implementation-defined.
* \warning Undefined behavior may occur if a FIB/PIT/Measurements/StrategyChoice entry
- * is inserted or erased during enumeration.
+ * is inserted or erased during iteration.
*/
const_iterator
begin() const
@@ -149,7 +149,7 @@
void
erase(name_tree::Entry* nte, bool canDeleteNte = true);
- /** \brief erase \p entry if it contains no nexthop record
+ /** \brief Erase \p entry if it contains no nexthop records
*/
void
eraseIfEmpty(Entry& entry);
@@ -159,9 +159,9 @@
private:
NameTree& m_nameTree;
- size_t m_nItems;
+ size_t m_nItems = 0;
- /** \brief the empty FIB entry.
+ /** \brief The empty FIB entry.
*
* This entry has no nexthops.
* It is returned by findLongestPrefixMatch if nothing is matched.
diff --git a/daemon/table/measurements-entry.cpp b/daemon/table/measurements-entry.cpp
deleted file mode 100644
index 60138af..0000000
--- a/daemon/table/measurements-entry.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis.
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "measurements-entry.hpp"
-
-namespace nfd {
-namespace measurements {
-
-Entry::Entry(const Name& name)
- : m_name(name)
- , m_expiry(time::steady_clock::TimePoint::min())
- , m_nameTreeEntry(nullptr)
-{
-}
-
-} // namespace measurements
-} // namespace nfd
diff --git a/daemon/table/measurements-entry.hpp b/daemon/table/measurements-entry.hpp
index 53f1a05..039fe54 100644
--- a/daemon/table/measurements-entry.hpp
+++ b/daemon/table/measurements-entry.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -37,13 +37,16 @@
namespace measurements {
-/** \brief represents a Measurements entry
+/** \brief Represents a Measurements entry
*/
class Entry : public StrategyInfoHost, noncopyable
{
public:
explicit
- Entry(const Name& name);
+ Entry(const Name& name)
+ : m_name(name)
+ {
+ }
const Name&
getName() const
@@ -53,10 +56,10 @@
private:
Name m_name;
- time::steady_clock::TimePoint m_expiry;
+ time::steady_clock::TimePoint m_expiry = time::steady_clock::TimePoint::min();
scheduler::EventId m_cleanup;
- name_tree::Entry* m_nameTreeEntry;
+ name_tree::Entry* m_nameTreeEntry = nullptr;
friend class Measurements;
friend class name_tree::Entry;
diff --git a/daemon/table/measurements.cpp b/daemon/table/measurements.cpp
index 651a83b..8ab89cc 100644
--- a/daemon/table/measurements.cpp
+++ b/daemon/table/measurements.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -33,7 +33,6 @@
Measurements::Measurements(NameTree& nameTree)
: m_nameTree(nameTree)
- , m_nItems(0)
{
}
@@ -128,7 +127,7 @@
{
BOOST_ASSERT(m_nameTree.getEntry(entry) != nullptr);
- time::steady_clock::TimePoint expiry = time::steady_clock::now() + lifetime;
+ auto expiry = time::steady_clock::now() + lifetime;
if (entry.m_expiry >= expiry) {
// has longer lifetime, not extending
return;
diff --git a/daemon/table/measurements.hpp b/daemon/table/measurements.hpp
index c72ba28..342d753 100644
--- a/daemon/table/measurements.hpp
+++ b/daemon/table/measurements.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -41,23 +41,23 @@
namespace measurements {
-/** \brief a predicate that accepts or rejects an entry
+/** \brief A predicate that accepts or rejects an entry
*/
-typedef std::function<bool(const Entry&)> EntryPredicate;
+using EntryPredicate = std::function<bool(const Entry&)>;
-/** \brief an \c EntryPredicate that accepts any entry
+/** \brief An \c EntryPredicate that accepts any entry
*/
class AnyEntry
{
public:
bool
- operator()(const Entry& entry) const
+ operator()(const Entry&) const
{
return true;
}
};
-/** \brief an \c EntryPredicate that accepts an entry if it has StrategyInfo of type T
+/** \brief An \c EntryPredicate that accepts an entry if it has StrategyInfo of type T
*/
template<typename T>
class EntryWithStrategyInfo
@@ -70,7 +70,7 @@
}
};
-/** \brief the Measurements table
+/** \brief The Measurements table
*
* The Measurements table is a data structure for forwarding strategies to store per name prefix
* measurements. A strategy can access this table via \c Strategy::getMeasurements(), and then
@@ -90,7 +90,7 @@
return NameTree::getMaxDepth();
}
- /** \brief find or insert an entry by name
+ /** \brief Find or insert an entry by name
*
* An entry name can have at most \c getMaxDepth() components. If \p name exceeds this limit,
* it is truncated to the first \c getMaxDepth() components.
@@ -98,45 +98,47 @@
Entry&
get(const Name& name);
- /** \brief equivalent to `get(fibEntry.getPrefix())`
+ /** \brief Equivalent to `get(fibEntry.getPrefix())`
*/
Entry&
get(const fib::Entry& fibEntry);
- /** \brief equivalent to
- * `get(pitEntry.getName(), std::min(pitEntry.getName().size(), getMaxDepth()))`
+ /** \brief Equivalent to `get(pitEntry.getName(), std::min(pitEntry.getName().size(), getMaxDepth()))`
*/
Entry&
get(const pit::Entry& pitEntry);
- /** \brief find or insert a parent entry
+ /** \brief Find or insert a parent entry
* \retval nullptr child is the root entry
* \return get(child.getName().getPrefix(-1))
*/
Entry*
getParent(const Entry& child);
- /** \brief perform a longest prefix match for \p name
+ /** \brief Perform a longest prefix match for \p name
*/
Entry*
findLongestPrefixMatch(const Name& name,
const EntryPredicate& pred = AnyEntry()) const;
- /** \brief perform a longest prefix match for `pitEntry.getName()`
+ /** \brief Perform a longest prefix match for `pitEntry.getName()`
*/
Entry*
findLongestPrefixMatch(const pit::Entry& pitEntry,
const EntryPredicate& pred = AnyEntry()) const;
- /** \brief perform an exact match
+ /** \brief Perform an exact match
*/
Entry*
findExactMatch(const Name& name) const;
static time::nanoseconds
- getInitialLifetime();
+ getInitialLifetime()
+ {
+ return 4_s;
+ }
- /** \brief extend lifetime of an entry
+ /** \brief Extend lifetime of an entry
*
* The entry will be kept until at least now()+lifetime.
*/
@@ -144,7 +146,10 @@
extendLifetime(Entry& entry, const time::nanoseconds& lifetime);
size_t
- size() const;
+ size() const
+ {
+ return m_nItems;
+ }
private:
void
@@ -161,21 +166,9 @@
private:
NameTree& m_nameTree;
- size_t m_nItems;
+ size_t m_nItems = 0;
};
-inline time::nanoseconds
-Measurements::getInitialLifetime()
-{
- return 4_s;
-}
-
-inline size_t
-Measurements::size() const
-{
- return m_nItems;
-}
-
} // namespace measurements
using measurements::Measurements;
diff --git a/daemon/table/name-tree-entry.cpp b/daemon/table/name-tree-entry.cpp
index 889d84f..c145129 100644
--- a/daemon/table/name-tree-entry.cpp
+++ b/daemon/table/name-tree-entry.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -32,7 +32,6 @@
Entry::Entry(const Name& name, Node* node)
: m_name(name)
, m_node(node)
- , m_parent(nullptr)
{
BOOST_ASSERT(node != nullptr);
BOOST_ASSERT(name.size() <= NameTree::getMaxDepth());
@@ -46,7 +45,6 @@
BOOST_ASSERT(entry.getName() == this->getName().getPrefix(-1));
m_parent = &entry;
-
m_parent->m_children.push_back(this);
}
@@ -103,7 +101,7 @@
BOOST_ASSERT(pitEntry->m_nameTreeEntry == this);
auto it = std::find_if(m_pitEntries.begin(), m_pitEntries.end(),
- [pitEntry] (const shared_ptr<pit::Entry>& pitEntry2) { return pitEntry2.get() == pitEntry; });
+ [pitEntry] (const auto& pitEntry2) { return pitEntry2.get() == pitEntry; });
BOOST_ASSERT(it != m_pitEntries.end());
pitEntry->m_nameTreeEntry = nullptr; // must be done before pitEntry is deallocated
diff --git a/daemon/table/name-tree-entry.hpp b/daemon/table/name-tree-entry.hpp
index 2fa0806..9c101ff 100644
--- a/daemon/table/name-tree-entry.hpp
+++ b/daemon/table/name-tree-entry.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -36,7 +36,7 @@
class Node;
-/** \brief an entry in the name tree
+/** \brief An entry in the name tree
*/
class Entry : noncopyable
{
@@ -58,7 +58,7 @@
return m_parent;
}
- /** \brief set parent of this entry
+ /** \brief Set parent of this entry
* \param entry entry of getName().getPrefix(-1)
* \pre getParent() == nullptr
* \post getParent() == &entry
@@ -67,20 +67,19 @@
void
setParent(Entry& entry);
- /** \brief unset parent of this entry
+ /** \brief Unset parent of this entry
* \post getParent() == nullptr
* \post parent.getChildren() does not contain this
*/
void
unsetParent();
- /** \retval true this entry has at least one child
- * \retval false this entry has no children
+ /** \brief Check whether this entry has any children
*/
bool
hasChildren() const
{
- return !this->getChildren().empty();
+ return !m_children.empty();
}
/** \return children of this entry
@@ -167,7 +166,7 @@
private:
Name m_name;
Node* m_node;
- Entry* m_parent;
+ Entry* m_parent = nullptr;
std::vector<Entry*> m_children;
unique_ptr<fib::Entry> m_fibEntry;
@@ -185,7 +184,7 @@
class GetTableEntry
{
public:
- /** \brief a function pointer to the getter on Entry class that returns ENTRY
+ /** \brief A function pointer to the getter on Entry class that returns ENTRY
*/
using Getter = ENTRY* (Entry::*)() const;
diff --git a/daemon/table/name-tree.cpp b/daemon/table/name-tree.cpp
index 93bed3a..3eca24f 100644
--- a/daemon/table/name-tree.cpp
+++ b/daemon/table/name-tree.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -91,9 +91,9 @@
Entry* nte = this->getEntry(pitEntry);
BOOST_ASSERT(nte != nullptr);
BOOST_ASSERT(std::count_if(nte->getPitEntries().begin(), nte->getPitEntries().end(),
- [&pitEntry] (const shared_ptr<pit::Entry>& pitEntry1) {
- return pitEntry1.get() == &pitEntry;
- }) == 1);
+ [&pitEntry] (const auto& pitEntry1) {
+ return pitEntry1.get() == &pitEntry;
+ }) == 1);
return *nte;
}
diff --git a/daemon/table/name-tree.hpp b/daemon/table/name-tree.hpp
index 4ecca80..1cb5f31 100644
--- a/daemon/table/name-tree.hpp
+++ b/daemon/table/name-tree.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -33,7 +33,7 @@
namespace nfd {
namespace name_tree {
-/** \brief a common index structure for FIB, PIT, StrategyChoice, and Measurements
+/** \brief A common index structure for FIB, PIT, StrategyChoice, and Measurements
*/
class NameTree : noncopyable
{
@@ -42,7 +42,7 @@
NameTree(size_t nBuckets = 1024);
public: // information
- /** \brief maximum depth of the name tree
+ /** \brief Maximum depth of the name tree
*
* Calling \c NameTree::lookup with a name with many components would cause the creation of many
* NameTree entries, which could take very long time. This constant limits the maximum number of
@@ -82,7 +82,7 @@
}
public: // mutation
- /** \brief find or insert an entry by name
+ /** \brief Find or insert an entry by name
*
* This method seeks a name tree entry of name \c name.getPrefix(prefixLen).
* If the entry does not exist, it is created along with all ancestors.
@@ -94,7 +94,7 @@
Entry&
lookup(const Name& name, size_t prefixLen);
- /** \brief equivalent to `lookup(name, name.size())`
+ /** \brief Equivalent to `lookup(name, name.size())`
*/
Entry&
lookup(const Name& name)
@@ -102,36 +102,35 @@
return this->lookup(name, name.size());
}
- /** \brief equivalent to `lookup(fibEntry.getPrefix())`
+ /** \brief Equivalent to `lookup(fibEntry.getPrefix())`
* \param fibEntry a FIB entry attached to this name tree, or \c Fib::s_emptyEntry
* \note This overload is more efficient than `lookup(const Name&)` in common cases.
*/
Entry&
lookup(const fib::Entry& fibEntry);
- /** \brief equivalent to
- * `lookup(pitEntry.getName(), std::min(pitEntry.getName().size(), getMaxDepth()))`
+ /** \brief Equivalent to `lookup(pitEntry.getName(), std::min(pitEntry.getName().size(), getMaxDepth()))`
* \param pitEntry a PIT entry attached to this name tree
* \note This overload is more efficient than `lookup(const Name&)` in common cases.
*/
Entry&
lookup(const pit::Entry& pitEntry);
- /** \brief equivalent to `lookup(measurementsEntry.getName())`
+ /** \brief Equivalent to `lookup(measurementsEntry.getName())`
* \param measurementsEntry a Measurements entry attached to this name tree
* \note This overload is more efficient than `lookup(const Name&)` in common cases.
*/
Entry&
lookup(const measurements::Entry& measurementsEntry);
- /** \brief equivalent to `lookup(strategyChoiceEntry.getPrefix())`
+ /** \brief Equivalent to `lookup(strategyChoiceEntry.getPrefix())`
* \param strategyChoiceEntry a StrategyChoice entry attached to this name tree
* \note This overload is more efficient than `lookup(const Name&)` in common cases.
*/
Entry&
lookup(const strategy_choice::Entry& strategyChoiceEntry);
- /** \brief delete the entry if it is empty
+ /** \brief Delete the entry if it is empty
* \param entry a valid entry
* \param canEraseAncestors whether ancestors should be deleted if they become empty
* \return number of deleted entries
@@ -145,13 +144,13 @@
eraseIfEmpty(Entry* entry, bool canEraseAncestors = true);
public: // matching
- /** \brief exact match lookup
+ /** \brief Exact match lookup
* \return entry with \c name.getPrefix(prefixLen), or nullptr if it does not exist
*/
Entry*
findExactMatch(const Name& name, size_t prefixLen = std::numeric_limits<size_t>::max()) const;
- /** \brief longest prefix matching
+ /** \brief Longest prefix matching
* \return entry whose name is a prefix of \p name and passes \p entrySelector,
* where no other entry with a longer name satisfies those requirements;
* or nullptr if no entry satisfying those requirements exists
@@ -160,7 +159,7 @@
findLongestPrefixMatch(const Name& name,
const EntrySelector& entrySelector = AnyEntry()) const;
- /** \brief equivalent to `findLongestPrefixMatch(entry.getName(), entrySelector)`
+ /** \brief Equivalent to `findLongestPrefixMatch(entry.getName(), entrySelector)`
* \note This overload is more efficient than
* `findLongestPrefixMatch(const Name&, const EntrySelector&)` in common cases.
*/
@@ -168,7 +167,7 @@
findLongestPrefixMatch(const Entry& entry,
const EntrySelector& entrySelector = AnyEntry()) const;
- /** \brief equivalent to `findLongestPrefixMatch(getEntry(tableEntry)->getName(), entrySelector)`
+ /** \brief Equivalent to `findLongestPrefixMatch(getEntry(tableEntry)->getName(), entrySelector)`
* \tparam EntryT \c fib::Entry or \c measurements::Entry or \c strategy_choice::Entry
* \note This overload is more efficient than
* `findLongestPrefixMatch(const Name&, const EntrySelector&)` in common cases.
@@ -184,7 +183,7 @@
return this->findLongestPrefixMatch(*nte, entrySelector);
}
- /** \brief equivalent to `findLongestPrefixMatch(pitEntry.getName(), entrySelector)`
+ /** \brief Equivalent to `findLongestPrefixMatch(pitEntry.getName(), entrySelector)`
* \note This overload is more efficient than
* `findLongestPrefixMatch(const Name&, const EntrySelector&)` in common cases.
* \warning Undefined behavior may occur if \p pitEntry is not attached to this name tree.
@@ -193,7 +192,7 @@
findLongestPrefixMatch(const pit::Entry& pitEntry,
const EntrySelector& entrySelector = AnyEntry()) const;
- /** \brief all-prefixes match lookup
+ /** \brief All-prefixes match lookup
* \return a range where every entry has a name that is a prefix of \p name ,
* and matches \p entrySelector.
*
@@ -219,7 +218,7 @@
public: // enumeration
using const_iterator = Iterator;
- /** \brief enumerate all entries
+ /** \brief Enumerate all entries
* \return a range where every entry matches \p entrySelector
*
* Example:
@@ -236,7 +235,7 @@
Range
fullEnumerate(const EntrySelector& entrySelector = AnyEntry()) const;
- /** \brief enumerate all entries under a prefix
+ /** \brief Enumerate all entries under a prefix
* \return a range where every entry has a name that starts with \p prefix,
* and matches \p entrySubTreeSelector.
*
diff --git a/daemon/table/network-region-table.cpp b/daemon/table/network-region-table.cpp
index 828a35b..c7e9cea 100644
--- a/daemon/table/network-region-table.cpp
+++ b/daemon/table/network-region-table.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2017, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,7 +24,6 @@
*/
#include "network-region-table.hpp"
-#include <boost/range/adaptor/map.hpp>
namespace nfd {
diff --git a/daemon/table/pit-entry.cpp b/daemon/table/pit-entry.cpp
index 53929e6..4f6f3f4 100644
--- a/daemon/table/pit-entry.cpp
+++ b/daemon/table/pit-entry.cpp
@@ -24,16 +24,14 @@
*/
#include "pit-entry.hpp"
+
#include <algorithm>
namespace nfd {
namespace pit {
Entry::Entry(const Interest& interest)
- : isSatisfied(false)
- , dataFreshnessPeriod(0_ms)
- , m_interest(interest.shared_from_this())
- , m_nameTreeEntry(nullptr)
+ : m_interest(interest.shared_from_this())
{
}
diff --git a/daemon/table/pit-entry.hpp b/daemon/table/pit-entry.hpp
index 5a814bd..42334f0 100644
--- a/daemon/table/pit-entry.hpp
+++ b/daemon/table/pit-entry.hpp
@@ -40,15 +40,15 @@
namespace pit {
-/** \brief an unordered collection of in-records
+/** \brief An unordered collection of in-records
*/
typedef std::list<InRecord> InRecordCollection;
-/** \brief an unordered collection of out-records
+/** \brief An unordered collection of out-records
*/
typedef std::list<OutRecord> OutRecordCollection;
-/** \brief an Interest table entry
+/** \brief An Interest table entry
*
* An Interest table entry represents either a pending Interest or a recently satisfied Interest.
* Each entry contains a collection of in-records, a collection of out-records,
@@ -133,7 +133,7 @@
}
/** \brief get the in-record for \p face and \p endpointId
- * \return an iterator to the in-record, or .in_end() if it does not exist
+ * \return an iterator to the in-record, or in_end() if it does not exist
*/
InRecordCollection::iterator
getInRecord(const Face& face, EndpointId endpointId);
@@ -200,7 +200,7 @@
}
/** \brief get the out-record for \p face and \p endpointId
- * \return an iterator to the out-record, or .out_end() if it does not exist
+ * \return an iterator to the out-record, or out_end() if it does not exist
*/
OutRecordCollection::iterator
getOutRecord(const Face& face, EndpointId endpointId);
@@ -223,27 +223,27 @@
deleteInOutRecordsByFace(const Face& face);
public:
- /** \brief expiry timer
+ /** \brief Expiry timer
*
* This timer is used in forwarding pipelines to delete the entry
*/
scheduler::EventId expiryTimer;
- /** \brief indicate if PIT entry is satisfied
+ /** \brief Indicates whether this PIT entry is satisfied
*/
- bool isSatisfied;
+ bool isSatisfied = false;
/** \brief Data freshness period
* \note This field is meaningful only if isSatisfied is true
*/
- time::milliseconds dataFreshnessPeriod;
+ time::milliseconds dataFreshnessPeriod = 0_ms;
private:
shared_ptr<const Interest> m_interest;
InRecordCollection m_inRecords;
OutRecordCollection m_outRecords;
- name_tree::Entry* m_nameTreeEntry;
+ name_tree::Entry* m_nameTreeEntry = nullptr;
friend class name_tree::Entry;
};
diff --git a/daemon/table/pit-face-record.cpp b/daemon/table/pit-face-record.cpp
index 212ad23..d58ec96 100644
--- a/daemon/table/pit-face-record.cpp
+++ b/daemon/table/pit-face-record.cpp
@@ -28,28 +28,18 @@
namespace nfd {
namespace pit {
-FaceRecord::FaceRecord(Face& face, EndpointId endpointId)
- : m_face(face)
- , m_endpointId(endpointId)
- , m_lastNonce(0)
- , m_lastRenewed(time::steady_clock::TimePoint::min())
- , m_expiry(time::steady_clock::TimePoint::min())
-{
-}
-
void
FaceRecord::update(const Interest& interest)
{
m_lastNonce = interest.getNonce();
m_lastRenewed = time::steady_clock::now();
- time::milliseconds lifetime = interest.getInterestLifetime();
- if (lifetime < time::milliseconds::zero()) {
+ auto lifetime = interest.getInterestLifetime();
+ if (lifetime < 0_ms) {
lifetime = ndn::DEFAULT_INTEREST_LIFETIME;
}
m_expiry = m_lastRenewed + lifetime;
}
-
} // namespace pit
} // namespace nfd
diff --git a/daemon/table/pit-face-record.hpp b/daemon/table/pit-face-record.hpp
index 8f4132c..0c76530 100644
--- a/daemon/table/pit-face-record.hpp
+++ b/daemon/table/pit-face-record.hpp
@@ -32,33 +32,51 @@
namespace nfd {
namespace pit {
-/** \brief contains information about an Interest
- * on an incoming or outgoing face
+/** \brief Contains information about an Interest on an incoming or outgoing face
* \note This is an implementation detail to extract common functionality
* of InRecord and OutRecord
*/
class FaceRecord : public StrategyInfoHost
{
public:
- FaceRecord(Face& face, EndpointId endpointId);
+ FaceRecord(Face& face, EndpointId endpointId)
+ : m_face(face)
+ , m_endpointId(endpointId)
+ {
+ }
Face&
- getFace() const;
+ getFace() const
+ {
+ return m_face;
+ }
EndpointId
- getEndpointId() const;
+ getEndpointId() const
+ {
+ return m_endpointId;
+ }
uint32_t
- getLastNonce() const;
+ getLastNonce() const
+ {
+ return m_lastNonce;
+ }
time::steady_clock::TimePoint
- getLastRenewed() const;
+ getLastRenewed() const
+ {
+ return m_lastRenewed;
+ }
- /** \brief gives the time point this record expires
+ /** \brief Returns the time point at which this record expires
* \return getLastRenewed() + InterestLifetime
*/
time::steady_clock::TimePoint
- getExpiry() const;
+ getExpiry() const
+ {
+ return m_expiry;
+ }
/** \brief updates lastNonce, lastRenewed, expiry fields
*/
@@ -68,41 +86,11 @@
private:
Face& m_face;
EndpointId m_endpointId;
- uint32_t m_lastNonce;
- time::steady_clock::TimePoint m_lastRenewed;
- time::steady_clock::TimePoint m_expiry;
+ uint32_t m_lastNonce = 0;
+ time::steady_clock::TimePoint m_lastRenewed = time::steady_clock::TimePoint::min();
+ time::steady_clock::TimePoint m_expiry = time::steady_clock::TimePoint::min();
};
-inline Face&
-FaceRecord::getFace() const
-{
- return m_face;
-}
-
-inline EndpointId
-FaceRecord::getEndpointId() const
-{
- return m_endpointId;
-}
-
-inline uint32_t
-FaceRecord::getLastNonce() const
-{
- return m_lastNonce;
-}
-
-inline time::steady_clock::TimePoint
-FaceRecord::getLastRenewed() const
-{
- return m_lastRenewed;
-}
-
-inline time::steady_clock::TimePoint
-FaceRecord::getExpiry() const
-{
- return m_expiry;
-}
-
} // namespace pit
} // namespace nfd
diff --git a/daemon/table/pit-in-record.cpp b/daemon/table/pit-in-record.cpp
index e26e767..15131da 100644
--- a/daemon/table/pit-in-record.cpp
+++ b/daemon/table/pit-in-record.cpp
@@ -28,16 +28,11 @@
namespace nfd {
namespace pit {
-InRecord::InRecord(Face& face, EndpointId endpointId)
- : FaceRecord(face, endpointId)
-{
-}
-
void
InRecord::update(const Interest& interest)
{
- this->FaceRecord::update(interest);
- m_interest = const_cast<Interest&>(interest).shared_from_this();
+ FaceRecord::update(interest);
+ m_interest = interest.shared_from_this();
}
} // namespace pit
diff --git a/daemon/table/pit-in-record.hpp b/daemon/table/pit-in-record.hpp
index f03c608..002537b 100644
--- a/daemon/table/pit-in-record.hpp
+++ b/daemon/table/pit-in-record.hpp
@@ -31,30 +31,27 @@
namespace nfd {
namespace pit {
-/** \brief contains information about an Interest from an incoming face
+/** \brief Contains information about an Interest from an incoming face
*/
class InRecord : public FaceRecord
{
public:
- InRecord(Face& face, EndpointId endpointId);
+ using FaceRecord::FaceRecord;
+
+ const Interest&
+ getInterest() const
+ {
+ BOOST_ASSERT(m_interest != nullptr);
+ return *m_interest;
+ }
void
update(const Interest& interest);
- const Interest&
- getInterest() const;
-
private:
shared_ptr<const Interest> m_interest;
};
-inline const Interest&
-InRecord::getInterest() const
-{
- BOOST_ASSERT(static_cast<bool>(m_interest));
- return *m_interest;
-}
-
} // namespace pit
} // namespace nfd
diff --git a/daemon/table/pit-out-record.cpp b/daemon/table/pit-out-record.cpp
index 5a42151..e86f440 100644
--- a/daemon/table/pit-out-record.cpp
+++ b/daemon/table/pit-out-record.cpp
@@ -28,11 +28,6 @@
namespace nfd {
namespace pit {
-OutRecord::OutRecord(Face& face, EndpointId endpointId)
- : FaceRecord(face, endpointId)
-{
-}
-
bool
OutRecord::setIncomingNack(const lp::Nack& nack)
{
@@ -40,7 +35,7 @@
return false;
}
- m_incomingNack.reset(new lp::NackHeader(nack.getHeader()));
+ m_incomingNack = make_unique<lp::NackHeader>(nack.getHeader());
return true;
}
diff --git a/daemon/table/pit-out-record.hpp b/daemon/table/pit-out-record.hpp
index 985a129..383e0c8 100644
--- a/daemon/table/pit-out-record.hpp
+++ b/daemon/table/pit-out-record.hpp
@@ -31,12 +31,12 @@
namespace nfd {
namespace pit {
-/** \brief contains information about an Interest toward an outgoing face
+/** \brief Contains information about an Interest toward an outgoing face
*/
class OutRecord : public FaceRecord
{
public:
- OutRecord(Face& face, EndpointId endpointId);
+ using FaceRecord::FaceRecord;
/** \return last NACK returned by \p getFace()
*
diff --git a/daemon/table/pit.cpp b/daemon/table/pit.cpp
index 5e26fc0..c626c3a 100644
--- a/daemon/table/pit.cpp
+++ b/daemon/table/pit.cpp
@@ -36,7 +36,6 @@
Pit::Pit(NameTree& nameTree)
: m_nameTree(nameTree)
- , m_nItems(0)
{
}
@@ -89,8 +88,8 @@
auto&& ntMatches = m_nameTree.findAllMatches(data.getName(), &nteHasPitEntries);
DataMatchResult matches;
- for (const name_tree::Entry& nte : ntMatches) {
- for (const shared_ptr<Entry>& pitEntry : nte.getPitEntries()) {
+ for (const auto& nte : ntMatches) {
+ for (const auto& pitEntry : nte.getPitEntries()) {
if (pitEntry->getInterest().matchesData(data))
matches.emplace_back(pitEntry);
}
diff --git a/daemon/table/pit.hpp b/daemon/table/pit.hpp
index eb2438b..5464e00 100644
--- a/daemon/table/pit.hpp
+++ b/daemon/table/pit.hpp
@@ -42,7 +42,7 @@
*/
using DataMatchResult = std::vector<shared_ptr<Entry>>;
-/** \brief represents the Interest Table
+/** \brief Represents the Interest Table
*/
class Pit : noncopyable
{
@@ -58,7 +58,7 @@
return m_nItems;
}
- /** \brief finds a PIT entry for Interest
+ /** \brief Finds a PIT entry for \p interest
* \param interest the Interest
* \return an existing entry with same Name and Selectors; otherwise nullptr
*/
@@ -68,7 +68,7 @@
return const_cast<Pit*>(this)->findOrInsert(interest, false).first;
}
- /** \brief inserts a PIT entry for Interest
+ /** \brief Inserts a PIT entry for \p interest
* \param interest the Interest; must be created with make_shared
* \return a new or existing entry with same Name and Selectors,
* and true for new entry, false for existing entry
@@ -79,13 +79,13 @@
return this->findOrInsert(interest, true);
}
- /** \brief performs a Data match
- * \return an iterable of all PIT entries matching data
+ /** \brief Performs a Data match
+ * \return an iterable of all PIT entries matching \p data
*/
DataMatchResult
findAllDataMatches(const Data& data) const;
- /** \brief deletes an entry
+ /** \brief Deletes an entry
*/
void
erase(Entry* entry)
@@ -93,7 +93,7 @@
this->erase(entry, true);
}
- /** \brief deletes all in-records and out-records for \p face
+ /** \brief Deletes all in-records and out-records for \p face
*/
void
deleteInOutRecordsByFace(Entry* entry, const Face& face);
@@ -104,7 +104,7 @@
/** \return an iterator to the beginning
* \note Iteration order is implementation-defined.
* \warning Undefined behavior may occur if a FIB/PIT/Measurements/StrategyChoice entry
- * is inserted or erased during enumeration.
+ * is inserted or erased during iteration.
*/
const_iterator
begin() const;
@@ -122,20 +122,20 @@
void
erase(Entry* pitEntry, bool canDeleteNte);
- /** \brief finds or inserts a PIT entry for Interest
+ /** \brief Finds or inserts a PIT entry for \p interest
* \param interest the Interest; must be created with make_shared if allowInsert
- * \param allowInsert whether inserting new entry is allowed.
+ * \param allowInsert whether inserting a new entry is allowed
* \return if allowInsert, a new or existing entry with same Name+Selectors,
* and true for new entry, false for existing entry;
* if not allowInsert, an existing entry with same Name+Selectors and false,
- * or {nullptr, true} if there's no existing entry
+ * or `{nullptr, true}` if there's no existing entry
*/
std::pair<shared_ptr<Entry>, bool>
findOrInsert(const Interest& interest, bool allowInsert);
private:
NameTree& m_nameTree;
- size_t m_nItems;
+ size_t m_nItems = 0;
};
} // namespace pit
diff --git a/daemon/table/strategy-choice-entry.cpp b/daemon/table/strategy-choice-entry.cpp
index 77302f7..1a1ea8e 100644
--- a/daemon/table/strategy-choice-entry.cpp
+++ b/daemon/table/strategy-choice-entry.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -31,7 +31,6 @@
Entry::Entry(const Name& prefix)
: m_prefix(prefix)
- , m_nameTreeEntry(nullptr)
{
}
diff --git a/daemon/table/strategy-choice-entry.hpp b/daemon/table/strategy-choice-entry.hpp
index e1f1eb3..f64d332 100644
--- a/daemon/table/strategy-choice-entry.hpp
+++ b/daemon/table/strategy-choice-entry.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -40,11 +40,12 @@
namespace strategy_choice {
-/** \brief represents a Strategy Choice entry
+/** \brief Represents a Strategy Choice entry
*/
class Entry : noncopyable
{
public:
+ explicit
Entry(const Name& prefix);
~Entry();
@@ -78,7 +79,7 @@
Name m_prefix;
unique_ptr<fw::Strategy> m_strategy;
- name_tree::Entry* m_nameTreeEntry;
+ name_tree::Entry* m_nameTreeEntry = nullptr;
friend class name_tree::Entry;
};
diff --git a/daemon/table/strategy-choice.cpp b/daemon/table/strategy-choice.cpp
index 233f367..b6cb0f7 100644
--- a/daemon/table/strategy-choice.cpp
+++ b/daemon/table/strategy-choice.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -50,7 +50,6 @@
StrategyChoice::StrategyChoice(Forwarder& forwarder)
: m_forwarder(forwarder)
, m_nameTree(m_forwarder.getNameTree())
- , m_nItems(0)
{
}
@@ -168,12 +167,12 @@
{
name_tree::Entry* nte = m_nameTree.findExactMatch(prefix);
if (nte == nullptr) {
- return {false, Name()};
+ return {false, {}};
}
Entry* entry = nte->getStrategyChoiceEntry();
if (entry == nullptr) {
- return {false, Name()};
+ return {false, {}};
}
return {true, entry->getStrategyInstanceName()};
@@ -211,12 +210,12 @@
{
NFD_LOG_TRACE("clearStrategyInfo " << nte.getName());
- for (const shared_ptr<pit::Entry>& pitEntry : nte.getPitEntries()) {
+ for (const auto& pitEntry : nte.getPitEntries()) {
pitEntry->clearStrategyInfo();
- for (const pit::InRecord& inRecord : pitEntry->getInRecords()) {
+ for (const auto& inRecord : pitEntry->getInRecords()) {
const_cast<pit::InRecord&>(inRecord).clearStrategyInfo();
}
- for (const pit::OutRecord& outRecord : pitEntry->getOutRecords()) {
+ for (const auto& outRecord : pitEntry->getOutRecords()) {
const_cast<pit::OutRecord&>(outRecord).clearStrategyInfo();
}
}
@@ -233,8 +232,7 @@
if (Strategy::areSameType(oldInstanceName, newInstanceName)) {
// same Strategy subclass type: no need to clear StrategyInfo
NFD_LOG_INFO("changeStrategy(" << entry.getPrefix() << ") "
- << oldInstanceName << " -> " << newInstanceName
- << " same-type");
+ << oldInstanceName << " -> " << newInstanceName << " same-type");
return;
}
@@ -245,7 +243,7 @@
// where entry's effective strategy is covered by the changing StrategyChoice entry
const name_tree::Entry* rootNte = m_nameTree.getEntry(entry);
BOOST_ASSERT(rootNte != nullptr);
- auto&& ntChanged = m_nameTree.partialEnumerate(entry.getPrefix(),
+ const auto& ntChanged = m_nameTree.partialEnumerate(entry.getPrefix(),
[&rootNte] (const name_tree::Entry& nte) -> std::pair<bool, bool> {
if (&nte == rootNte) {
return {true, true};
@@ -255,7 +253,7 @@
}
return {true, true};
});
- for (const name_tree::Entry& nte : ntChanged) {
+ for (const auto& nte : ntChanged) {
clearStrategyInfo(nte);
}
}
diff --git a/daemon/table/strategy-choice.hpp b/daemon/table/strategy-choice.hpp
index 5965ddc..4b1548e 100644
--- a/daemon/table/strategy-choice.hpp
+++ b/daemon/table/strategy-choice.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2018, Regents of the University of California,
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -37,7 +37,7 @@
namespace strategy_choice {
-/** \brief represents the Strategy Choice table
+/** \brief Represents the Strategy Choice table
*
* The Strategy Choice table maintains available Strategy types,
* and associates Name prefixes with Strategy types.
@@ -60,7 +60,7 @@
return m_nItems;
}
- /** \brief set the default strategy
+ /** \brief Set the default strategy
*
* This must be called by forwarder constructor.
*/
@@ -83,7 +83,7 @@
return m_status == OK || m_status == EXCEPTION;
}
- /** \brief get a status code for use in management command response
+ /** \brief Get a status code for use in management command response
*/
int
getStatusCode() const
@@ -110,7 +110,7 @@
friend std::ostream& operator<<(std::ostream&, const InsertResult&);
};
- /** \brief set strategy of \p prefix to be \p strategyName
+ /** \brief Set strategy of \p prefix to be \p strategyName
* \param prefix the name prefix to change strategy
* \param strategyName strategy instance name, may contain version and parameters;
* strategy must have been registered
@@ -119,35 +119,34 @@
InsertResult
insert(const Name& prefix, const Name& strategyName);
- /** \brief make prefix to inherit strategy from its parent
- *
- * not allowed for root prefix (ndn:/)
+ /** \brief Make prefix to inherit strategy from its parent
+ * \note Not allowed for root prefix (ndn:/)
*/
void
erase(const Name& prefix);
- /** \brief get strategy Name of prefix
+ /** \brief Get strategy Name of prefix
* \return true and strategyName at exact match, or false
*/
std::pair<bool, Name>
get(const Name& prefix) const;
public: // effective strategy
- /** \brief get effective strategy for prefix
+ /** \brief Get effective strategy for \p prefix
*/
fw::Strategy&
findEffectiveStrategy(const Name& prefix) const;
- /** \brief get effective strategy for pitEntry
+ /** \brief Get effective strategy for \p pitEntry
*
- * This is equivalent to .findEffectiveStrategy(pitEntry.getName())
+ * This is equivalent to `findEffectiveStrategy(pitEntry.getName())`
*/
fw::Strategy&
findEffectiveStrategy(const pit::Entry& pitEntry) const;
- /** \brief get effective strategy for measurementsEntry
+ /** \brief Get effective strategy for \p measurementsEntry
*
- * This is equivalent to .findEffectiveStrategy(measurementsEntry.getName())
+ * This is equivalent to `findEffectiveStrategy(measurementsEntry.getName())`
*/
fw::Strategy&
findEffectiveStrategy(const measurements::Entry& measurementsEntry) const;
@@ -194,7 +193,7 @@
private:
Forwarder& m_forwarder;
NameTree& m_nameTree;
- size_t m_nItems;
+ size_t m_nItems = 0;
};
std::ostream&
diff --git a/daemon/table/strategy-info-host.cpp b/daemon/table/strategy-info-host.cpp
deleted file mode 100644
index 4961c68..0000000
--- a/daemon/table/strategy-info-host.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014, Regents of the University of California,
- * Arizona Board of Regents,
- * Colorado State University,
- * University Pierre & Marie Curie, Sorbonne University,
- * Washington University in St. Louis,
- * Beijing Institute of Technology,
- * The University of Memphis
- *
- * This file is part of NFD (Named Data Networking Forwarding Daemon).
- * See AUTHORS.md for complete list of NFD authors and contributors.
- *
- * NFD is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation,
- * either version 3 of the License, or (at your option) any later version.
- *
- * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "strategy-info-host.hpp"
-
-namespace nfd {
-
-void
-StrategyInfoHost::clearStrategyInfo()
-{
- m_items.clear();
-}
-
-} // namespace nfd
diff --git a/daemon/table/strategy-info-host.hpp b/daemon/table/strategy-info-host.hpp
index db88558..03f42f4 100644
--- a/daemon/table/strategy-info-host.hpp
+++ b/daemon/table/strategy-info-host.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2016, Regents of the University of California,
+/*
+ * Copyright (c) 2014-2019, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -30,12 +30,12 @@
namespace nfd {
-/** \brief base class for an entity onto which StrategyInfo items may be placed
+/** \brief Base class for an entity onto which StrategyInfo items may be placed
*/
class StrategyInfoHost
{
public:
- /** \brief get a StrategyInfo item
+ /** \brief Get a StrategyInfo item
* \tparam T type of StrategyInfo, must be a subclass of fw::StrategyInfo
* \return an existing StrategyInfo item of type T, or nullptr if it does not exist
*/
@@ -53,7 +53,7 @@
return static_cast<T*>(it->second.get());
}
- /** \brief insert a StrategyInfo item
+ /** \brief Insert a StrategyInfo item
* \tparam T type of StrategyInfo, must be a subclass of fw::StrategyInfo
* \return a new or existing StrategyInfo item of type T,
* and true for new item, false for existing item
@@ -65,15 +65,15 @@
static_assert(std::is_base_of<fw::StrategyInfo, T>::value,
"T must inherit from StrategyInfo");
- unique_ptr<fw::StrategyInfo>& item = m_items[T::getTypeId()];
- bool isNew = (item == nullptr);
+ auto& item = m_items[T::getTypeId()];
+ bool isNew = item == nullptr;
if (isNew) {
- item.reset(new T(std::forward<A>(args)...));
+ item = make_unique<T>(std::forward<A>(args)...);
}
return {static_cast<T*>(item.get()), isNew};
}
- /** \brief erase a StrategyInfo item
+ /** \brief Erase a StrategyInfo item
* \tparam T type of StrategyInfo, must be a subclass of fw::StrategyInfo
* \return number of items erased
*/
@@ -87,10 +87,13 @@
return m_items.erase(T::getTypeId());
}
- /** \brief clear all StrategyInfo items
+ /** \brief Clear all StrategyInfo items
*/
void
- clearStrategyInfo();
+ clearStrategyInfo()
+ {
+ m_items.clear();
+ }
private:
std::unordered_map<int, unique_ptr<fw::StrategyInfo>> m_items;