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>));
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);
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"));
198 BOOST_THROW_EXCEPTION(
Error(
"Excluded component must be generic or ImplicitSha256Digest"));
202 if (i != m_wire.elements_end() && i->type() ==
tlv::Any) {
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);
278 "(for single name exclude use Exclude::excludeOne)"));
281 ExcludeMap::iterator newFrom = m_entries.lower_bound(from);
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;
293 ExcludeMap::iterator newTo = m_entries.lower_bound(to);
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);
312 ExcludeMap::iterator newFrom = m_entries.lower_bound(from);
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) {
415 m_range.
from = m_it->first.component;
418 auto next = std::next(m_it);
419 if (next == m_rend) {
424 m_range.
to = next->first.component;
428 BOOST_ASSERT(!m_it->first.isNegInf);
430 m_range.
from = m_range.
to = m_it->first.component;
bool isGeneric() const
Check if the component is GenericComponent.
Copyright (c) 2013-2017 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)
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.
#define NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
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)
Represents a name component.
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.
bool isImplicitSha256Digest() const
Check if the component is ImplicitSha256DigestComponent.