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