Interest: Moved class ExcludeEntry to inner class Exclude::Entry.
diff --git a/CHANGELOG b/CHANGELOG
index 8413b39..30089dc 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -10,6 +10,7 @@
Changes
* MetaInfo: Added setFinalBlockID for Name::Component, remove unused setFinalBlockID which take uint8_t*, etc.
* Fix clang compiler warnings: Include headers, parentheses and cast explicitly.
+* Moved class ExcludeEntry to inner class Exclude::Entry.
Documentation
* Move instructions for running ./autogen.sh from configure.ac to the Development section of INSTALL.
diff --git a/include/ndn-cpp/interest.hpp b/include/ndn-cpp/interest.hpp
index 7e77165..7dfb09a 100644
--- a/include/ndn-cpp/interest.hpp
+++ b/include/ndn-cpp/interest.hpp
@@ -20,52 +20,6 @@
namespace ndn {
/**
- * An ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds the component value.
- */
-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(uint8_t *component, size_t componentLen)
- : type_(ndn_Exclude_COMPONENT), component_(component, componentLen)
- {
- }
-
- /**
- * Create an ExcludeEntry of type ndn_Exclude_COMPONENT.
- */
- ExcludeEntry(const Blob& component)
- : type_(ndn_Exclude_COMPONENT), component_(component)
- {
- }
-
- /**
- * 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;
-
- ndn_ExcludeType getType() const { return type_; }
-
- const Name::Component& getComponent() const { return component_; }
-
-private:
- ndn_ExcludeType type_;
- Name::Component component_; /**< only used if type_ is ndn_Exclude_COMPONENT */
-};
-
-/**
* An Exclude holds a vector of ExcludeEntry.
*/
class Exclude {
@@ -75,13 +29,78 @@
*/
Exclude() {
}
-
+
+ /**
+ * An Exclude::Entry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds the component value.
+ */
+ class Entry {
+ public:
+ /**
+ * Create an Exclude::Entry of type ndn_Exclude_ANY
+ */
+ Entry()
+ : type_(ndn_Exclude_ANY)
+ {
+ }
+
+ /**
+ * Create an Exclude::Entry of type ndn_Exclude_COMPONENT.
+ */
+ Entry(uint8_t *component, size_t componentLen)
+ : type_(ndn_Exclude_COMPONENT), component_(component, componentLen)
+ {
+ }
+
+ /**
+ * Create an Exclude::Entry of type ndn_Exclude_COMPONENT.
+ */
+ Entry(const Blob& component)
+ : type_(ndn_Exclude_COMPONENT), component_(component)
+ {
+ }
+
+ /**
+ * Set the type in the excludeEntryStruct and to point to this entry, 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_ExcludeEntry struct to receive the pointer
+ */
+ void
+ get(struct ndn_ExcludeEntry& excludeEntryStruct) const;
+
+ ndn_ExcludeType getType() const { return type_; }
+
+ const Name::Component& getComponent() const { return component_; }
+
+ private:
+ ndn_ExcludeType type_;
+ Name::Component component_; /**< only used if type_ is ndn_Exclude_COMPONENT */
+ };
+
+ /**
+ * Get the number of entries.
+ * @return The number of entries.
+ */
size_t
- getEntryCount() const {
- return entries_.size();
- }
+ size() const { return entries_.size(); }
- const ExcludeEntry&
+ /**
+ * Get the entry at the given index.
+ * @param i The index of the entry, starting from 0.
+ * @return The entry at the index.
+ */
+ const Exclude::Entry&
+ get(size_t i) const { return entries_[i]; }
+
+ /**
+ * @deprecated Use size().
+ */
+ size_t
+ getEntryCount() const { return entries_.size(); }
+
+ /**
+ * @deprecated Use get(i).
+ */
+ const Exclude::Entry&
getEntry(size_t i) const { return entries_[i]; }
/**
@@ -106,7 +125,7 @@
Exclude&
appendAny()
{
- entries_.push_back(ExcludeEntry());
+ entries_.push_back(Entry());
return *this;
}
@@ -119,7 +138,7 @@
Exclude&
appendComponent(uint8_t *component, size_t componentLength)
{
- entries_.push_back(ExcludeEntry(component, componentLength));
+ entries_.push_back(Entry(component, componentLength));
return *this;
}
@@ -131,7 +150,7 @@
Exclude&
appendComponent(const Blob &component)
{
- entries_.push_back(ExcludeEntry(component));
+ entries_.push_back(Entry(component));
return *this;
}
@@ -151,7 +170,8 @@
* Clear all the entries.
*/
void
- clear() {
+ clear()
+ {
entries_.clear();
}
@@ -162,7 +182,7 @@
std::string toUri() const;
private:
- std::vector<ExcludeEntry> entries_;
+ std::vector<Entry> entries_;
};
/**
diff --git a/src/interest.cpp b/src/interest.cpp
index b2ab024..b81ea6f 100644
--- a/src/interest.cpp
+++ b/src/interest.cpp
@@ -15,7 +15,7 @@
namespace ndn {
void
-ExcludeEntry::get(struct ndn_ExcludeEntry& excludeEntryStruct) const
+Exclude::Entry::get(struct ndn_ExcludeEntry& excludeEntryStruct) const
{
excludeEntryStruct.type = type_;
if (type_ == ndn_Exclude_COMPONENT)
diff --git a/src/node.cpp b/src/node.cpp
index f9076fb..83096cd 100644
--- a/src/node.cpp
+++ b/src/node.cpp
@@ -348,7 +348,7 @@
// Set up interestStruct_.
// TODO: Doesn't this belong in the Interest class?
nameComponents_.reserve(interest_->getName().getComponentCount());
- excludeEntries_.reserve(interest_->getExclude().getEntryCount());
+ excludeEntries_.reserve(interest_->getExclude().size());
ndn_Interest_initialize
(interestStruct_.get(), &nameComponents_[0], nameComponents_.capacity(), &excludeEntries_[0], excludeEntries_.capacity());
interest_->get(*interestStruct_);