lsa: define NameLsa operator==

refs #4094

Change-Id: I99650cb3c6c452b157595a394c30227e47aa88c8
This commit is contained in:
Junxiao Shi authored and Junxiao Shi committed 2023-08-27 20:27:34 +00:00
1 parent 20377645fb
commit 2ecb059eb9
3 files changed
+19 -14

No files matched your search

-6
View File
@@ -112,12 +112,6 @@ NameLsa::wireDecode(const ndn::Block& wire)
m_npl = npl;
}
bool
NameLsa::isEqualContent(const NameLsa& other) const
{
return m_npl == other.getNpl();
}
std::string
NameLsa::toString() const
{
+14 -4
View File
@@ -25,6 +25,8 @@
#include "lsa.hpp"
#include "name-prefix-list.hpp"
#include <boost/operators.hpp>
namespace nlsr {
/*!
@@ -33,7 +35,7 @@ namespace nlsr {
Lsa
Name+
*/
class NameLsa : public Lsa
class NameLsa : public Lsa, private boost::equality_comparable<NameLsa>
{
public:
NameLsa() = default;
@@ -82,9 +84,6 @@ public:
m_npl.erase(name);
}
bool
isEqualContent(const NameLsa& other) const;
template<ndn::encoding::Tag TAG>
size_t
wireEncode(ndn::EncodingImpl<TAG>& block) const;
@@ -101,6 +100,17 @@ public:
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 NameLsa& lhs, const NameLsa& rhs)
{
return lhs.m_npl == rhs.m_npl;
}
private:
NamePrefixList m_npl;
};
+5 -4
View File
@@ -107,21 +107,22 @@ BOOST_AUTO_TEST_CASE(InitializeFromContent)
BOOST_AUTO_TEST_CASE(OperatorEquals)
{
NameLsa lsa1;
NameLsa lsa2;
ndn::Name name1("/ndn/test/name1");
ndn::Name name2("/ndn/test/name2");
ndn::Name name3("/ndn/some/other/name1");
NameLsa lsa1;
lsa1.addName(name1);
lsa1.addName(name2);
lsa1.addName(name3);
NameLsa lsa2;
lsa2.addName(name1);
lsa2.addName(name2);
lsa2.addName(name3);
BOOST_CHECK_NE(lsa1, lsa2);
BOOST_CHECK(lsa1.isEqualContent(lsa2));
lsa2.addName(name3);
BOOST_CHECK_EQUAL(lsa1, lsa2);
}
BOOST_AUTO_TEST_CASE(Update)