exclude.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_EXCLUDE_HPP
23 #define NDN_EXCLUDE_HPP
24 
25 #include "name.hpp"
26 #include "c/interest-types.h"
27 
28 struct ndn_ExcludeEntry;
29 struct ndn_Exclude;
30 
31 namespace ndn {
32 
36 class Exclude {
37 public:
42  : changeCount_(0)
43  {
44  }
45 
49  class Entry {
50  public:
55  : type_(ndn_Exclude_ANY)
56  {
57  }
58 
62  Entry(const uint8_t *component, size_t componentLen)
63  : type_(ndn_Exclude_COMPONENT), component_(component, componentLen)
64  {
65  }
66 
70  Entry(const Name::Component& component)
71  : type_(ndn_Exclude_COMPONENT), component_(component)
72  {
73  }
74 
80  void
81  get(struct ndn_ExcludeEntry& excludeEntryStruct) const;
82 
83  ndn_ExcludeType
84  getType() const { return type_; }
85 
86  const Name::Component&
87  getComponent() const { return component_; }
88 
89  private:
90  ndn_ExcludeType type_;
91  Name::Component component_;
92  };
93 
98  size_t
99  size() const { return entries_.size(); }
100 
106  const Exclude::Entry&
107  get(size_t i) const { return entries_[i]; }
108 
112  size_t
113  DEPRECATED_IN_NDN_CPP getEntryCount() const { return entries_.size(); }
114 
118  const Exclude::Entry&
119  DEPRECATED_IN_NDN_CPP getEntry(size_t i) const { return entries_[i]; }
120 
126  void
127  get(struct ndn_Exclude& excludeStruct) const;
128 
133  void
134  set(const struct ndn_Exclude& excludeStruct);
135 
140  Exclude&
142  {
143  entries_.push_back(Entry());
144  ++changeCount_;
145  return *this;
146  }
147 
154  Exclude&
155  appendComponent(const uint8_t *component, size_t componentLength)
156  {
157  entries_.push_back(Entry(component, componentLength));
158  ++changeCount_;
159  return *this;
160  }
161 
167  Exclude&
169  {
170  entries_.push_back(Entry(component));
171  ++changeCount_;
172  return *this;
173  }
174 
178  Exclude&
179  DEPRECATED_IN_NDN_CPP addAny() { return appendAny(); }
180 
184  Exclude&
185  DEPRECATED_IN_NDN_CPP addComponent(uint8_t *component, size_t componentLength)
186  {
187  return appendComponent(component, componentLength);
188  }
189 
193  void
195  {
196  entries_.clear();
197  ++changeCount_;
198  }
199 
206  bool
207  matches(const Name::Component& component) const;
208 
213  std::string
214  toUri() const;
215 
221  const Exclude::Entry&
222  operator [] (int i) const
223  {
224  return get(i);
225  }
226 
231  uint64_t
232  getChangeCount() const { return changeCount_; }
233 
234 private:
235  std::vector<Entry> entries_;
236  uint64_t changeCount_;
237 };
238 
239 }
240 
241 #endif
An ndn_ExcludeEntry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds a pointer to the com...
Definition: interest-types.h:40
Copyright (C) 2013-2015 Regents of the University of California.
Definition: common.hpp:35
Exclude()
Create a new Exclude with no entries.
Definition: exclude.hpp:41
Exclude & appendAny()
Append a new entry of type ndn_Exclude_ANY.
Definition: exclude.hpp:141
size_t size() const
Get the number of entries.
Definition: exclude.hpp:99
Entry()
Create an Exclude::Entry of type ndn_Exclude_ANY.
Definition: exclude.hpp:54
Entry(const Name::Component &component)
Create an Exclude::Entry of type ndn_Exclude_COMPONENT.
Definition: exclude.hpp:70
An Exclude::Entry holds an ndn_ExcludeType, and if it is a COMPONENT, it holds the component value...
Definition: exclude.hpp:49
const Exclude::Entry & operator[](int i) const
The same as get(i), get the entry at the given index.
Definition: exclude.hpp:222
An Exclude holds a vector of Exclude::Entry.
Definition: exclude.hpp:36
void clear()
Clear all the entries.
Definition: exclude.hpp:194
uint64_t getChangeCount() const
Get the change count, which is incremented each time this object is changed.
Definition: exclude.hpp:232
A Name::Component holds a read-only name component value.
Definition: name.hpp:47
Exclude & appendComponent(const uint8_t *component, size_t componentLength)
Append a new entry of type ndn_Exclude_COMPONENT, copying from component of length componentLength...
Definition: exclude.hpp:155
An ndn_Exclude holds an array of ndn_ExcludeEntry.
Definition: interest-types.h:48
Entry(const uint8_t *component, size_t componentLen)
Create an Exclude::Entry of type ndn_Exclude_COMPONENT.
Definition: exclude.hpp:62
Exclude &DEPRECATED_IN_NDN_CPP addComponent(uint8_t *component, size_t componentLength)
Definition: exclude.hpp:185
size_t DEPRECATED_IN_NDN_CPP getEntryCount() const
Definition: exclude.hpp:113
bool matches(const Name::Component &component) const
Check if the component matches any of the exclude criteria.
Definition: exclude.cpp:67
Exclude &DEPRECATED_IN_NDN_CPP addAny()
Definition: exclude.hpp:179
Exclude & appendComponent(const Name::Component &component)
Append a new entry of type ndn_Exclude_COMPONENT, taking another pointer to the Blob value...
Definition: exclude.hpp:168
const Exclude::Entry &DEPRECATED_IN_NDN_CPP getEntry(size_t i) const
Definition: exclude.hpp:119
std::string toUri() const
Encode this Exclude with elements separated by "," and ndn_Exclude_ANY shown as "*".
Definition: exclude.cpp:122
void set(const struct ndn_Exclude &excludeStruct)
Clear this Exclude, and set the entries by copying from the ndn_Exclude struct.
Definition: exclude.cpp:51