Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [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 | /** |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2015 Regents of the University of California. |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 4 | * |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 20 | * |
| 21 | * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html> |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 22 | */ |
| 23 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 24 | #include "exclude.hpp" |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 25 | #include "encoding/block-helpers.hpp" |
Junxiao Shi | 7284a40 | 2014-09-12 13:42:16 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | c076e6d | 2015-04-02 20:07:13 -0700 | [diff] [blame] | 27 | #include <boost/range/adaptors.hpp> |
| 28 | |
Alexander Afanasyev | 3aeeaeb | 2014-04-22 23:34:23 -0700 | [diff] [blame] | 29 | namespace ndn { |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 30 | |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 31 | BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Exclude>)); |
| 32 | BOOST_CONCEPT_ASSERT((WireEncodable<Exclude>)); |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 33 | BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Exclude>)); |
Junxiao Shi | c2b8d24 | 2014-11-04 08:35:29 -0700 | [diff] [blame] | 34 | BOOST_CONCEPT_ASSERT((WireDecodable<Exclude>)); |
| 35 | static_assert(std::is_base_of<tlv::Error, Exclude::Error>::value, |
| 36 | "Exclude::Error must inherit from tlv::Error"); |
Junxiao Shi | 7284a40 | 2014-09-12 13:42:16 -0700 | [diff] [blame] | 37 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 38 | Exclude::Exclude() |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 39 | { |
| 40 | } |
| 41 | |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 42 | Exclude::Exclude(const Block& wire) |
| 43 | { |
| 44 | wireDecode(wire); |
| 45 | } |
| 46 | |
Alexander Afanasyev | 7463389 | 2015-02-08 18:08:46 -0800 | [diff] [blame] | 47 | template<encoding::Tag TAG> |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 48 | size_t |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 49 | Exclude::wireEncode(EncodingImpl<TAG>& encoder) const |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 50 | { |
Junxiao Shi | 7284a40 | 2014-09-12 13:42:16 -0700 | [diff] [blame] | 51 | if (m_exclude.empty()) { |
| 52 | throw Error("Exclude filter cannot be empty"); |
| 53 | } |
| 54 | |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 55 | size_t totalLength = 0; |
| 56 | |
| 57 | // Exclude ::= EXCLUDE-TYPE TLV-LENGTH Any? (NameComponent (Any)?)+ |
| 58 | // Any ::= ANY-TYPE TLV-LENGTH(=0) |
| 59 | |
Alexander Afanasyev | c076e6d | 2015-04-02 20:07:13 -0700 | [diff] [blame] | 60 | for (const auto& item : m_exclude) { |
| 61 | if (item.second) { |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 62 | totalLength += prependEmptyBlock(encoder, tlv::Any); |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 63 | } |
Alexander Afanasyev | c076e6d | 2015-04-02 20:07:13 -0700 | [diff] [blame] | 64 | if (!item.first.empty() || !item.second) { |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 65 | totalLength += item.first.wireEncode(encoder); |
Alexander Afanasyev | c076e6d | 2015-04-02 20:07:13 -0700 | [diff] [blame] | 66 | } |
| 67 | } |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 68 | |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 69 | totalLength += encoder.prependVarNumber(totalLength); |
| 70 | totalLength += encoder.prependVarNumber(tlv::Exclude); |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 71 | return totalLength; |
| 72 | } |
| 73 | |
| 74 | template size_t |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 75 | Exclude::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>& encoder) const; |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 76 | |
| 77 | template size_t |
Alexander Afanasyev | d5c48e0 | 2015-06-24 11:58:14 -0700 | [diff] [blame] | 78 | Exclude::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>& encoder) const; |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 79 | |
| 80 | const Block& |
| 81 | Exclude::wireEncode() const |
| 82 | { |
| 83 | if (m_wire.hasWire()) |
| 84 | return m_wire; |
| 85 | |
| 86 | EncodingEstimator estimator; |
| 87 | size_t estimatedSize = wireEncode(estimator); |
| 88 | |
| 89 | EncodingBuffer buffer(estimatedSize, 0); |
| 90 | wireEncode(buffer); |
| 91 | |
| 92 | m_wire = buffer.block(); |
| 93 | return m_wire; |
| 94 | } |
| 95 | |
| 96 | void |
| 97 | Exclude::wireDecode(const Block& wire) |
| 98 | { |
Alexander Afanasyev | ba09605 | 2014-09-19 15:36:37 -0700 | [diff] [blame] | 99 | clear(); |
| 100 | |
Junxiao Shi | 7284a40 | 2014-09-12 13:42:16 -0700 | [diff] [blame] | 101 | if (wire.type() != tlv::Exclude) |
| 102 | throw tlv::Error("Unexpected TLV type when decoding Exclude"); |
| 103 | |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 104 | m_wire = wire; |
| 105 | m_wire.parse(); |
| 106 | |
Junxiao Shi | 7284a40 | 2014-09-12 13:42:16 -0700 | [diff] [blame] | 107 | if (m_wire.elements_size() == 0) { |
| 108 | throw Error("Exclude element cannot be empty"); |
| 109 | } |
| 110 | |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 111 | // Exclude ::= EXCLUDE-TYPE TLV-LENGTH Any? (NameComponent (Any)?)+ |
| 112 | // Any ::= ANY-TYPE TLV-LENGTH(=0) |
| 113 | |
| 114 | Block::element_const_iterator i = m_wire.elements_begin(); |
Alexander Afanasyev | c076e6d | 2015-04-02 20:07:13 -0700 | [diff] [blame] | 115 | if (i->type() == tlv::Any) { |
| 116 | appendExclude(name::Component(), true); |
| 117 | ++i; |
| 118 | } |
| 119 | |
| 120 | while (i != m_wire.elements_end()) { |
| 121 | name::Component excludedComponent; |
| 122 | try { |
| 123 | excludedComponent = std::move(name::Component(*i)); |
| 124 | } |
| 125 | catch (const name::Component::Error&) { |
| 126 | throw Error("Incorrect format of Exclude filter"); |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Alexander Afanasyev | c076e6d | 2015-04-02 20:07:13 -0700 | [diff] [blame] | 129 | ++i; |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 130 | |
Alexander Afanasyev | c076e6d | 2015-04-02 20:07:13 -0700 | [diff] [blame] | 131 | if (i != m_wire.elements_end()) { |
| 132 | if (i->type() == tlv::Any) { |
| 133 | appendExclude(excludedComponent, true); |
| 134 | ++i; |
| 135 | } |
| 136 | else { |
| 137 | appendExclude(excludedComponent, false); |
| 138 | } |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 139 | } |
Alexander Afanasyev | c076e6d | 2015-04-02 20:07:13 -0700 | [diff] [blame] | 140 | else { |
| 141 | appendExclude(excludedComponent, false); |
| 142 | } |
| 143 | } |
Junxiao Shi | 7520302 | 2014-09-11 10:01:50 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 146 | // example: ANY /b /d ANY /f |
| 147 | // |
| 148 | // ordered in map as: |
| 149 | // |
| 150 | // /f (false); /d (true); /b (false); / (true) |
| 151 | // |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 152 | // lower_bound(/) -> / (true) <-- excluded (equal) |
| 153 | // lower_bound(/a) -> / (true) <-- excluded (any) |
| 154 | // lower_bound(/b) -> /b (false) <--- excluded (equal) |
| 155 | // lower_bound(/c) -> /b (false) <--- not excluded (not equal and no ANY) |
| 156 | // lower_bound(/d) -> /d (true) <- excluded |
| 157 | // lower_bound(/e) -> /d (true) <- excluded |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 158 | bool |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 159 | Exclude::isExcluded(const name::Component& comp) const |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 160 | { |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 161 | const_iterator lowerBound = m_exclude.lower_bound(comp); |
| 162 | if (lowerBound == end()) |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 163 | return false; |
| 164 | |
| 165 | if (lowerBound->second) |
| 166 | return true; |
| 167 | else |
| 168 | return lowerBound->first == comp; |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 171 | Exclude& |
| 172 | Exclude::excludeOne(const name::Component& comp) |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 173 | { |
Alexander Afanasyev | c076e6d | 2015-04-02 20:07:13 -0700 | [diff] [blame] | 174 | if (!isExcluded(comp)) { |
| 175 | m_exclude.insert(std::make_pair(comp, false)); |
| 176 | m_wire.reset(); |
| 177 | } |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 178 | return *this; |
| 179 | } |
| 180 | |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 181 | // example: ANY /b0 /d0 ANY /f0 |
| 182 | // |
| 183 | // ordered in map as: |
| 184 | // |
| 185 | // /f0 (false); /d0 (true); /b0 (false); / (true) |
| 186 | // |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 187 | // lower_bound(/) -> / (true) <-- excluded (equal) |
| 188 | // lower_bound(/a0) -> / (true) <-- excluded (any) |
| 189 | // lower_bound(/b0) -> /b0 (false) <--- excluded (equal) |
| 190 | // lower_bound(/c0) -> /b0 (false) <--- not excluded (not equal and no ANY) |
| 191 | // lower_bound(/d0) -> /d0 (true) <- excluded |
| 192 | // lower_bound(/e0) -> /d0 (true) <- excluded |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 193 | |
| 194 | |
| 195 | // examples with desired outcomes |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 196 | // excludeRange(/, /f0) -> ANY /f0 |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 197 | // /f0 (false); / (true) |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 198 | // excludeRange(/, /f1) -> ANY /f1 |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 199 | // /f1 (false); / (true) |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 200 | // excludeRange(/a0, /e0) -> ANY /f0 |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 201 | // /f0 (false); / (true) |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 202 | // excludeRange(/a0, /e0) -> ANY /f0 |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 203 | // /f0 (false); / (true) |
| 204 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 205 | // excludeRange(/b1, /c0) -> ANY /b0 /b1 ANY /c0 /d0 ANY /f0 |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 206 | // /f0 (false); /d0 (true); /c0 (false); /b1 (true); /b0 (false); / (true) |
| 207 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 208 | Exclude& |
| 209 | Exclude::excludeRange(const name::Component& from, const name::Component& to) |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 210 | { |
Alexander Afanasyev | 3aeeaeb | 2014-04-22 23:34:23 -0700 | [diff] [blame] | 211 | if (from >= to) { |
Alexander Afanasyev | 9c57818 | 2014-05-14 17:28:28 -0700 | [diff] [blame] | 212 | throw Error("Invalid exclude range [" + from.toUri() + ", " + to.toUri() + "] " |
| 213 | "(for single name exclude use Exclude::excludeOne)"); |
Alexander Afanasyev | 3aeeaeb | 2014-04-22 23:34:23 -0700 | [diff] [blame] | 214 | } |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 215 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 216 | iterator newFrom = m_exclude.lower_bound(from); |
Alexander Afanasyev | 3aeeaeb | 2014-04-22 23:34:23 -0700 | [diff] [blame] | 217 | if (newFrom == end() || !newFrom->second /*without ANY*/) { |
| 218 | std::pair<iterator, bool> fromResult = m_exclude.insert(std::make_pair(from, true)); |
| 219 | newFrom = fromResult.first; |
| 220 | if (!fromResult.second) { |
| 221 | // this means that the lower bound is equal to the item itself. So, just update ANY flag |
| 222 | newFrom->second = true; |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 223 | } |
Alexander Afanasyev | 3aeeaeb | 2014-04-22 23:34:23 -0700 | [diff] [blame] | 224 | } |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 225 | // else |
| 226 | // nothing special if start of the range already exists with ANY flag set |
| 227 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 228 | iterator newTo = m_exclude.lower_bound(to); // !newTo cannot be end() |
Alexander Afanasyev | 3aeeaeb | 2014-04-22 23:34:23 -0700 | [diff] [blame] | 229 | if (newTo == newFrom || !newTo->second) { |
Alexander Afanasyev | c076e6d | 2015-04-02 20:07:13 -0700 | [diff] [blame] | 230 | std::pair<iterator, bool> toResult = m_exclude.insert(std::make_pair(to, false)); |
| 231 | newTo = toResult.first; |
| 232 | ++ newTo; |
Alexander Afanasyev | 3aeeaeb | 2014-04-22 23:34:23 -0700 | [diff] [blame] | 233 | } |
| 234 | // else |
| 235 | // nothing to do really |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 236 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 237 | m_exclude.erase(newTo, newFrom); // remove any intermediate node, since all of the are excluded |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 238 | |
Alexander Afanasyev | ba09605 | 2014-09-19 15:36:37 -0700 | [diff] [blame] | 239 | m_wire.reset(); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 240 | return *this; |
| 241 | } |
| 242 | |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 243 | Exclude& |
| 244 | Exclude::excludeAfter(const name::Component& from) |
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 | iterator newFrom = m_exclude.lower_bound(from); |
Alexander Afanasyev | 3aeeaeb | 2014-04-22 23:34:23 -0700 | [diff] [blame] | 247 | if (newFrom == end() || !newFrom->second /*without ANY*/) { |
| 248 | std::pair<iterator, bool> fromResult = m_exclude.insert(std::make_pair(from, true)); |
| 249 | newFrom = fromResult.first; |
| 250 | if (!fromResult.second) { |
| 251 | // this means that the lower bound is equal to the item itself. So, just update ANY flag |
| 252 | newFrom->second = true; |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 253 | } |
Alexander Afanasyev | 3aeeaeb | 2014-04-22 23:34:23 -0700 | [diff] [blame] | 254 | } |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 255 | // else |
| 256 | // nothing special if start of the range already exists with ANY flag set |
| 257 | |
Alexander Afanasyev | 3aeeaeb | 2014-04-22 23:34:23 -0700 | [diff] [blame] | 258 | if (newFrom != m_exclude.begin()) { |
| 259 | // remove any intermediate node, since all of the are excluded |
| 260 | m_exclude.erase(m_exclude.begin(), newFrom); |
| 261 | } |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 262 | |
Alexander Afanasyev | ba09605 | 2014-09-19 15:36:37 -0700 | [diff] [blame] | 263 | m_wire.reset(); |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 264 | return *this; |
| 265 | } |
| 266 | |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 267 | std::ostream& |
Alexander Afanasyev | ff2d08f | 2014-04-07 18:28:25 -0700 | [diff] [blame] | 268 | operator<<(std::ostream& os, const Exclude& exclude) |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 269 | { |
Alexander Afanasyev | c076e6d | 2015-04-02 20:07:13 -0700 | [diff] [blame] | 270 | bool isFirst = true; |
| 271 | for (const auto& item : exclude | boost::adaptors::reversed) { |
| 272 | if (!item.first.empty() || !item.second) { |
| 273 | if (!isFirst) |
| 274 | os << ","; |
| 275 | os << item.first.toUri(); |
| 276 | isFirst = false; |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 277 | } |
Alexander Afanasyev | c076e6d | 2015-04-02 20:07:13 -0700 | [diff] [blame] | 278 | if (item.second) { |
| 279 | if (!isFirst) |
| 280 | os << ","; |
Alexander Afanasyev | 3aeeaeb | 2014-04-22 23:34:23 -0700 | [diff] [blame] | 281 | os << "*"; |
Alexander Afanasyev | c076e6d | 2015-04-02 20:07:13 -0700 | [diff] [blame] | 282 | isFirst = false; |
Alexander Afanasyev | 3aeeaeb | 2014-04-22 23:34:23 -0700 | [diff] [blame] | 283 | } |
| 284 | } |
Alexander Afanasyev | b3a6af4 | 2014-01-03 13:08:28 -0800 | [diff] [blame] | 285 | return os; |
| 286 | } |
| 287 | |
Alexander Afanasyev | ba09605 | 2014-09-19 15:36:37 -0700 | [diff] [blame] | 288 | std::string |
| 289 | Exclude::toUri() const |
| 290 | { |
| 291 | std::ostringstream os; |
| 292 | os << *this; |
| 293 | return os.str(); |
| 294 | } |
| 295 | |
| 296 | bool |
| 297 | Exclude::operator==(const Exclude& other) const |
| 298 | { |
| 299 | if (empty() && other.empty()) |
| 300 | return true; |
| 301 | if (empty() || other.empty()) |
| 302 | return false; |
| 303 | |
| 304 | return wireEncode() == other.wireEncode(); |
| 305 | } |
| 306 | |
Alexander Afanasyev | 3aeeaeb | 2014-04-22 23:34:23 -0700 | [diff] [blame] | 307 | } // namespace ndn |