lsa: define CoordinateLsa operator==
getCorRadius, setCorRadius, getCorTheta, setCorTheta methods are
renamed, in accordance with ndn-cxx code style recommendations.
refs #4094
Change-Id: Iaf3ebf3b895d6dc351b2f754e4a9c65713bdca3a
diff --git a/src/lsa/coordinate-lsa.cpp b/src/lsa/coordinate-lsa.cpp
index f25ab2c..be42d9e 100644
--- a/src/lsa/coordinate-lsa.cpp
+++ b/src/lsa/coordinate-lsa.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2023, The University of Memphis,
+ * Copyright (c) 2014-2024, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -38,24 +38,6 @@
wireDecode(block);
}
-bool
-CoordinateLsa::isEqualContent(const CoordinateLsa& clsa) const
-{
- if (clsa.getCorTheta().size() != m_hyperbolicAngles.size()) {
- return false;
- }
-
- std::vector<double> m_angles2 = clsa.getCorTheta();
- for (unsigned int i = 0; i < clsa.getCorTheta().size(); i++) {
- if (std::abs(m_hyperbolicAngles[i] - m_angles2[i]) > std::numeric_limits<double>::epsilon()) {
- return false;
- }
- }
-
- return (std::abs(m_hyperbolicRadius - clsa.getCorRadius()) <
- std::numeric_limits<double>::epsilon());
-}
-
template<ndn::encoding::Tag TAG>
size_t
CoordinateLsa::wireEncode(ndn::EncodingImpl<TAG>& block) const
@@ -155,10 +137,10 @@
CoordinateLsa::update(const std::shared_ptr<Lsa>& lsa)
{
auto clsa = std::static_pointer_cast<CoordinateLsa>(lsa);
- if (!isEqualContent(*clsa)) {
- m_hyperbolicRadius = clsa->getCorRadius();
+ if (*this != *clsa) {
+ m_hyperbolicRadius = clsa->getRadius();
m_hyperbolicAngles.clear();
- for (const auto& angle : clsa->getCorTheta()) {
+ for (const auto& angle : clsa->getTheta()) {
m_hyperbolicAngles.push_back(angle);
}
return {true, std::list<ndn::Name>{}, std::list<ndn::Name>{}};
diff --git a/src/lsa/coordinate-lsa.hpp b/src/lsa/coordinate-lsa.hpp
index 112e7d5..c9e3904 100644
--- a/src/lsa/coordinate-lsa.hpp
+++ b/src/lsa/coordinate-lsa.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2023, The University of Memphis,
+ * Copyright (c) 2014-2024, The University of Memphis,
* Regents of the University of California,
* Arizona Board of Regents.
*
@@ -23,6 +23,9 @@
#define NLSR_LSA_COORDINATE_LSA_HPP
#include "lsa.hpp"
+#include "utility/numeric.hpp"
+
+#include <boost/operators.hpp>
namespace nlsr {
@@ -33,7 +36,7 @@
HyperbolicRadius
HyperbolicAngle+
*/
-class CoordinateLsa : public Lsa
+class CoordinateLsa : public Lsa, private boost::equality_comparable<CoordinateLsa>
{
public:
CoordinateLsa() = default;
@@ -57,34 +60,31 @@
}
double
- getCorRadius() const
+ getRadius() const
{
return m_hyperbolicRadius;
}
void
- setCorRadius(double cr)
+ setRadius(double cr)
{
m_wire.reset();
m_hyperbolicRadius = cr;
}
- const std::vector<double>
- getCorTheta() const
+ const std::vector<double>&
+ getTheta() const
{
return m_hyperbolicAngles;
}
void
- setCorTheta(std::vector<double> ct)
+ setTheta(std::vector<double> ct)
{
m_wire.reset();
- m_hyperbolicAngles = ct;
+ m_hyperbolicAngles = std::move(ct);
}
- bool
- isEqualContent(const CoordinateLsa& clsa) const;
-
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<TAG>& block) const;
@@ -101,6 +101,20 @@
std::tuple<bool, std::list<ndn::Name>, std::list<ndn::Name>>
update(const std::shared_ptr<Lsa>& lsa) override;
+private: // non-member operators
+ // NOTE: the following "hidden friend" operators are available via
+ // argument-dependent lookup only and must be defined inline.
+ // boost::equality_comparable provides != operator.
+
+ friend bool
+ operator==(const CoordinateLsa& lhs, const CoordinateLsa& rhs)
+ {
+ return util::diffInEpsilon(lhs.m_hyperbolicRadius, rhs.m_hyperbolicRadius) &&
+ std::equal(lhs.m_hyperbolicAngles.begin(), lhs.m_hyperbolicAngles.end(),
+ rhs.m_hyperbolicAngles.begin(), rhs.m_hyperbolicAngles.end(),
+ util::diffInEpsilon);
+ }
+
private:
double m_hyperbolicRadius = 0.0;
std::vector<double> m_hyperbolicAngles;