27 #include <boost/range/adaptors.hpp> 33 , component(component1)
40 BOOST_ASSERT(isNegInf1 ==
true);
61 (this->fromInfinity || this->from == other.
from) &&
62 (this->toInfinity || this->to == other.
to);
69 return os <<
'{' << range.
from <<
'}';
76 os <<
'[' << range.
from;
85 os << range.
to <<
']';
91 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Exclude>));
95 static_assert(std::is_base_of<tlv::Error, Exclude::Error>::value,
96 "Exclude::Error must inherit from tlv::Error");
105 template<encoding::Tag TAG>
109 if (m_entries.empty()) {
110 BOOST_THROW_EXCEPTION(
Error(
"cannot encode empty Exclude selector"));
113 size_t totalLength = 0;
118 for (
const Entry& entry : m_entries) {
122 if (!entry.first.isNegInf) {
123 totalLength += entry.first.component.wireEncode(encoder);
127 totalLength += encoder.prependVarNumber(totalLength);
141 if (m_wire.hasWire())
150 m_wire = buffer.block();
160 BOOST_THROW_EXCEPTION(
tlv::Error(
"Unexpected TLV type when decoding Exclude"));
165 if (m_wire.elements_size() == 0) {
166 BOOST_THROW_EXCEPTION(
Error(
"Exclude element cannot be empty"));
174 this->appendEntry(
true,
true);
178 while (i != m_wire.elements_end()) {
184 BOOST_THROW_EXCEPTION(
Error(
"Incorrect format of Exclude filter"));
188 if (i != m_wire.elements_end() && i->type() ==
tlv::Any) {
189 this->appendEntry(component,
true);
193 this->appendEntry(component,
false);
200 Exclude::appendEntry(
const T&
component,
bool hasAny)
202 m_entries.emplace_hint(m_entries.begin(), std::piecewise_construct,
203 std::forward_as_tuple(component),
204 std::forward_as_tuple(hasAny));
219 ExcludeMap::const_iterator lb = m_entries.lower_bound(comp);
220 return lb != m_entries.end() &&
222 (!lb->first.isNegInf && lb->first.component == comp));
229 this->appendEntry(comp,
false);
264 "(for single name exclude use Exclude::excludeOne)"));
268 if (newFrom == m_entries.end() || !newFrom->second ) {
269 bool isNewEntry =
false;
270 std::tie(newFrom, isNewEntry) = m_entries.emplace(from,
true);
273 newFrom->second =
true;
280 BOOST_ASSERT(newTo != m_entries.end());
281 if (newTo == newFrom || !newTo->second) {
282 newTo = m_entries.emplace_hint(newTo, to,
false);
289 m_entries.erase(newTo, newFrom);
299 if (newFrom == m_entries.end() || !newFrom->second ) {
300 bool isNewEntry =
false;
301 std::tie(newFrom, isNewEntry) = m_entries.emplace(from,
true);
304 newFrom->second =
true;
311 m_entries.erase(m_entries.begin(), newFrom);
321 for (
const Exclude::Entry& entry : exclude.m_entries | boost::adaptors::reversed) {
322 if (!entry.first.isNegInf) {
325 entry.first.component.toUri(os);
341 std::ostringstream os;
349 return m_entries == other.m_entries;
355 return std::distance(
begin(),
end());
366 ExcludeMap::const_reverse_iterator rend)
376 bool wasInRange = m_it->second;
378 if (wasInRange && m_it != m_rend) {
379 BOOST_ASSERT(m_it->second ==
false);
395 Exclude::const_iterator::update()
397 if (m_it == m_rend) {
402 if (m_it->first.isNegInf) {
407 m_range.
from = m_it->first.component;
410 auto next = std::next(m_it);
411 if (next == m_rend) {
416 m_range.
to = next->first.component;
420 BOOST_ASSERT(!m_it->first.isNegInf);
422 m_range.
from = m_range.
to = m_it->first.component;
std::string toUri() const
Get escaped string representation (e.g., for use in URI) of the exclude filter.
bool operator==(const Exclude::Range &other) const
Copyright (c) 2011-2015 Regents of the University of California.
Exclude & excludeBefore(const name::Component &to)
Exclude all components in range (-Inf, to].
friend std::ostream & operator<<(std::ostream &os, const Exclude &name)
either a name::Component or "negative infinity"
represent an excluded component or range
EncodingImpl< EstimatorTag > EncodingEstimator
const_iterator & operator++()
name::Component from
from component (inclusive)
bool toInfinity
to positive infinity?
const_iterator end() const
void parse() const
Parse wire buffer into subblocks.
Class representing a wire element of NDN-TLV packet format.
Exclude()
Constructs an empty Exclude.
bool operator>(const Exclude::ExcludeComponent &a, const Exclude::ExcludeComponent &b)
Table::const_iterator iterator
a concept check for TLV abstraction with .wireEncode method
void wireDecode(const Block &wire)
Decode from the wire format.
Exclude & excludeOne(const name::Component &comp)
Exclude specific name component.
const Block & wireEncode() const
Encode to a wire format.
ExcludeMap::value_type Entry
EncodingImpl< EncoderTag > EncodingBuffer
size_t prependEmptyBlock(EncodingImpl< TAG > &encoder, uint32_t type)
Helper to prepend TLV block type type containing no value (i.e., a boolean block) ...
void toUri(std::ostream &os) const
Write *this to the output stream, escaping characters according to the NDN URI Scheme.
element_container::const_iterator element_const_iterator
bool fromInfinity
from negative infinity?
name::Component to
to component (inclusive)
Component holds a read-only name component value.
name::Component component
Exclude & excludeAfter(const name::Component &from)
Exclude all components in range [from, +Inf)
bool isExcluded(const name::Component &comp) const
Check if name component is excluded.
Exclude & excludeRange(const name::Component &from, const name::Component &to)
Exclude components in range [from, to].
bool operator==(const Exclude &other) const
a concept check for TLV abstraction with .wireEncode method
const_iterator begin() const
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
ExcludeComponent(const name::Component &component)
implicitly construct a regular infinity ExcludeComponent
represents an error in TLV encoding or decoding
Represents Exclude selector in NDN Interest.
Error that can be thrown from name::Component.