Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame^] | 2 | /** |
| 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 5 | * |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame^] | 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 8 | * |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame^] | 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
| 11 | * |
| 12 | * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html> |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef NDN_EXCLUDE_H |
| 16 | #define NDN_EXCLUDE_H |
| 17 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 18 | #include "name-component.hpp" |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 19 | |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 20 | namespace ndn { |
| 21 | |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 22 | /** |
| 23 | * @brief Class to represent Exclude component in NDN interests |
| 24 | */ |
| 25 | class Exclude |
| 26 | { |
| 27 | public: |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 28 | class Error : public Tlv::Error |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 29 | { |
| 30 | public: |
| 31 | explicit |
| 32 | Error(const std::string& what) |
Alexander Afanasyev | 2a7f720 | 2014-04-23 14:25:29 -0700 | [diff] [blame] | 33 | : Tlv::Error(what) |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 34 | { |
| 35 | } |
| 36 | }; |
Alexander Afanasyev | 993a0e1 | 2014-01-03 13:51:37 -0800 | [diff] [blame] | 37 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 38 | typedef std::map< name::Component, bool /*any*/, std::greater<name::Component> > exclude_type; |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 39 | |
| 40 | typedef exclude_type::iterator iterator; |
| 41 | typedef exclude_type::const_iterator const_iterator; |
| 42 | typedef exclude_type::reverse_iterator reverse_iterator; |
| 43 | typedef exclude_type::const_reverse_iterator const_reverse_iterator; |
| 44 | |
| 45 | /** |
| 46 | * @brief Default constructor an empty exclude |
| 47 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 48 | Exclude(); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 49 | |
| 50 | /** |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 51 | * @brief Create from wire encoding |
| 52 | */ |
| 53 | explicit |
| 54 | Exclude(const Block& wire) |
| 55 | { |
| 56 | wireDecode(wire); |
| 57 | } |
| 58 | |
| 59 | /** |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 60 | * @brief Fast encoding or block size estimation |
| 61 | */ |
| 62 | template<bool T> |
| 63 | inline size_t |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 64 | wireEncode(EncodingImpl<T>& block) const; |
| 65 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 66 | /** |
| 67 | * @brief Encode to a wire format |
| 68 | */ |
| 69 | inline const Block& |
| 70 | wireEncode() const; |
| 71 | |
| 72 | /** |
| 73 | * @brief Decode from the wire format |
| 74 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 75 | inline void |
| 76 | wireDecode(const Block& wire); |
| 77 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 78 | /////////////////////////////////////////////////////////////////////////////// |
| 79 | |
| 80 | |
| 81 | /** |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 82 | * @brief Check if name component is excluded |
| 83 | * @param comp Name component to check against exclude filter |
| 84 | */ |
| 85 | bool |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 86 | isExcluded(const name::Component& comp) const; |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * @brief Exclude specific name component |
| 90 | * @param comp component to exclude |
| 91 | * @returns *this to allow chaining |
| 92 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 93 | Exclude& |
| 94 | excludeOne(const name::Component& comp); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * @brief Exclude components from range [from, to] |
| 98 | * @param from first element of the range |
| 99 | * @param to last element of the range |
| 100 | * @returns *this to allow chaining |
| 101 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 102 | Exclude& |
| 103 | excludeRange(const name::Component& from, const name::Component& to); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * @brief Exclude all components from range [/, to] |
| 107 | * @param to last element of the range |
| 108 | * @returns *this to allow chaining |
| 109 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 110 | inline Exclude& |
| 111 | excludeBefore(const name::Component& to); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 112 | |
| 113 | /** |
| 114 | * @brief Exclude all components from range [from, +Inf] |
| 115 | * @param to last element of the range |
| 116 | * @returns *this to allow chaining |
| 117 | */ |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 118 | Exclude& |
| 119 | excludeAfter(const name::Component& from); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 120 | |
| 121 | /** |
| 122 | * @brief Method to directly append exclude element |
| 123 | * @param name excluded name component |
| 124 | * @param any flag indicating if there is a postfix ANY component after the name |
| 125 | * |
| 126 | * This method is used during conversion from wire format of exclude filter |
| 127 | * |
| 128 | * If there is an error with ranges (e.g., order of components is wrong) an exception is thrown |
| 129 | */ |
Alexander Afanasyev | 993a0e1 | 2014-01-03 13:51:37 -0800 | [diff] [blame] | 130 | inline void |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 131 | appendExclude(const name::Component& name, bool any); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 132 | |
| 133 | /** |
| 134 | * @brief Check if exclude filter is empty |
| 135 | */ |
| 136 | inline bool |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 137 | empty() const; |
Alexander Afanasyev | 8548084 | 2014-01-06 14:46:54 -0800 | [diff] [blame] | 138 | |
| 139 | /** |
| 140 | * @brief Clear the exclude filter |
| 141 | */ |
| 142 | inline void |
| 143 | clear(); |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 144 | |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 145 | /** |
| 146 | * @brief Get number of exclude terms |
| 147 | */ |
| 148 | inline size_t |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 149 | size() const; |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 150 | |
| 151 | /** |
| 152 | * @brief Get begin iterator of the exclude terms |
| 153 | */ |
| 154 | inline const_iterator |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 155 | begin() const; |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 156 | |
| 157 | /** |
| 158 | * @brief Get end iterator of the exclude terms |
| 159 | */ |
| 160 | inline const_iterator |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 161 | end() const; |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 162 | |
| 163 | /** |
| 164 | * @brief Get begin iterator of the exclude terms |
| 165 | */ |
| 166 | inline const_reverse_iterator |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 167 | rbegin() const; |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 168 | |
| 169 | /** |
| 170 | * @brief Get end iterator of the exclude terms |
| 171 | */ |
| 172 | inline const_reverse_iterator |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 173 | rend() const; |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 174 | |
| 175 | /** |
| 176 | * @brief Get escaped string representation (e.g., for use in URI) of the exclude filter |
| 177 | */ |
| 178 | inline std::string |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 179 | toUri() const; |
Alexander Afanasyev | 993a0e1 | 2014-01-03 13:51:37 -0800 | [diff] [blame] | 180 | |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 181 | private: |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 182 | Exclude& |
| 183 | excludeRange(iterator fromLowerBound, iterator toLowerBound); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 184 | |
| 185 | private: |
| 186 | exclude_type m_exclude; |
Alexander Afanasyev | 993a0e1 | 2014-01-03 13:51:37 -0800 | [diff] [blame] | 187 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 188 | mutable Block m_wire; |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | std::ostream& |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 192 | operator<<(std::ostream& os, const Exclude& name); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 193 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 194 | inline Exclude& |
| 195 | Exclude::excludeBefore(const name::Component& to) |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 196 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 197 | return excludeRange(name::Component(), to); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 198 | } |
| 199 | |
Alexander Afanasyev | 993a0e1 | 2014-01-03 13:51:37 -0800 | [diff] [blame] | 200 | inline void |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 201 | Exclude::appendExclude(const name::Component& name, bool any) |
Alexander Afanasyev | 993a0e1 | 2014-01-03 13:51:37 -0800 | [diff] [blame] | 202 | { |
| 203 | m_exclude[name] = any; |
| 204 | } |
| 205 | |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 206 | inline bool |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 207 | Exclude::empty() const |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 208 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 209 | return m_exclude.empty(); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Alexander Afanasyev | 8548084 | 2014-01-06 14:46:54 -0800 | [diff] [blame] | 212 | inline void |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 213 | Exclude::clear() |
Alexander Afanasyev | 8548084 | 2014-01-06 14:46:54 -0800 | [diff] [blame] | 214 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 215 | m_exclude.clear(); |
Alexander Afanasyev | 8548084 | 2014-01-06 14:46:54 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 219 | inline size_t |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 220 | Exclude::size() const |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 221 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 222 | return m_exclude.size(); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | inline Exclude::const_iterator |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 226 | Exclude::begin() const |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 227 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 228 | return m_exclude.begin(); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | inline Exclude::const_iterator |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 232 | Exclude::end() const |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 233 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 234 | return m_exclude.end(); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | inline Exclude::const_reverse_iterator |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 238 | Exclude::rbegin() const |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 239 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 240 | return m_exclude.rbegin(); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | inline Exclude::const_reverse_iterator |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 244 | Exclude::rend() const |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 245 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 246 | return m_exclude.rend(); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | inline std::string |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 250 | Exclude::toUri() const |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 251 | { |
| 252 | std::ostringstream os; |
| 253 | os << *this; |
| 254 | return os.str(); |
| 255 | } |
| 256 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 257 | template<bool T> |
| 258 | inline size_t |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 259 | Exclude::wireEncode(EncodingImpl<T>& block) const |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 260 | { |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 261 | size_t totalLength = 0; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 262 | |
| 263 | // Exclude ::= EXCLUDE-TYPE TLV-LENGTH Any? (NameComponent (Any)?)+ |
| 264 | // Any ::= ANY-TYPE TLV-LENGTH(=0) |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 265 | |
| 266 | for (Exclude::const_iterator i = m_exclude.begin(); i != m_exclude.end(); i++) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 267 | { |
| 268 | if (i->second) |
| 269 | { |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 270 | totalLength += prependBooleanBlock(block, Tlv::Any); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 271 | } |
| 272 | if (!i->first.empty()) |
| 273 | { |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 274 | totalLength += i->first.wireEncode(block); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame] | 278 | totalLength += block.prependVarNumber(totalLength); |
| 279 | totalLength += block.prependVarNumber(Tlv::Exclude); |
| 280 | return totalLength; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 283 | inline const Block& |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 284 | Exclude::wireEncode() const |
| 285 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 286 | if (m_wire.hasWire()) |
| 287 | return m_wire; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 288 | |
| 289 | EncodingEstimator estimator; |
| 290 | size_t estimatedSize = wireEncode(estimator); |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 291 | |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 292 | EncodingBuffer buffer(estimatedSize, 0); |
| 293 | wireEncode(buffer); |
| 294 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 295 | m_wire = buffer.block(); |
| 296 | return m_wire; |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | inline void |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 300 | Exclude::wireDecode(const Block& wire) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 301 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 302 | m_wire = wire; |
| 303 | m_wire.parse(); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 304 | |
| 305 | // Exclude ::= EXCLUDE-TYPE TLV-LENGTH Any? (NameComponent (Any)?)+ |
| 306 | // Any ::= ANY-TYPE TLV-LENGTH(=0) |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 307 | |
| 308 | Block::element_const_iterator i = m_wire.elements_begin(); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 309 | if (i->type() == Tlv::Any) |
| 310 | { |
| 311 | appendExclude(name::Component(), true); |
| 312 | ++i; |
| 313 | } |
| 314 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 315 | while (i != m_wire.elements_end()) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 316 | { |
| 317 | if (i->type() != Tlv::NameComponent) |
| 318 | throw Error("Incorrect format of Exclude filter"); |
| 319 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 320 | name::Component excludedComponent(i->value(), i->value_size()); |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 321 | ++i; |
| 322 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 323 | if (i != m_wire.elements_end()) |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 324 | { |
| 325 | if (i->type() == Tlv::Any) |
| 326 | { |
| 327 | appendExclude(excludedComponent, true); |
| 328 | ++i; |
| 329 | } |
| 330 | else |
| 331 | { |
| 332 | appendExclude(excludedComponent, false); |
| 333 | } |
| 334 | } |
| 335 | else |
| 336 | { |
| 337 | appendExclude(excludedComponent, false); |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 343 | } // ndn |
| 344 | |
| 345 | #endif // NDN_EXCLUDE_H |