27 #include <boost/range/adaptor/reversed.hpp> 34 , component(component1)
41 BOOST_ASSERT(isNegInf1 ==
true);
65 : fromInfinity(fromInfinity)
67 , toInfinity(toInfinity)
76 (this->fromInfinity || this->from == other.
from) &&
77 (this->toInfinity || this->to == other.
to);
84 return os <<
'{' << range.
from <<
'}';
91 os <<
'[' << range.
from;
100 os << range.
to <<
']';
106 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Exclude>));
110 static_assert(std::is_base_of<tlv::Error, Exclude::Error>::value,
111 "Exclude::Error must inherit from tlv::Error");
120 template<encoding::Tag TAG>
124 if (m_entries.empty()) {
125 BOOST_THROW_EXCEPTION(
Error(
"cannot encode empty Exclude selector"));
128 size_t totalLength = 0;
133 for (
const Entry& entry : m_entries) {
137 if (!entry.first.isNegInf) {
138 totalLength += entry.first.component.wireEncode(encoder);
142 totalLength += encoder.prependVarNumber(totalLength);
161 m_wire = buffer.block();
171 BOOST_THROW_EXCEPTION(
tlv::Error(
"Unexpected TLV type when decoding Exclude"));
177 BOOST_THROW_EXCEPTION(
Error(
"Exclude element cannot be empty"));
185 this->appendEntry(
true,
true);
195 BOOST_THROW_EXCEPTION(
Error(
"Incorrect format of Exclude filter"));
200 this->appendEntry(component,
true);
204 this->appendEntry(component,
false);
211 Exclude::appendEntry(
const T& component,
bool hasAny)
213 m_entries.emplace_hint(m_entries.begin(), std::piecewise_construct,
214 std::forward_as_tuple(component),
215 std::forward_as_tuple(hasAny));
230 ExcludeMap::const_iterator lb = m_entries.lower_bound(comp);
231 return lb != m_entries.end() &&
233 (!lb->first.isNegInf && lb->first.component == comp));
240 this->appendEntry(comp,
false);
273 if (!from.isNegInf && from.component >= to) {
274 BOOST_THROW_EXCEPTION(Error(
"Invalid exclude range [" + from.component.toUri() +
", " + to.
toUri() +
"] " 275 "(for single name exclude use Exclude::excludeOne)"));
279 if (newFrom == m_entries.end() || !newFrom->second ) {
280 bool isNewEntry =
false;
281 std::tie(newFrom, isNewEntry) = m_entries.emplace(from,
true);
284 newFrom->second =
true;
291 BOOST_ASSERT(newTo != m_entries.end());
292 if (newTo == newFrom || !newTo->second) {
293 newTo = m_entries.emplace_hint(newTo, to,
false);
300 m_entries.erase(newTo, newFrom);
310 if (newFrom == m_entries.end() || !newFrom->second ) {
311 bool isNewEntry =
false;
312 std::tie(newFrom, isNewEntry) = m_entries.emplace(from,
true);
315 newFrom->second =
true;
322 m_entries.erase(m_entries.begin(), newFrom);
332 for (
const Exclude::Entry& entry : exclude.m_entries | boost::adaptors::reversed) {
333 if (!entry.first.isNegInf) {
334 join = entry.first.component;
346 std::ostringstream os;
354 return m_entries == other.m_entries;
360 return std::distance(
begin(),
end());
371 ExcludeMap::const_reverse_iterator rend)
381 bool wasInRange = m_it->second;
383 if (wasInRange && m_it != m_rend) {
384 BOOST_ASSERT(m_it->second ==
false);
400 Exclude::const_iterator::update()
402 if (m_it == m_rend) {
407 if (m_it->first.isNegInf) {
408 m_range.fromInfinity =
true;
411 m_range.fromInfinity =
false;
412 m_range.from = m_it->first.component;
415 auto next = std::next(m_it);
416 if (next == m_rend) {
417 m_range.toInfinity =
true;
420 m_range.toInfinity =
false;
421 m_range.to = next->first.component;
425 BOOST_ASSERT(!m_it->first.isNegInf);
426 m_range.fromInfinity = m_range.toInfinity =
false;
427 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
bool hasWire() const
Check if the Block has fully encoded wire.
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
const_iterator & operator++()
name::Component from
from component (inclusive)
bool toInfinity
to positive infinity?
element_container::const_iterator element_const_iterator
const_iterator end() const
void parse() const
Parse TLV-VALUE into sub elements.
Represents a TLV element of NDN packet format.
element_const_iterator elements_begin() const
Equivalent to elements().begin()
Exclude()
Constructs an empty Exclude.
ostream_joiner< typename std::decay< DelimT >::type, CharT, Traits > make_ostream_joiner(std::basic_ostream< CharT, Traits > &os, DelimT &&delimiter)
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.
element_const_iterator elements_end() const
Equivalent to elements().end()
ExcludeMap::value_type Entry
size_t prependEmptyBlock(EncodingImpl< TAG > &encoder, uint32_t type)
Prepend an empty TLV element.
void toUri(std::ostream &os) const
Write *this to the output stream, escaping characters according to the NDN URI Scheme.
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Exclude)
void reset()
Reset wire buffer of the element.
size_t elements_size() const
Equivalent to elements().size()
bool fromInfinity
from negative infinity?
name::Component to
to component (inclusive)
bool operator>(const Delegation &lhs, const Delegation &rhs)
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 ...
EncodingImpl< EncoderTag > EncodingBuffer
ExcludeComponent(const name::Component &component)
implicitly construct a regular infinity ExcludeComponent
uint32_t type() const
Get TLV-TYPE.
represents an error in TLV encoding or decoding
EncodingImpl< EstimatorTag > EncodingEstimator
Represents Exclude selector in NDN Interest.
Error that can be thrown from name::Component.