NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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 
109  Exclude&
110  excludeRange(const name::Component& from, const name::Component& to);
111 
117  Exclude&
118  excludeBefore(const name::Component& to);
119 
125  Exclude&
126  excludeAfter(const name::Component& from);
127 
131  bool
132  empty() const;
133 
137  void
138  clear();
139 
140 public: // EqualityComparable concept
141  bool
142  operator==(const Exclude& other) const;
143 
144  bool
145  operator!=(const Exclude& other) const;
146 
147 public: // low-level exclude element API
148  typedef std::map< name::Component, bool /*any*/, std::greater<name::Component> > exclude_type;
149 
151  typedef exclude_type::const_iterator const_iterator;
152  typedef exclude_type::reverse_iterator reverse_iterator;
153  typedef exclude_type::const_reverse_iterator const_reverse_iterator;
154 
164  void
165  appendExclude(const name::Component& name, bool any);
166 
170  size_t
171  size() const;
172 
176  const_iterator
177  begin() const;
178 
182  const_iterator
183  end() const;
184 
188  const_reverse_iterator
189  rbegin() const;
190 
194  const_reverse_iterator
195  rend() const;
196 
197 private:
198  Exclude&
199  excludeRange(iterator fromLowerBound, iterator toLowerBound);
200 
201 private:
202  exclude_type m_exclude;
203 
204  mutable Block m_wire;
205 };
206 
207 std::ostream&
208 operator<<(std::ostream& os, const Exclude& name);
209 
210 inline Exclude&
212 {
213  return excludeRange(name::Component(), to);
214 }
215 
216 inline void
218 {
219  m_exclude[name] = any;
220 }
221 
222 inline bool
224 {
225  return m_exclude.empty();
226 }
227 
228 inline void
230 {
231  m_exclude.clear();
232  m_wire.reset();
233 }
234 
235 inline size_t
237 {
238  return m_exclude.size();
239 }
240 
243 {
244  return m_exclude.begin();
245 }
246 
249 {
250  return m_exclude.end();
251 }
252 
255 {
256  return m_exclude.rbegin();
257 }
258 
261 {
262  return m_exclude.rend();
263 }
264 
265 inline bool
266 Exclude::operator!=(const Exclude& other) const
267 {
268  return !(*this == other);
269 }
270 
271 } // ndn
272 
273 #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:289
void appendExclude(const name::Component &name, bool any)
Method to directly append exclude element.
Definition: exclude.hpp:217
Copyright (c) 2011-2015 Regents of the University of California.
Exclude & excludeBefore(const name::Component &to)
Exclude all components from range [/, to].
Definition: exclude.hpp:211
bool empty() const
Check if exclude filter is empty.
Definition: exclude.hpp:223
const_reverse_iterator rend() const
Get end iterator of the exclude terms.
Definition: exclude.hpp:260
std::ostream & operator<<(std::ostream &os, const Data &data)
Definition: data.cpp:320
exclude_type::reverse_iterator reverse_iterator
Definition: exclude.hpp:152
exclude_type::const_iterator const_iterator
Definition: exclude.hpp:151
const_iterator end() const
Get end iterator of the exclude terms.
Definition: exclude.hpp:248
const_reverse_iterator rbegin() const
Get begin iterator of the exclude terms.
Definition: exclude.hpp:254
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
void clear()
Clear the exclude filter.
Definition: exclude.hpp:229
Exclude()
Default constructor an empty exclude.
Definition: exclude.cpp:38
Table::const_iterator iterator
Definition: cs-internal.hpp:41
void wireDecode(const Block &wire)
Decode from the wire format.
Definition: exclude.cpp:97
Exclude & excludeOne(const name::Component &comp)
Exclude specific name component.
Definition: exclude.cpp:172
const Block & wireEncode() const
Encode to a wire format.
Definition: exclude.cpp:81
size_t size() const
Get number of exclude terms.
Definition: exclude.hpp:236
Component holds a read-only name component value.
exclude_type::iterator iterator
Definition: exclude.hpp:150
exclude_type::const_reverse_iterator const_reverse_iterator
Definition: exclude.hpp:153
Exclude & excludeAfter(const name::Component &from)
Exclude all components from range [from, +Inf].
Definition: exclude.cpp:244
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:159
Exclude & excludeRange(const name::Component &from, const name::Component &to)
Exclude components from range [from, to].
Definition: exclude.cpp:209
bool operator==(const Exclude &other) const
Definition: exclude.cpp:297
std::map< name::Component, bool, std::greater< name::Component > > exclude_type
Definition: exclude.hpp:148
const_iterator begin() const
Get begin iterator of the exclude terms.
Definition: exclude.hpp:242
represents an error in TLV encoding or decoding
Definition: tlv.hpp:50
Class to represent Exclude component in NDN interests.
Definition: exclude.hpp:38
bool operator!=(const Exclude &other) const
Definition: exclude.hpp:266