Simplify some code with Boost.Operators
Change-Id: Ic873bcbaf6be00d5c35601cfc8090df534d815ee
diff --git a/daemon/rib/fib-update.hpp b/daemon/rib/fib-update.hpp
index fd80b89..edf6c00 100644
--- a/daemon/rib/fib-update.hpp
+++ b/daemon/rib/fib-update.hpp
@@ -28,12 +28,14 @@
#include "core/common.hpp"
+#include <boost/operators.hpp>
+
namespace nfd::rib {
/**
* \brief Represents a FIB update.
*/
-class FibUpdate
+class FibUpdate : private boost::equality_comparable<FibUpdate>
{
public:
enum Action {
@@ -57,12 +59,6 @@
lhs.action == rhs.action;
}
- friend bool
- operator!=(const FibUpdate& lhs, const FibUpdate& rhs) noexcept
- {
- return !(lhs == rhs);
- }
-
public:
Name name;
uint64_t faceId = 0;
diff --git a/daemon/rib/readvertise/readvertised-route.hpp b/daemon/rib/readvertise/readvertised-route.hpp
index a57fe70..bc2d8c1 100644
--- a/daemon/rib/readvertise/readvertised-route.hpp
+++ b/daemon/rib/readvertise/readvertised-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,
@@ -33,7 +33,8 @@
namespace nfd::rib {
-/** \brief State of a readvertised route.
+/**
+ * \brief State of a readvertised route.
*/
class ReadvertisedRoute : noncopyable
{
@@ -41,25 +42,23 @@
explicit
ReadvertisedRoute(const Name& prefix)
: prefix(prefix)
- , nRibRoutes(0)
- , retryDelay(0)
{
}
+ friend bool
+ operator<(const ReadvertisedRoute& lhs, const ReadvertisedRoute& rhs)
+ {
+ return lhs.prefix < rhs.prefix;
+ }
+
public:
Name prefix; ///< readvertised prefix
mutable ndn::security::SigningInfo signer; ///< signer for commands
- mutable size_t nRibRoutes; ///< number of RIB routes that cause the readvertisement
- mutable time::milliseconds retryDelay; ///< retry interval (not used for refresh)
+ mutable size_t nRibRoutes = 0; ///< number of RIB routes that cause the readvertisement
+ mutable time::milliseconds retryDelay = 0_ms; ///< retry interval (not used for refresh)
mutable scheduler::ScopedEventId retryEvt; ///< retry or refresh event
};
-inline bool
-operator<(const ReadvertisedRoute& lhs, const ReadvertisedRoute& rhs)
-{
- return lhs.prefix < rhs.prefix;
-}
-
using ReadvertisedRouteContainer = std::set<ReadvertisedRoute>;
} // namespace nfd::rib
diff --git a/daemon/rib/rib.cpp b/daemon/rib/rib.cpp
index 952cc9a..7288c9a 100644
--- a/daemon/rib/rib.cpp
+++ b/daemon/rib/rib.cpp
@@ -31,13 +31,6 @@
NFD_LOG_INIT(Rib);
-bool
-operator<(const RibRouteRef& lhs, const RibRouteRef& rhs)
-{
- return std::tie(lhs.entry->getName(), lhs.route->faceId, lhs.route->origin) <
- std::tie(rhs.entry->getName(), rhs.route->faceId, rhs.route->origin);
-}
-
static inline bool
sortRoutes(const Route& lhs, const Route& rhs)
{
diff --git a/daemon/rib/rib.hpp b/daemon/rib/rib.hpp
index ddfa591..795222c 100644
--- a/daemon/rib/rib.hpp
+++ b/daemon/rib/rib.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,16 +37,21 @@
class FibUpdater;
-/** \brief References a route.
+/**
+ * \brief References a route.
*/
struct RibRouteRef
{
shared_ptr<RibEntry> entry;
RibEntry::const_iterator route;
-};
-bool
-operator<(const RibRouteRef& lhs, const RibRouteRef& rhs);
+ friend bool
+ operator<(const RibRouteRef& lhs, const RibRouteRef& rhs) noexcept
+ {
+ return std::tie(lhs.entry->getName(), lhs.route->faceId, lhs.route->origin) <
+ std::tie(rhs.entry->getName(), rhs.route->faceId, rhs.route->origin);
+ }
+};
/**
* \brief Represents the Routing Information Base.
diff --git a/daemon/rib/route.hpp b/daemon/rib/route.hpp
index 5179dbf..f460487 100644
--- a/daemon/rib/route.hpp
+++ b/daemon/rib/route.hpp
@@ -40,7 +40,7 @@
/**
* \brief Represents a route for a name prefix.
*/
-class Route : public ndn::nfd::RouteFlagsTraits<Route>
+class Route : public ndn::nfd::RouteFlagsTraits<Route>, private boost::equality_comparable<Route>
{
public:
/** \brief Default constructor.
@@ -89,12 +89,6 @@
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;