exclude: Provide EqualityComparable concept
Change-Id: Iee9a1738881be159b7944ce618869687f61e61b5
diff --git a/src/exclude.cpp b/src/exclude.cpp
index 202ab91..8e44e1a 100644
--- a/src/exclude.cpp
+++ b/src/exclude.cpp
@@ -24,6 +24,7 @@
#include "exclude.hpp"
#include <boost/static_assert.hpp>
+#include <boost/type_traits.hpp>
namespace ndn {
@@ -93,6 +94,8 @@
void
Exclude::wireDecode(const Block& wire)
{
+ clear();
+
if (wire.type() != tlv::Exclude)
throw tlv::Error("Unexpected TLV type when decoding Exclude");
@@ -173,6 +176,7 @@
if (!isExcluded(comp))
{
m_exclude.insert(std::make_pair(comp, false));
+ m_wire.reset();
}
return *this;
}
@@ -235,6 +239,7 @@
m_exclude.erase(newTo, newFrom); // remove any intermediate node, since all of the are excluded
+ m_wire.reset();
return *this;
}
@@ -258,6 +263,7 @@
m_exclude.erase(m_exclude.begin(), newFrom);
}
+ m_wire.reset();
return *this;
}
@@ -280,4 +286,23 @@
return os;
}
+std::string
+Exclude::toUri() const
+{
+ std::ostringstream os;
+ os << *this;
+ return os.str();
+}
+
+bool
+Exclude::operator==(const Exclude& other) const
+{
+ if (empty() && other.empty())
+ return true;
+ if (empty() || other.empty())
+ return false;
+
+ return wireEncode() == other.wireEncode();
+}
+
} // namespace ndn
diff --git a/src/exclude.hpp b/src/exclude.hpp
index 9435f41..1475697 100644
--- a/src/exclude.hpp
+++ b/src/exclude.hpp
@@ -137,6 +137,13 @@
void
clear();
+public: // EqualityComparable concept
+ bool
+ operator==(const Exclude& other) const;
+
+ bool
+ operator!=(const Exclude& other) const;
+
public: // low-level exclude element API
typedef std::map< name::Component, bool /*any*/, std::greater<name::Component> > exclude_type;
@@ -222,6 +229,7 @@
Exclude::clear()
{
m_exclude.clear();
+ m_wire.reset();
}
inline size_t
@@ -254,12 +262,10 @@
return m_exclude.rend();
}
-inline std::string
-Exclude::toUri() const
+inline bool
+Exclude::operator!=(const Exclude& other) const
{
- std::ostringstream os;
- os << *this;
- return os.str();
+ return !(*this == other);
}
} // ndn