NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
exclude.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
24 #ifndef NDN_EXCLUDE_H
25 #define NDN_EXCLUDE_H
26 
27 #include "name-component.hpp"
29 
30 #include <sstream>
31 #include <map>
32 
33 namespace ndn {
34 
38 class Exclude
39 {
40 public:
41  class Error : public tlv::Error
42  {
43  public:
44  explicit
45  Error(const std::string& what)
46  : tlv::Error(what)
47  {
48  }
49  };
50 
54  Exclude();
55 
59  explicit
60  Exclude(const Block& wire);
61 
65  template<encoding::Tag TAG>
66  size_t
67  wireEncode(EncodingImpl<TAG>& encoder) const;
68 
72  const Block&
73  wireEncode() const;
74 
78  void
79  wireDecode(const Block& wire);
80 
84  std::string
85  toUri() const;
86 
87 public: // high-level API
92  bool
93  isExcluded(const name::Component& comp) const;
94 
100  Exclude&
101  excludeOne(const name::Component& comp);
102 
110  Exclude&
111  excludeRange(const name::Component& from, const name::Component& to);
112 
118  Exclude&
119  excludeBefore(const name::Component& to);
120 
126  Exclude&
127  excludeAfter(const name::Component& from);
128 
129 public: // EqualityComparable concept
130  bool
131  operator==(const Exclude& other) const;
132 
133  bool
134  operator!=(const Exclude& other) const;
135 
136 public: // interal storage
141  {
142  public:
147  ExcludeComponent(const name::Component& component);
148 
153  explicit
154  ExcludeComponent(bool isNegInf);
155 
156  public:
157  bool isNegInf;
159  };
160 
170  typedef std::map<ExcludeComponent, bool, std::greater<ExcludeComponent>> ExcludeMap;
171  typedef ExcludeMap::value_type Entry;
172 
173 public: // enumeration API
177  class Range
178  {
179  public:
184  bool
185  isSingular() const;
186 
187  bool
188  operator==(const Exclude::Range& other) const;
189 
190  bool
191  operator!=(const Exclude::Range& other) const;
192 
193  public:
198 
204 
209 
215  };
216 
217  class const_iterator : public std::iterator<std::forward_iterator_tag, const Range>
218  {
219  public:
220  const_iterator() = default;
221 
222  const_iterator(ExcludeMap::const_reverse_iterator it, ExcludeMap::const_reverse_iterator rend);
223 
224  const Range&
225  operator*() const;
226 
227  const Range*
228  operator->() const;
229 
231  operator++();
232 
234  operator++(int);
235 
236  bool
237  operator==(const const_iterator& other) const;
238 
239  bool
240  operator!=(const const_iterator& other) const;
241 
242  private:
243  void
244  update();
245 
246  private:
247  ExcludeMap::const_reverse_iterator m_it;
248  ExcludeMap::const_reverse_iterator m_rend;
249  Range m_range;
250  friend class Exclude;
251  };
252 
254  begin() const;
255 
257  end() const;
258 
259  bool
260  empty() const;
261 
262  size_t
263  size() const;
264 
266 
267  void
268  clear();
269 
270 private:
277  template<typename T>
278  void
279  appendEntry(const T& component, bool hasAny);
280 
281  Exclude&
282  excludeRange(const ExcludeComponent& from, const name::Component& to);
283 
284 private:
285  ExcludeMap m_entries;
286  mutable Block m_wire;
287 
288  friend std::ostream&
289  operator<<(std::ostream& os, const Exclude& name);
290 };
291 
292 std::ostream&
293 operator<<(std::ostream& os, const Exclude& name);
294 
295 bool
297 
298 bool
300 
301 std::ostream&
302 operator<<(std::ostream& os, const Exclude::Range& range);
303 
306 {
307  return const_iterator(m_entries.rbegin(), m_entries.rend());
308 }
309 
312 {
313  return const_iterator(m_entries.rend(), m_entries.rend());
314 }
315 
316 inline bool
318 {
319  return m_entries.empty();
320 }
321 
322 inline bool
323 Exclude::operator!=(const Exclude& other) const
324 {
325  return !(*this == other);
326 }
327 
328 inline bool
330 {
331  return !this->fromInfinity && !this->toInfinity && this->from == this->to;
332 }
333 
334 inline bool
336 {
337  return !this->operator==(other);
338 }
339 
340 inline const Exclude::Range&
342 {
343  BOOST_ASSERT(m_it != m_rend);
344  return m_range;
345 }
346 
347 inline const Exclude::Range*
349 {
350  BOOST_ASSERT(m_it != m_rend);
351  return &m_range;
352 }
353 
354 inline bool
356 {
357  return m_it == other.m_it;
358 }
359 
360 inline bool
362 {
363  return !this->operator==(other);
364 }
365 
366 } // namespace ndn
367 
368 #endif // NDN_EXCLUDE_H
std::string toUri() const
Get escaped string representation (e.g., for use in URI) of the exclude filter.
Definition: exclude.cpp:339
const Range & operator*() const
Definition: exclude.hpp:341
Copyright (c) 2011-2015 Regents of the University of California.
Exclude & excludeBefore(const name::Component &to)
Exclude all components in range (-Inf, to].
Definition: exclude.cpp:236
friend std::ostream & operator<<(std::ostream &os, const Exclude &name)
Definition: exclude.cpp:318
either a name::Component or "negative infinity"
Definition: exclude.hpp:140
represent an excluded component or range
Definition: exclude.hpp:177
bool empty() const
Definition: exclude.hpp:317
name::Component from
from component (inclusive)
Definition: exclude.hpp:203
bool toInfinity
to positive infinity?
Definition: exclude.hpp:208
const_iterator end() const
Definition: exclude.hpp:311
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
void clear()
Definition: exclude.cpp:359
Exclude()
Constructs an empty Exclude.
bool operator>(const Exclude::ExcludeComponent &a, const Exclude::ExcludeComponent &b)
Definition: exclude.cpp:51
Table::const_iterator iterator
Definition: cs-internal.hpp:41
void wireDecode(const Block &wire)
Decode from the wire format.
Definition: exclude.cpp:155
Exclude & excludeOne(const name::Component &comp)
Exclude specific name component.
Definition: exclude.cpp:226
const Block & wireEncode() const
Encode to a wire format.
Definition: exclude.cpp:139
ExcludeMap::value_type Entry
Definition: exclude.hpp:171
bool operator==(const const_iterator &other) const
Definition: exclude.hpp:355
size_t size() const
Definition: exclude.cpp:353
std::map< ExcludeComponent, bool, std::greater< ExcludeComponent > > ExcludeMap
a map of exclude entries
Definition: exclude.hpp:170
bool fromInfinity
from negative infinity?
Definition: exclude.hpp:197
name::Component to
to component (inclusive)
Definition: exclude.hpp:214
Component holds a read-only name component value.
bool isSingular() const
Definition: exclude.hpp:329
Exclude & excludeAfter(const name::Component &from)
Exclude all components in range [from, +Inf)
Definition: exclude.cpp:296
Error(const std::string &what)
Definition: exclude.hpp:45
bool isExcluded(const name::Component &comp) const
Check if name component is excluded.
Definition: exclude.cpp:217
Exclude & excludeRange(const name::Component &from, const name::Component &to)
Exclude components in range [from, to].
Definition: exclude.cpp:242
const Range * operator->() const
Definition: exclude.hpp:348
bool operator==(const Exclude &other) const
Definition: exclude.cpp:347
const_iterator begin() const
Definition: exclude.hpp:305
bool operator!=(const Exclude::Range &other) const
Definition: exclude.hpp:335
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
Represents Exclude selector in NDN Interest.
Definition: exclude.hpp:38
bool operator!=(const Exclude &other) const
Definition: exclude.hpp:323
bool operator!=(const const_iterator &other) const
Definition: exclude.hpp:361