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"));
198 BOOST_THROW_EXCEPTION(
Error(
"Excluded component must be generic or ImplicitSha256Digest"));
203 this->appendEntry(component,
true);
207 this->appendEntry(component,
false);
214 Exclude::appendEntry(
const T& component,
bool hasAny)
216 m_entries.emplace_hint(m_entries.begin(), std::piecewise_construct,
217 std::forward_as_tuple(component),
218 std::forward_as_tuple(hasAny));
233 ExcludeMap::const_iterator lb = m_entries.lower_bound(comp);
234 return lb != m_entries.end() &&
236 (!lb->first.isNegInf && lb->first.component == comp));
243 this->appendEntry(comp,
false);
276 if (!from.isNegInf && from.component >= to) {
277 BOOST_THROW_EXCEPTION(Error(
"Invalid exclude range [" + from.component.toUri() +
", " + to.
toUri() +
"] " 278 "(for single name exclude use Exclude::excludeOne)"));
282 if (newFrom == m_entries.end() || !newFrom->second ) {
283 bool isNewEntry =
false;
284 std::tie(newFrom, isNewEntry) = m_entries.emplace(from,
true);
287 newFrom->second =
true;
294 BOOST_ASSERT(newTo != m_entries.end());
295 if (newTo == newFrom || !newTo->second) {
296 newTo = m_entries.emplace_hint(newTo, to,
false);
303 m_entries.erase(newTo, newFrom);
313 if (newFrom == m_entries.end() || !newFrom->second ) {
314 bool isNewEntry =
false;
315 std::tie(newFrom, isNewEntry) = m_entries.emplace(from,
true);
318 newFrom->second =
true;
325 m_entries.erase(m_entries.begin(), newFrom);
335 for (
const Exclude::Entry& entry : exclude.m_entries | boost::adaptors::reversed) {
336 if (!entry.first.isNegInf) {
337 join = entry.first.component;
349 std::ostringstream os;
357 return m_entries == other.m_entries;
363 return std::distance(
begin(),
end());
374 ExcludeMap::const_reverse_iterator rend)
384 bool wasInRange = m_it->second;
386 if (wasInRange && m_it != m_rend) {
387 BOOST_ASSERT(m_it->second ==
false);
403 Exclude::const_iterator::update()
405 if (m_it == m_rend) {
410 if (m_it->first.isNegInf) {
411 m_range.fromInfinity =
true;
414 m_range.fromInfinity =
false;
415 m_range.from = m_it->first.component;
418 auto next = std::next(m_it);
419 if (next == m_rend) {
420 m_range.toInfinity =
true;
423 m_range.toInfinity =
false;
424 m_range.to = next->first.component;
428 BOOST_ASSERT(!m_it->first.isNegInf);
429 m_range.fromInfinity = m_range.toInfinity =
false;
430 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)
bool isImplicitSha256Digest() const
Check if the component is ImplicitSha256DigestComponent.
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)
Represents a name component.
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.
bool isGeneric() const
Check if the component is GenericComponent.
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.