27 #include <boost/range/adaptor/reversed.hpp> 34 , component(component1)
41 BOOST_ASSERT(isNegInf1 ==
true);
65 : fromInfinity(fromInfinity)
67 , toInfinity(toInfinity)
84 return os <<
'{' << range.
from <<
'}';
91 os <<
'[' << range.
from;
100 os << range.
to <<
']';
106 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Exclude>));
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);
152 if (m_wire.hasWire())
161 m_wire = buffer.block();
171 BOOST_THROW_EXCEPTION(
tlv::Error(
"Unexpected TLV type when decoding Exclude"));
176 if (m_wire.elements_size() == 0) {
177 BOOST_THROW_EXCEPTION(
Error(
"Exclude element cannot be empty"));
185 this->appendEntry(
true,
true);
189 while (i != m_wire.elements_end()) {
195 BOOST_THROW_EXCEPTION(
Error(
"Incorrect format of Exclude filter"));
199 if (i != m_wire.elements_end() && i->type() ==
tlv::Any) {
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);
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) {
412 m_range.
from = m_it->first.component;
415 auto next = std::next(m_it);
416 if (next == m_rend) {
421 m_range.
to = next->first.component;
425 BOOST_ASSERT(!m_it->first.isNegInf);
427 m_range.
from = m_range.
to = m_it->first.component;
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
Represents a TLV element of NDN packet format.
Exclude()
Constructs an empty Exclude.
bool operator==(const Exclude::Range &other) const
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
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
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)
const_iterator begin() const
bool fromInfinity
from negative infinity?
void parse() const
Parse TLV-VALUE into sub elements.
uint32_t type() const
Get TLV-TYPE.
name::Component to
to component (inclusive)
bool operator>(const Delegation &lhs, const Delegation &rhs)
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.
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 ...
EncodingImpl< EncoderTag > EncodingBuffer
ExcludeComponent(const name::Component &component)
implicitly construct a regular infinity ExcludeComponent
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.