Implement Interest Exclude
diff --git a/ndn-cpp/Interest.hpp b/ndn-cpp/Interest.hpp
index ab94f99..2a3def0 100644
--- a/ndn-cpp/Interest.hpp
+++ b/ndn-cpp/Interest.hpp
@@ -11,6 +11,101 @@
#include "c/Interest.h"
namespace ndn {
+
+class ExcludeEntry {
+public:
+ /**
+ * Create an ExcludeEntry of type ndn_Exclude_ANY
+ */
+ ExcludeEntry()
+ : type_(ndn_Exclude_ANY)
+ {
+ }
+
+ /**
+ * Create an ExcludeEntry of type ndn_Exclude_COMPONENT
+ */
+ ExcludeEntry(unsigned char *component, unsigned int componentLen)
+ : type_(ndn_Exclude_COMPONENT), component_(component, component + componentLen)
+ {
+ }
+
+ /**
+ * Set the type in the excludeEntryStruct and to point to this component, without copying any memory.
+ * WARNING: The resulting pointer in excludeEntryStruct is invalid after a further use of this object which could reallocate memory.
+ * @param excludeEntryStruct the C ndn_NameComponent struct to receive the pointer.
+ */
+ void get(struct ndn_ExcludeEntry &excludeEntryStruct) const
+ {
+ excludeEntryStruct.type = type_;
+ if (type_ == ndn_Exclude_COMPONENT) {
+ excludeEntryStruct.componentLength = component_.size();
+ excludeEntryStruct.component = (unsigned char *)&component_[0];
+ }
+ }
+
+ ndn_ExcludeType getType() const { return type_; }
+
+ const std::vector<unsigned char> &getComponent() const { return component_; }
+
+private:
+ ndn_ExcludeType type_;
+ std::vector<unsigned char> component_; /**< only used if type_ is ndn_Exclude_COMPONENT */
+};
+
+class Exclude {
+public:
+ /**
+ * Create a new Exclude with no entries.
+ */
+ Exclude() {
+ }
+
+ unsigned int getEntryCount() const {
+ return entries_.size();
+ }
+
+ const ExcludeEntry &getEntry(unsigned int i) const { return entries_[i]; }
+
+ /**
+ * Set the excludeStruct to point to the entries in this exclude, without copying any memory.
+ * WARNING: The resulting pointers in excludeStruct are invalid after a further use of this object which could reallocate memory.
+ * @param excludeStruct a C ndn_Exclude struct where the entries array is already allocated.
+ */
+ void get(struct ndn_Exclude &excludeStruct) const;
+
+ /**
+ * Clear this exclude, and set the entries by copying from the ndn_Exclude struct.
+ * @param excludeStruct a C ndn_Exclude struct
+ */
+ void set(struct ndn_Exclude &excludeStruct);
+
+ /**
+ * Add a new entry of type ndn_Exclude_ANY
+ */
+ void addAny()
+ {
+ entries_.push_back(ExcludeEntry());
+ }
+
+ /**
+ * Add a new entry of type ndn_Exclude_COMPONENT, copying from component of length compnentLength
+ */
+ void addComponent(unsigned char *component, unsigned int componentLen)
+ {
+ entries_.push_back(ExcludeEntry(component, componentLen));
+ }
+
+ /**
+ * Clear all the entries.
+ */
+ void clear() {
+ entries_.clear();
+ }
+
+private:
+ std::vector<ExcludeEntry> entries_;
+};
class Interest {
public:
@@ -54,7 +149,7 @@
const std::vector<unsigned char> getPublisherPublicKeyDigest() const { return publisherPublicKeyDigest_; }
- // TODO: Implement getExclude().)
+ const Exclude &getExclude() const { return exclude_; }
int getChildSelector() const { return childSelector_; }
@@ -78,7 +173,7 @@
int minSuffixComponents_;
int maxSuffixComponents_;
std::vector<unsigned char> publisherPublicKeyDigest_;
- // TODO: implement exclude
+ Exclude exclude_;
int childSelector_;
int answerOriginKind_;
int scope_;