use Name everywhere
diff --git a/src/ccnx-name.cpp b/src/ccnx-name.cpp
index bc7b9bd..ce5f270 100644
--- a/src/ccnx-name.cpp
+++ b/src/ccnx-name.cpp
@@ -4,6 +4,7 @@
#include <boost/algorithm/string/join.hpp>
namespace Ccnx{
+CcnxCharbufPtr CcnxCharbuf::Null;
CcnxCharbuf::CcnxCharbuf()
: m_buf(NULL)
@@ -66,6 +67,40 @@
}
}
+Name &
+Name::operator=(const Name &other)
+{
+ m_comps = other.m_comps;
+ return *this;
+}
+bool
+Name::operator==(const string &str)
+{
+ return this->toString() == str;
+}
+
+bool
+Name::operator!=(const string &str)
+{
+ return !(*this == str);
+}
+
+Name
+operator+(const Name &n1, const Name &n2)
+{
+ vector<Bytes> comps = n1.m_comps;
+ copy(n2.m_comps.begin(), n2.m_comps.end(), back_inserter(comps));
+ return Name(comps);
+}
+
+string
+Name::toString() const
+{
+ stringstream ss(stringstream::out);
+ ss << *this;
+ return ss.str();
+}
+
CcnxCharbufPtr
Name::toCcnxCharbuf() const
{
@@ -131,7 +166,7 @@
Name::getPartialName(int start, int n) const
{
int size = m_comps.size();
- if (start < 0 || start >= size || start + n > size)
+ if (start < 0 || start >= size || n > 0 && start + n > size)
{
stringstream ss(stringstream::out);
ss << "getPartialName() parameter out of range! ";
@@ -142,10 +177,21 @@
}
vector<Bytes> comps;
- for (int i = 0; i < n; i++)
+ int end;
+ if (n > 0)
{
- comps.push_back(m_comps[start + i]);
+ end = start + n;
}
+ else
+ {
+ end = size;
+ }
+
+ for (int i = start; i < end; i++)
+ {
+ comps.push_back(m_comps[i]);
+ }
+
return Name(comps);
}
@@ -163,6 +209,31 @@
return os;
}
+bool
+operator ==(const Name &n1, const Name &n2)
+{
+ stringstream ss1(stringstream::out);
+ stringstream ss2(stringstream::out);
+ ss1 << n1;
+ ss2 << n2;
+ return ss1.str() == ss2.str();
+}
+
+bool
+operator !=(const Name &n1, const Name &n2)
+{
+ return !(n1 == n2);
+}
+
+bool
+operator <(const Name &n1, const Name &n2)
+{
+ stringstream ss1(stringstream::out);
+ stringstream ss2(stringstream::out);
+ ss1 << n1;
+ ss2 << n2;
+ return ss1.str() < ss2.str();
+}
Selectors::Selectors()
: m_maxSuffixComps(-1)
@@ -185,9 +256,36 @@
m_publisherPublicKeyDigest = other.m_publisherPublicKeyDigest;
}
-CcnxCharbufPtr
-Selectors::toCcnxCharbuf()
+bool
+Selectors::operator == (const Selectors &other)
{
+ return m_maxSuffixComps == other.m_maxSuffixComps
+ && m_minSuffixComps == other.m_minSuffixComps
+ && m_answerOriginKind == other.m_answerOriginKind
+ && (m_interestLifetime - other.m_interestLifetime) < 10e-4
+ && m_scope == other.m_scope
+ && m_childSelector == other.m_childSelector;
+}
+
+bool
+Selectors::isEmpty() const
+{
+ return m_maxSuffixComps == -1
+ && m_minSuffixComps == -1
+ && m_answerOriginKind == AOK_DEFAULT
+ && (m_interestLifetime - (-1.0)) < 10e-4
+ && m_scope == -1
+ && m_childSelector == DEFAULT;
+}
+
+
+CcnxCharbufPtr
+Selectors::toCcnxCharbuf() const
+{
+ if (isEmpty())
+ {
+ return CcnxCharbuf::Null;
+ }
CcnxCharbufPtr ptr(new CcnxCharbuf());
ccn_charbuf *cbuf = ptr->getBuf();
ccn_charbuf_append_tt(cbuf, CCN_DTAG_Interest, CCN_DTAG);