NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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; -*- */
2 /*
3  * Copyright (c) 2013-2018 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  *
21  * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
22  */
23 
24 #ifndef NDN_EXCLUDE_HPP
25 #define NDN_EXCLUDE_HPP
26 
27 #include "name-component.hpp"
29 
30 #include <map>
31 
32 namespace ndn {
33 
42 class Exclude
43 {
44 public:
45  class Error : public tlv::Error
46  {
47  public:
48  explicit
49  Error(const std::string& what)
50  : tlv::Error(what)
51  {
52  }
53  };
54 
58  Exclude();
59 
63  explicit
64  Exclude(const Block& wire);
65 
69  template<encoding::Tag TAG>
70  size_t
71  wireEncode(EncodingImpl<TAG>& encoder) const;
72 
76  const Block&
77  wireEncode() const;
78 
82  void
83  wireDecode(const Block& wire);
84 
88  std::string
89  toUri() const;
90 
91 public: // high-level API
96  bool
97  isExcluded(const name::Component& comp) const;
98 
104  Exclude&
105  excludeOne(const name::Component& comp);
106 
114  Exclude&
115  excludeRange(const name::Component& from, const name::Component& to);
116 
122  Exclude&
123  excludeBefore(const name::Component& to);
124 
130  Exclude&
131  excludeAfter(const name::Component& from);
132 
133 public: // EqualityComparable concept
134  bool
135  operator==(const Exclude& other) const;
136 
137  bool
138  operator!=(const Exclude& other) const;
139 
140 public: // internal storage
145  {
146  public:
152 
157  explicit
159 
160  public:
161  bool isNegInf;
163  };
164 
174  typedef std::map<ExcludeComponent, bool, std::greater<ExcludeComponent>> ExcludeMap;
175  typedef ExcludeMap::value_type Entry;
176 
177 public: // enumeration API
181  class Range
182  {
183  public:
184  Range();
185 
186  Range(bool fromInfinity, const name::Component& from, bool toInfinity, const name::Component& to);
187 
192  bool
193  isSingular() const;
194 
195  bool
196  operator==(const Exclude::Range& other) const;
197 
198  bool
199  operator!=(const Exclude::Range& other) const;
200 
201  public:
206 
212 
217 
223  };
224 
225  class const_iterator : public std::iterator<std::forward_iterator_tag, const Range>
226  {
227  public:
228  const_iterator() = default;
229 
230  const_iterator(ExcludeMap::const_reverse_iterator it, ExcludeMap::const_reverse_iterator rend);
231 
232  const Range&
233  operator*() const;
234 
235  const Range*
236  operator->() const;
237 
239  operator++();
240 
242  operator++(int);
243 
244  bool
245  operator==(const const_iterator& other) const;
246 
247  bool
248  operator!=(const const_iterator& other) const;
249 
250  private:
251  void
252  update();
253 
254  private:
255  ExcludeMap::const_reverse_iterator m_it;
256  ExcludeMap::const_reverse_iterator m_rend;
257  Range m_range;
258  friend class Exclude;
259  };
260 
262  begin() const;
263 
265  end() const;
266 
267  bool
268  empty() const;
269 
270  size_t
271  size() const;
272 
274 
275  void
276  clear();
277 
278 private:
285  template<typename T>
286  void
287  appendEntry(const T& component, bool hasAny);
288 
289  Exclude&
290  excludeRange(const ExcludeComponent& from, const name::Component& to);
291 
292 private:
293  ExcludeMap m_entries;
294  mutable Block m_wire;
295 
296  friend std::ostream&
297  operator<<(std::ostream& os, const Exclude& name);
298 };
299 
301 
302 bool
304 
305 bool
307 
308 std::ostream&
309 operator<<(std::ostream& os, const Exclude::Range& range);
310 
311 std::ostream&
312 operator<<(std::ostream& os, const Exclude& name);
313 
316 {
317  return const_iterator(m_entries.rbegin(), m_entries.rend());
318 }
319 
322 {
323  return const_iterator(m_entries.rend(), m_entries.rend());
324 }
325 
326 inline bool
328 {
329  return m_entries.empty();
330 }
331 
332 inline bool
333 Exclude::operator!=(const Exclude& other) const
334 {
335  return !(*this == other);
336 }
337 
338 inline bool
340 {
341  return !this->fromInfinity && !this->toInfinity && this->from == this->to;
342 }
343 
344 inline bool
346 {
347  return !this->operator==(other);
348 }
349 
350 inline const Exclude::Range&
352 {
353  BOOST_ASSERT(m_it != m_rend);
354  return m_range;
355 }
356 
357 inline const Exclude::Range*
359 {
360  BOOST_ASSERT(m_it != m_rend);
361  return &m_range;
362 }
363 
364 inline bool
366 {
367  return m_it == other.m_it;
368 }
369 
370 inline bool
372 {
373  return !this->operator==(other);
374 }
375 
376 } // namespace ndn
377 
378 #endif // NDN_EXCLUDE_HPP
std::string toUri() const
Get escaped string representation (e.g., for use in URI) of the exclude filter.
Definition: exclude.cpp:347
bool operator==(const Exclude::Range &other) const
Definition: exclude.cpp:73
const Range & operator*() const
Definition: exclude.hpp:351
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:250
friend std::ostream & operator<<(std::ostream &os, const Exclude &name)
Definition: exclude.cpp:332
either a name::Component or "negative infinity"
Definition: exclude.hpp:144
represent an excluded component or range
Definition: exclude.hpp:181
bool empty() const
Definition: exclude.hpp:327
const_iterator & operator++()
Definition: exclude.cpp:382
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:337
name::Component from
from component (inclusive)
Definition: exclude.hpp:211
bool toInfinity
to positive infinity?
Definition: exclude.hpp:216
const_iterator end() const
Definition: exclude.hpp:321
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
void clear()
Definition: exclude.cpp:367
Exclude()
Constructs an empty Exclude.
Table::const_iterator iterator
Definition: cs-internal.hpp:41
void wireDecode(const Block &wire)
Decode from the wire format.
Definition: exclude.cpp:166
Exclude & excludeOne(const name::Component &comp)
Exclude specific name component.
Definition: exclude.cpp:240
const Block & wireEncode() const
Encode to a wire format.
Definition: exclude.cpp:150
ExcludeMap::value_type Entry
Definition: exclude.hpp:175
bool operator==(const const_iterator &other) const
Definition: exclude.hpp:365
size_t size() const
Definition: exclude.cpp:361
std::map< ExcludeComponent, bool, std::greater< ExcludeComponent > > ExcludeMap
a map of exclude entries
Definition: exclude.hpp:174
bool fromInfinity
from negative infinity?
Definition: exclude.hpp:205
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Exclude)
name::Component to
to component (inclusive)
Definition: exclude.hpp:222
bool operator>(const Delegation &lhs, const Delegation &rhs)
Definition: delegation.hpp:54
Represents a name component.
bool isSingular() const
Definition: exclude.hpp:339
Exclude & excludeAfter(const name::Component &from)
Exclude all components in range [from, +Inf)
Definition: exclude.cpp:310
bool operator==(const Data &lhs, const Data &rhs)
Definition: data.cpp:328
Error(const std::string &what)
Definition: exclude.hpp:49
bool isExcluded(const name::Component &comp) const
Check if name component is excluded.
Definition: exclude.cpp:231
Exclude & excludeRange(const name::Component &from, const name::Component &to)
Exclude components in range [from, to].
Definition: exclude.cpp:256
const Range * operator->() const
Definition: exclude.hpp:358
bool operator==(const Exclude &other) const
Definition: exclude.cpp:355
const_iterator begin() const
Definition: exclude.hpp:315
bool operator!=(const Exclude::Range &other) const
Definition: exclude.hpp:345
ExcludeComponent(const name::Component &component)
implicitly construct a regular infinity ExcludeComponent
Definition: exclude.cpp:32
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
Represents Exclude selector in NDN Interest.
Definition: exclude.hpp:42
bool operator!=(const Exclude &other) const
Definition: exclude.hpp:333
bool operator!=(const const_iterator &other) const
Definition: exclude.hpp:371