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