Browse Source

Interest: Moved class ExcludeEntry to inner class Exclude::Entry.

pull/1/head
Jeff Thompson 12 years ago
parent
commit
f62f9f27a5
  1. 1
      CHANGELOG
  2. 124
      include/ndn-cpp/interest.hpp
  3. 2
      src/interest.cpp
  4. 2
      src/node.cpp

1
CHANGELOG

@ -10,6 +10,7 @@ Bug fixes
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.

124
include/ndn-cpp/interest.hpp

@ -20,68 +20,87 @@ struct ndn_Interest;
namespace ndn {
/**
* An ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds the component value.
* An Exclude holds a vector of ExcludeEntry.
*/
class ExcludeEntry {
class Exclude {
public:
/**
* Create an ExcludeEntry of type ndn_Exclude_ANY
* Create a new Exclude with no entries.
*/
ExcludeEntry()
: type_(ndn_Exclude_ANY)
{
Exclude() {
}
/**
* Create an ExcludeEntry of type ndn_Exclude_COMPONENT.
* An Exclude::Entry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds the component value.
*/
ExcludeEntry(uint8_t *component, size_t componentLen)
: type_(ndn_Exclude_COMPONENT), component_(component, componentLen)
{
}
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 */
};
/**
* Create an ExcludeEntry of type ndn_Exclude_COMPONENT.
* Get the number of entries.
* @return The number of entries.
*/
ExcludeEntry(const Blob& component)
: type_(ndn_Exclude_COMPONENT), component_(component)
{
}
size_t
size() const { return entries_.size(); }
/**
* 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
* Get the entry at the given index.
* @param i The index of the entry, starting from 0.
* @return The entry at the index.
*/
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 {
public:
const Exclude::Entry&
get(size_t i) const { return entries_[i]; }
/**
* Create a new Exclude with no entries.
*/
Exclude() {
}
* @deprecated Use size().
*/
size_t
getEntryCount() const {
return entries_.size();
}
getEntryCount() const { return entries_.size(); }
const ExcludeEntry&
/**
* @deprecated Use get(i).
*/
const Exclude::Entry&
getEntry(size_t i) const { return entries_[i]; }
/**
@ -106,7 +125,7 @@ public:
Exclude&
appendAny()
{
entries_.push_back(ExcludeEntry());
entries_.push_back(Entry());
return *this;
}
@ -119,7 +138,7 @@ public:
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 @@ public:
Exclude&
appendComponent(const Blob &component)
{
entries_.push_back(ExcludeEntry(component));
entries_.push_back(Entry(component));
return *this;
}
@ -151,7 +170,8 @@ public:
* Clear all the entries.
*/
void
clear() {
clear()
{
entries_.clear();
}
@ -162,7 +182,7 @@ public:
std::string toUri() const;
private:
std::vector<ExcludeEntry> entries_;
std::vector<Entry> entries_;
};
/**

2
src/interest.cpp

@ -15,7 +15,7 @@ using namespace std;
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)

2
src/node.cpp

@ -348,7 +348,7 @@ Node::PendingInterest::PendingInterest
// 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_);

Loading…
Cancel
Save