core+daemon: declare all equality operators as hidden friends
Change-Id: Id832ee1fb16fb6742879c8b87f56002f94745103
diff --git a/daemon/face/network-predicate.cpp b/daemon/face/network-predicate.cpp
index 340ef82..798ceeb 100644
--- a/daemon/face/network-predicate.cpp
+++ b/daemon/face/network-predicate.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-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -163,13 +163,6 @@
}
}
-bool
-NetworkPredicateBase::operator==(const NetworkPredicateBase& other) const
-{
- return this->m_whitelist == other.m_whitelist &&
- this->m_blacklist == other.m_blacklist;
-}
-
static bool
doesMatchPattern(const std::string& ifname, const std::string& pattern)
{
diff --git a/daemon/face/network-predicate.hpp b/daemon/face/network-predicate.hpp
index 5a758da..8e0bd52 100644
--- a/daemon/face/network-predicate.hpp
+++ b/daemon/face/network-predicate.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-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -57,15 +57,6 @@
assign(std::initializer_list<std::pair<std::string, std::string>> whitelist,
std::initializer_list<std::pair<std::string, std::string>> blacklist);
- bool
- operator==(const NetworkPredicateBase& other) const;
-
- bool
- operator!=(const NetworkPredicateBase& other) const
- {
- return !this->operator==(other);
- }
-
private:
virtual bool
isRuleSupported(const std::string& key) = 0;
@@ -79,6 +70,20 @@
void
parseList(std::set<std::string>& set, std::initializer_list<std::pair<std::string, std::string>> list);
+private: // non-member operators (hidden friends)
+ friend bool
+ operator==(const NetworkPredicateBase& lhs, const NetworkPredicateBase& rhs)
+ {
+ return lhs.m_whitelist == rhs.m_whitelist &&
+ lhs.m_blacklist == rhs.m_blacklist;
+ }
+
+ friend bool
+ operator!=(const NetworkPredicateBase& lhs, const NetworkPredicateBase& rhs)
+ {
+ return !(lhs == rhs);
+ }
+
NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED:
std::set<std::string> m_whitelist;
std::set<std::string> m_blacklist;
diff --git a/daemon/rib/fib-update.cpp b/daemon/rib/fib-update.cpp
index ca53565..7f48e69 100644
--- a/daemon/rib/fib-update.cpp
+++ b/daemon/rib/fib-update.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-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -28,28 +28,41 @@
namespace nfd::rib {
FibUpdate
-FibUpdate::createAddUpdate(const Name& name, const uint64_t faceId, const uint64_t cost)
+FibUpdate::createAddUpdate(const Name& name, uint64_t faceId, uint64_t cost)
{
FibUpdate update;
-
update.name = name;
update.faceId = faceId;
update.cost = cost;
update.action = ADD_NEXTHOP;
-
return update;
}
FibUpdate
-FibUpdate::createRemoveUpdate(const Name& name, const uint64_t faceId)
+FibUpdate::createRemoveUpdate(const Name& name, uint64_t faceId)
{
FibUpdate update;
-
update.name = name;
update.faceId = faceId;
update.action = REMOVE_NEXTHOP;
-
return update;
}
+std::ostream&
+operator<<(std::ostream& os, const FibUpdate& update)
+{
+ os << "FibUpdate(" << update.name << ", "
+ << "faceid: " << update.faceId << ", ";
+
+ if (update.action == FibUpdate::ADD_NEXTHOP) {
+ os << "cost: " << update.cost << ", "
+ << "action: ADD_NEXTHOP";
+ }
+ else {
+ os << "action: REMOVE_NEXTHOP";
+ }
+
+ return os << ")";
+}
+
} // namespace nfd::rib
diff --git a/daemon/rib/fib-update.hpp b/daemon/rib/fib-update.hpp
index 6eead74..fd80b89 100644
--- a/daemon/rib/fib-update.hpp
+++ b/daemon/rib/fib-update.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-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -30,64 +30,48 @@
namespace nfd::rib {
-/** \class FibUpdate
- * \brief represents a FIB update
+/**
+ * \brief Represents a FIB update.
*/
class FibUpdate
{
public:
- FibUpdate()
- : faceId(0)
- , cost(0)
- {
- }
-
- bool
- operator==(const FibUpdate& other) const
- {
- return (this->name == other.name &&
- this->faceId == other.faceId &&
- this->cost == other.cost &&
- this->action == other.action);
- }
-
- static FibUpdate
- createAddUpdate(const Name& name, const uint64_t faceId, const uint64_t cost);
-
- static FibUpdate
- createRemoveUpdate(const Name& name, const uint64_t faceId);
-
enum Action {
ADD_NEXTHOP = 0,
- REMOVE_NEXTHOP = 1
+ REMOVE_NEXTHOP = 1,
};
+ static FibUpdate
+ createAddUpdate(const Name& name, uint64_t faceId, uint64_t cost);
+
+ static FibUpdate
+ createRemoveUpdate(const Name& name, uint64_t faceId);
+
+public: // non-member operators (hidden friends)
+ friend bool
+ operator==(const FibUpdate& lhs, const FibUpdate& rhs) noexcept
+ {
+ return lhs.name == rhs.name &&
+ lhs.faceId == rhs.faceId &&
+ lhs.cost == rhs.cost &&
+ lhs.action == rhs.action;
+ }
+
+ friend bool
+ operator!=(const FibUpdate& lhs, const FibUpdate& rhs) noexcept
+ {
+ return !(lhs == rhs);
+ }
+
public:
Name name;
- uint64_t faceId;
- uint64_t cost;
+ uint64_t faceId = 0;
+ uint64_t cost = 0;
Action action;
};
-inline std::ostream&
-operator<<(std::ostream& os, const FibUpdate& update)
-{
- os << "FibUpdate("
- << " Name: " << update.name << ", "
- << "faceId: " << update.faceId << ", ";
-
- if (update.action == FibUpdate::ADD_NEXTHOP) {
- os << "cost: " << update.cost << ", "
- << "action: ADD_NEXTHOP";
- }
- else {
- os << "action: REMOVE_NEXTHOP";
- }
-
- os << ")";
-
- return os;
-}
+std::ostream&
+operator<<(std::ostream& os, const FibUpdate& update);
} // namespace nfd::rib
diff --git a/daemon/rib/fib-updater.cpp b/daemon/rib/fib-updater.cpp
index 3a7caff..75ffa4c 100644
--- a/daemon/rib/fib-updater.cpp
+++ b/daemon/rib/fib-updater.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-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -186,11 +186,10 @@
const FibUpdateSuccessCallback& onSuccess,
const FibUpdateFailureCallback& onFailure)
{
- std::string updateString = (updates.size() == 1) ? " update" : " updates";
- NFD_LOG_DEBUG("Applying " << updates.size() << updateString << " to FIB");
+ NFD_LOG_DEBUG("Applying " << updates.size() << " FIB update(s)");
for (const FibUpdate& update : updates) {
- NFD_LOG_DEBUG("Sending FIB update: " << update);
+ NFD_LOG_DEBUG("Sending " << update);
if (update.action == FibUpdate::ADD_NEXTHOP) {
sendAddNextHopUpdate(update, onSuccess, onFailure);
@@ -283,7 +282,7 @@
{
uint32_t code = response.getCode();
NFD_LOG_DEBUG("Failed to apply " << update <<
- " (code: " << code << ", error: " << response.getText() << ")");
+ " [code: " << code << ", error: " << response.getText() << "]");
if (code == ndn::nfd::Controller::ERROR_TIMEOUT && nTimeouts < MAX_NUM_TIMEOUTS) {
sendAddNextHopUpdate(update, onSuccess, onFailure, ++nTimeouts);
diff --git a/daemon/rib/rib-update.cpp b/daemon/rib/rib-update.cpp
index 343d39e..935ccce 100644
--- a/daemon/rib/rib-update.cpp
+++ b/daemon/rib/rib-update.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-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -32,14 +32,11 @@
{
switch (action) {
case RibUpdate::REGISTER:
- os << "REGISTER";
- break;
+ return os << "REGISTER";
case RibUpdate::UNREGISTER:
- os << "UNREGISTER";
- break;
+ return os << "UNREGISTER";
case RibUpdate::REMOVE_FACE:
- os << "REMOVE_FACE";
- break;
+ return os << "REMOVE_FACE";
}
return os;
}
diff --git a/daemon/rib/route.cpp b/daemon/rib/route.cpp
index 43227f1..e7c825f 100644
--- a/daemon/rib/route.cpp
+++ b/daemon/rib/route.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-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -31,6 +31,8 @@
constexpr uint64_t PA_ROUTE_COST = 2048; // cost of route created by prefix announcement
+Route::Route() = default;
+
static time::steady_clock::time_point
computeExpiration(const ndn::PrefixAnnouncement& ann)
{
@@ -59,17 +61,6 @@
{
}
-bool
-operator==(const Route& lhs, const Route& rhs)
-{
- return lhs.faceId == rhs.faceId &&
- lhs.origin == rhs.origin &&
- lhs.flags == rhs.flags &&
- lhs.cost == rhs.cost &&
- lhs.expires == rhs.expires &&
- lhs.announcement == rhs.announcement;
-}
-
std::ostream&
operator<<(std::ostream& os, const Route& route)
{
@@ -78,18 +69,19 @@
<< ", origin: " << route.origin
<< ", cost: " << route.cost
<< ", flags: " << ndn::AsHex{route.flags};
+
if (route.expires) {
os << ", expires in: " << time::duration_cast<time::milliseconds>(*route.expires - time::steady_clock::now());
}
else {
os << ", never expires";
}
+
if (route.announcement) {
os << ", announcement: (" << *route.announcement << ')';
}
- os << ')';
- return os;
+ return os << ')';
}
} // namespace nfd::rib
diff --git a/daemon/rib/route.hpp b/daemon/rib/route.hpp
index 471bdb6..5179dbf 100644
--- a/daemon/rib/route.hpp
+++ b/daemon/rib/route.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-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -37,14 +37,15 @@
namespace nfd::rib {
-/** \brief Represents a route for a name prefix.
+/**
+ * \brief Represents a route for a name prefix.
*/
class Route : public ndn::nfd::RouteFlagsTraits<Route>
{
public:
/** \brief Default constructor.
*/
- Route() = default;
+ Route();
/** \brief Construct from a prefix announcement.
* \param ann a prefix announcement that has passed verification
@@ -76,6 +77,24 @@
return flags;
}
+public: // non-member operators (hidden friends)
+ friend bool
+ operator==(const Route& lhs, const Route& rhs)
+ {
+ return lhs.faceId == rhs.faceId &&
+ lhs.origin == rhs.origin &&
+ lhs.cost == rhs.cost &&
+ lhs.flags == rhs.flags &&
+ lhs.expires == rhs.expires &&
+ lhs.announcement == rhs.announcement;
+ }
+
+ friend bool
+ operator!=(const Route& lhs, const Route& rhs)
+ {
+ return !(lhs == rhs);
+ }
+
public:
uint64_t faceId = 0;
ndn::nfd::RouteOrigin origin = ndn::nfd::ROUTE_ORIGIN_APP;
@@ -103,15 +122,6 @@
scheduler::EventId m_expirationEvent;
};
-bool
-operator==(const Route& lhs, const Route& rhs);
-
-inline bool
-operator!=(const Route& lhs, const Route& rhs)
-{
- return !(lhs == rhs);
-}
-
std::ostream&
operator<<(std::ostream& os, const Route& route);
diff --git a/daemon/table/name-tree-iterator.cpp b/daemon/table/name-tree-iterator.cpp
index ecfe40d..24c1422 100644
--- a/daemon/table/name-tree-iterator.cpp
+++ b/daemon/table/name-tree-iterator.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-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -64,12 +64,6 @@
return copy;
}
-bool
-Iterator::operator==(const Iterator& other) const
-{
- return m_entry == other.m_entry;
-}
-
std::ostream&
operator<<(std::ostream& os, const Iterator& i)
{
diff --git a/daemon/table/name-tree-iterator.hpp b/daemon/table/name-tree-iterator.hpp
index 4458a3e..fef3e6e 100644
--- a/daemon/table/name-tree-iterator.hpp
+++ b/daemon/table/name-tree-iterator.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-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -88,14 +88,14 @@
Iterator(shared_ptr<EnumerationImpl> impl, const Entry* ref);
const Entry&
- operator*() const
+ operator*() const noexcept
{
BOOST_ASSERT(m_impl != nullptr);
return *m_entry;
}
const Entry*
- operator->() const
+ operator->() const noexcept
{
BOOST_ASSERT(m_impl != nullptr);
return m_entry;
@@ -107,13 +107,16 @@
Iterator
operator++(int);
- bool
- operator==(const Iterator& other) const;
-
- bool
- operator!=(const Iterator& other) const
+ friend bool
+ operator==(const Iterator& lhs, const Iterator& rhs) noexcept
{
- return !this->operator==(other);
+ return lhs.m_entry == rhs.m_entry;
+ }
+
+ friend bool
+ operator!=(const Iterator& lhs, const Iterator& rhs) noexcept
+ {
+ return !(lhs == rhs);
}
private:
diff --git a/daemon/table/pit-iterator.hpp b/daemon/table/pit-iterator.hpp
index 2138b77..bfe0e8e 100644
--- a/daemon/table/pit-iterator.hpp
+++ b/daemon/table/pit-iterator.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-2023, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -70,16 +70,17 @@
Iterator
operator++(int);
- bool
- operator==(const Iterator& other) const
+ friend bool
+ operator==(const Iterator& lhs, const Iterator& rhs) noexcept
{
- return m_ntIt == other.m_ntIt && m_iPitEntry == other.m_iPitEntry;
+ return lhs.m_ntIt == rhs.m_ntIt &&
+ lhs.m_iPitEntry == rhs.m_iPitEntry;
}
- bool
- operator!=(const Iterator& other) const
+ friend bool
+ operator!=(const Iterator& lhs, const Iterator& rhs) noexcept
{
- return !this->operator==(other);
+ return !(lhs == rhs);
}
private: