table: add more `noexcept`
Also merge fib-nexthop.hpp into fib-entry.hpp
Change-Id: Iec2fb90ede446f5b8d326c882904c70db45b87d6
diff --git a/daemon/fw/algorithm.cpp b/daemon/fw/algorithm.cpp
index cdc432b..d82f607 100644
--- a/daemon/fw/algorithm.cpp
+++ b/daemon/fw/algorithm.cpp
@@ -25,6 +25,7 @@
#include "algorithm.hpp"
#include "scope-prefix.hpp"
+#include "face/face.hpp"
namespace nfd::fw {
diff --git a/daemon/fw/asf-measurements.hpp b/daemon/fw/asf-measurements.hpp
index 10c081c..75a3c2b 100644
--- a/daemon/fw/asf-measurements.hpp
+++ b/daemon/fw/asf-measurements.hpp
@@ -26,6 +26,7 @@
#ifndef NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP
#define NFD_DAEMON_FW_ASF_MEASUREMENTS_HPP
+#include "face/face-common.hpp"
#include "fw/strategy-info.hpp"
#include "table/measurements-accessor.hpp"
diff --git a/daemon/fw/asf-probing-module.cpp b/daemon/fw/asf-probing-module.cpp
index d186d22..a465a5b 100644
--- a/daemon/fw/asf-probing-module.cpp
+++ b/daemon/fw/asf-probing-module.cpp
@@ -26,6 +26,7 @@
#include "asf-probing-module.hpp"
#include "algorithm.hpp"
#include "common/global.hpp"
+#include "face/face.hpp"
#include <ndn-cxx/util/random.hpp>
diff --git a/daemon/table/fib-entry.cpp b/daemon/table/fib-entry.cpp
index cb97ea2..3ca8def 100644
--- a/daemon/table/fib-entry.cpp
+++ b/daemon/table/fib-entry.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California,
+ * Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -33,16 +33,14 @@
}
NextHopList::iterator
-Entry::findNextHop(const Face& face)
+Entry::findNextHop(const Face& face) noexcept
{
return std::find_if(m_nextHops.begin(), m_nextHops.end(),
- [&face] (const NextHop& nexthop) {
- return &nexthop.getFace() == &face;
- });
+ [&face] (const NextHop& nexthop) { return &nexthop.getFace() == &face; });
}
bool
-Entry::hasNextHop(const Face& face) const
+Entry::hasNextHop(const Face& face) const noexcept
{
return const_cast<Entry*>(this)->findNextHop(face) != m_nextHops.end();
}
@@ -50,7 +48,7 @@
std::pair<NextHopList::iterator, bool>
Entry::addOrUpdateNextHop(Face& face, uint64_t cost)
{
- auto it = this->findNextHop(face);
+ auto it = findNextHop(face);
bool isNew = false;
if (it == m_nextHops.end()) {
m_nextHops.emplace_back(face);
@@ -67,7 +65,7 @@
bool
Entry::removeNextHop(const Face& face)
{
- auto it = this->findNextHop(face);
+ auto it = findNextHop(face);
if (it != m_nextHops.end()) {
m_nextHops.erase(it);
return true;
diff --git a/daemon/table/fib-entry.hpp b/daemon/table/fib-entry.hpp
index 03a2c2e..fe49ecc 100644
--- a/daemon/table/fib-entry.hpp
+++ b/daemon/table/fib-entry.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2022, Regents of the University of California,
+ * Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -26,23 +26,60 @@
#ifndef NFD_DAEMON_TABLE_FIB_ENTRY_HPP
#define NFD_DAEMON_TABLE_FIB_ENTRY_HPP
-#include "fib-nexthop.hpp"
+#include "core/common.hpp"
-namespace nfd::name_tree {
+namespace nfd {
+
+namespace face {
+class Face;
+} // namespace face
+using face::Face;
+
+namespace name_tree {
class Entry;
-} // namespace nfd::name_tree
+} // namespace name_tree
-namespace nfd::fib {
+namespace fib {
class Fib;
-/** \class nfd::fib::NextHopList
- * \brief Represents a collection of nexthops.
- *
- * This type has the following member functions:
- * - `iterator<NextHop> begin()`
- * - `iterator<NextHop> end()`
- * - `size_t size()`
+/**
+ * \brief Represents a nexthop record in a FIB entry.
+ */
+class NextHop
+{
+public:
+ explicit
+ NextHop(Face& face) noexcept
+ : m_face(&face)
+ {
+ }
+
+ Face&
+ getFace() const noexcept
+ {
+ return *m_face;
+ }
+
+ uint64_t
+ getCost() const noexcept
+ {
+ return m_cost;
+ }
+
+ void
+ setCost(uint64_t cost) noexcept
+ {
+ m_cost = cost;
+ }
+
+private:
+ Face* m_face; // pointer instead of reference so that NextHop is movable
+ uint64_t m_cost = 0;
+};
+
+/**
+ * \brief A collection of nexthops in a FIB entry.
*/
using NextHopList = std::vector<NextHop>;
@@ -57,29 +94,31 @@
Entry(const Name& prefix);
const Name&
- getPrefix() const
+ getPrefix() const noexcept
{
return m_prefix;
}
const NextHopList&
- getNextHops() const
+ getNextHops() const noexcept
{
return m_nextHops;
}
- /** \return whether this Entry has any NextHop record
+ /**
+ * \brief Returns whether this Entry has any NextHop records.
*/
bool
- hasNextHops() const
+ hasNextHops() const noexcept
{
return !m_nextHops.empty();
}
- /** \return whether there is a NextHop record for \p face
+ /**
+ * \brief Returns whether there is a NextHop record for \p face.
*/
bool
- hasNextHop(const Face& face) const;
+ hasNextHop(const Face& face) const noexcept;
private:
/** \brief Adds a NextHop record to the entry.
@@ -102,7 +141,7 @@
/** \note This method is non-const because mutable iterators are needed by callers.
*/
NextHopList::iterator
- findNextHop(const Face& face);
+ findNextHop(const Face& face) noexcept;
/** \brief Sorts the nexthop list.
*/
@@ -119,6 +158,7 @@
friend Fib;
};
-} // namespace nfd::fib
+} // namespace fib
+} // namespace nfd
#endif // NFD_DAEMON_TABLE_FIB_ENTRY_HPP
diff --git a/daemon/table/fib-nexthop.hpp b/daemon/table/fib-nexthop.hpp
deleted file mode 100644
index b696cea..0000000
--- a/daemon/table/fib-nexthop.hpp
+++ /dev/null
@@ -1,70 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2014-2022, 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/>.
- */
-
-#ifndef NFD_DAEMON_TABLE_FIB_NEXTHOP_HPP
-#define NFD_DAEMON_TABLE_FIB_NEXTHOP_HPP
-
-#include "core/common.hpp"
-#include "face/face.hpp"
-
-namespace nfd::fib {
-
-/** \brief Represents a nexthop record in a FIB entry
- */
-class NextHop
-{
-public:
- explicit
- NextHop(Face& face)
- : m_face(&face)
- {
- }
-
- Face&
- getFace() const
- {
- return *m_face;
- }
-
- uint64_t
- getCost() const
- {
- return m_cost;
- }
-
- void
- setCost(uint64_t cost)
- {
- m_cost = cost;
- }
-
-private:
- Face* m_face; // pointer instead of reference so that NextHop is movable
- uint64_t m_cost = 0;
-};
-
-} // namespace nfd::fib
-
-#endif // NFD_DAEMON_TABLE_FIB_NEXTHOP_HPP
diff --git a/daemon/table/pit-entry.cpp b/daemon/table/pit-entry.cpp
index cfbbc82..53d71bd 100644
--- a/daemon/table/pit-entry.cpp
+++ b/daemon/table/pit-entry.cpp
@@ -78,7 +78,7 @@
}
InRecordCollection::iterator
-Entry::findInRecord(const Face& face)
+Entry::findInRecord(const Face& face) noexcept
{
return std::find_if(m_inRecords.begin(), m_inRecords.end(),
[&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
@@ -89,8 +89,7 @@
{
BOOST_ASSERT(this->canMatch(interest));
- auto it = std::find_if(m_inRecords.begin(), m_inRecords.end(),
- [&face] (const InRecord& inRecord) { return &inRecord.getFace() == &face; });
+ auto it = findInRecord(face);
if (it == m_inRecords.end()) {
m_inRecords.emplace_front(face);
it = m_inRecords.begin();
@@ -101,7 +100,7 @@
}
OutRecordCollection::iterator
-Entry::findOutRecord(const Face& face)
+Entry::findOutRecord(const Face& face) noexcept
{
return std::find_if(m_outRecords.begin(), m_outRecords.end(),
[&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
@@ -112,8 +111,7 @@
{
BOOST_ASSERT(this->canMatch(interest));
- auto it = std::find_if(m_outRecords.begin(), m_outRecords.end(),
- [&face] (const OutRecord& outRecord) { return &outRecord.getFace() == &face; });
+ auto it = findOutRecord(face);
if (it == m_outRecords.end()) {
m_outRecords.emplace_front(face);
it = m_outRecords.begin();
diff --git a/daemon/table/pit-entry.hpp b/daemon/table/pit-entry.hpp
index a314ae6..321f5ea 100644
--- a/daemon/table/pit-entry.hpp
+++ b/daemon/table/pit-entry.hpp
@@ -275,7 +275,7 @@
* \return an iterator to the in-record, or in_end() if it does not exist
*/
InRecordCollection::iterator
- findInRecord(const Face& face);
+ findInRecord(const Face& face) noexcept;
/**
* \brief Insert or update an in-record.
@@ -354,7 +354,7 @@
* \return an iterator to the out-record, or out_end() if it does not exist
*/
OutRecordCollection::iterator
- findOutRecord(const Face& face);
+ findOutRecord(const Face& face) noexcept;
/**
* \brief Insert or update an out-record.
diff --git a/tests/daemon/mgmt/fib-manager.t.cpp b/tests/daemon/mgmt/fib-manager.t.cpp
index 5da697b..3ba725d 100644
--- a/tests/daemon/mgmt/fib-manager.t.cpp
+++ b/tests/daemon/mgmt/fib-manager.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2023, Regents of the University of California,
+ * Copyright (c) 2014-2024, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -24,7 +24,7 @@
*/
#include "mgmt/fib-manager.hpp"
-#include "table/fib-nexthop.hpp"
+#include "table/fib-entry.hpp"
#include "manager-common-fixture.hpp"
#include "tests/daemon/face/dummy-face.hpp"