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);
133 Exclude::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>& encoder)
const;
136 Exclude::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>& encoder)
const;
150 m_wire = buffer.block();
160 BOOST_THROW_EXCEPTION(
tlv::Error(
"Unexpected TLV type when decoding Exclude"));
166 BOOST_THROW_EXCEPTION(
Error(
"Exclude element cannot be empty"));
174 this->appendEntry(
true,
true);
184 BOOST_THROW_EXCEPTION(
Error(
"Incorrect format of Exclude filter"));
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);
262 if (!from.isNegInf && from.component >= to) {
263 BOOST_THROW_EXCEPTION(Error(
"Invalid exclude range [" + from.component.toUri() +
", " + to.
toUri() +
"] "
264 "(for single name exclude use Exclude::excludeOne)"));
267 ExcludeMap::iterator newFrom = m_entries.lower_bound(from);
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;
279 ExcludeMap::iterator newTo = m_entries.lower_bound(to);
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);
298 ExcludeMap::iterator newFrom = m_entries.lower_bound(from);
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) {
403 m_range.fromInfinity =
true;
406 m_range.fromInfinity =
false;
407 m_range.from = m_it->first.component;
410 auto next = std::next(m_it);
411 if (next == m_rend) {
412 m_range.toInfinity =
true;
415 m_range.toInfinity =
false;
416 m_range.to = next->first.component;
420 BOOST_ASSERT(!m_it->first.isNegInf);
421 m_range.fromInfinity = m_range.toInfinity =
false;
422 m_range.from = m_range.to = m_it->first.component;
Copyright (c) 2013-2016 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?
Class representing a wire element of NDN-TLV packet format.
Exclude()
Constructs an empty Exclude.
bool operator==(const Exclude::Range &other) const
bool operator>(const Exclude::ExcludeComponent &a, const Exclude::ExcludeComponent &b)
element_const_iterator elements_end() const
element_const_iterator elements_begin() const
a concept check for TLV abstraction with .wireEncode method
const Block & wireEncode() const
Encode to a wire format.
void wireDecode(const Block &wire)
Decode from the wire format.
Exclude & excludeOne(const name::Component &comp)
Exclude specific name component.
bool isExcluded(const name::Component &comp) const
Check if name component is excluded.
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
size_t elements_size() const
const_iterator begin() const
void reset()
Reset wire buffer of the element.
bool fromInfinity
from negative infinity?
void parse() const
Parse wire buffer into subblocks.
name::Component to
to component (inclusive)
Component holds a read-only name component value.
std::string toUri() const
Get escaped string representation (e.g., for use in URI) of the exclude filter.
bool hasWire() const
Check if the Block has fully encoded wire.
name::Component component
Exclude & excludeAfter(const name::Component &from)
Exclude all components in range [from, +Inf)
Exclude & excludeRange(const name::Component &from, const name::Component &to)
Exclude components in range [from, to].
const_iterator end() const
a concept check for TLV abstraction with .wireEncode method
bool operator==(const Exclude &other) 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.