27 #include <boost/range/adaptors.hpp> 31 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Exclude>));
35 static_assert(std::is_base_of<tlv::Error, Exclude::Error>::value,
36 "Exclude::Error must inherit from tlv::Error");
47 template<encoding::Tag TAG>
51 if (m_exclude.empty()) {
52 BOOST_THROW_EXCEPTION(
Error(
"Exclude filter cannot be empty"));
55 size_t totalLength = 0;
60 for (
const auto& item : m_exclude) {
64 if (!item.first.empty() || !item.second) {
65 totalLength += item.first.wireEncode(encoder);
69 totalLength += encoder.prependVarNumber(totalLength);
75 Exclude::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>& encoder)
const;
78 Exclude::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>& encoder)
const;
92 m_wire = buffer.block();
102 BOOST_THROW_EXCEPTION(
tlv::Error(
"Unexpected TLV type when decoding Exclude"));
108 BOOST_THROW_EXCEPTION(
Error(
"Exclude element cannot be empty"));
126 BOOST_THROW_EXCEPTION(
Error(
"Incorrect format of Exclude filter"));
162 if (lowerBound ==
end())
165 if (lowerBound->second)
168 return lowerBound->first == comp;
175 m_exclude.insert(std::make_pair(comp,
false));
212 BOOST_THROW_EXCEPTION(
Error(
"Invalid exclude range [" + from.
toUri() +
", " + to.
toUri() +
"] " 213 "(for single name exclude use Exclude::excludeOne)"));
216 iterator newFrom = m_exclude.lower_bound(from);
217 if (newFrom ==
end() || !newFrom->second ) {
218 std::pair<iterator, bool> fromResult = m_exclude.insert(std::make_pair(from,
true));
219 newFrom = fromResult.first;
220 if (!fromResult.second) {
222 newFrom->second =
true;
228 iterator newTo = m_exclude.lower_bound(to);
229 if (newTo == newFrom || !newTo->second) {
230 std::pair<iterator, bool> toResult = m_exclude.insert(std::make_pair(to,
false));
231 newTo = toResult.first;
237 m_exclude.erase(newTo, newFrom);
246 iterator newFrom = m_exclude.lower_bound(from);
247 if (newFrom ==
end() || !newFrom->second ) {
248 std::pair<iterator, bool> fromResult = m_exclude.insert(std::make_pair(from,
true));
249 newFrom = fromResult.first;
250 if (!fromResult.second) {
252 newFrom->second =
true;
258 if (newFrom != m_exclude.begin()) {
260 m_exclude.erase(m_exclude.begin(), newFrom);
271 for (
const auto& item : exclude | boost::adaptors::reversed) {
272 if (!item.first.empty() || !item.second) {
275 os << item.first.toUri();
291 std::ostringstream os;
void appendExclude(const name::Component &name, bool any)
Method to directly append exclude element.
Copyright (c) 2011-2015 Regents of the University of California.
EncodingImpl< EstimatorTag > EncodingEstimator
std::ostream & operator<<(std::ostream &os, const Data &data)
exclude_type::const_iterator const_iterator
Class representing a wire element of NDN-TLV packet format.
void clear()
Clear the exclude filter.
Exclude()
Default constructor an empty exclude.
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.
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
void reset()
Reset wire buffer of the element.
void parse() const
Parse wire buffer into subblocks.
Component holds a read-only name component value.
exclude_type::iterator iterator
bool empty() const
Check if exclude filter is empty.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
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.
Exclude & excludeAfter(const name::Component &from)
Exclude all components from range [from, +Inf].
Exclude & excludeRange(const name::Component &from, const name::Component &to)
Exclude components from range [from, to].
const_iterator end() const
Get end iterator of the exclude terms.
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 ...
represents an error in TLV encoding or decoding
Class to represent Exclude component in NDN interests.
Error that can be thrown from name::Component.