33 #include <boost/algorithm/string/trim.hpp> 34 #include <boost/functional/hash.hpp> 35 #include <boost/range/adaptor/reversed.hpp> 36 #include <boost/range/concepts.hpp> 40 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Name>));
44 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::iterator>));
45 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::const_iterator>));
46 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::reverse_iterator>));
47 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::const_reverse_iterator>));
48 BOOST_CONCEPT_ASSERT((boost::RandomAccessRangeConcept<Name>));
50 "Name::Error must inherit from tlv::Error");
52 const size_t Name::npos = std::numeric_limits<size_t>::max();
74 boost::algorithm::trim(uri);
78 size_t iColon = uri.find(
':');
79 if (iColon != std::string::npos) {
81 size_t iFirstSlash = uri.find(
'/');
82 if (iFirstSlash == std::string::npos || iColon < iFirstSlash) {
84 uri.erase(0, iColon + 1);
85 boost::algorithm::trim(uri);
91 if (uri.size() >= 2 && uri[1] ==
'/') {
93 size_t iAfterAuthority = uri.find(
'/', 2);
94 if (iAfterAuthority == std::string::npos)
98 uri.erase(0, iAfterAuthority + 1);
99 boost::algorithm::trim(uri);
104 boost::algorithm::trim(uri);
108 size_t iComponentStart = 0;
111 while (iComponentStart < uri.size()) {
112 size_t iComponentEnd = uri.find(
"/", iComponentStart);
113 if (iComponentEnd == std::string::npos)
114 iComponentEnd = uri.size();
117 iComponentStart = iComponentEnd + 1;
124 std::ostringstream os;
129 template<encoding::Tag TAG>
133 size_t totalLength = 0;
134 for (
const Component& comp : *
this | boost::adaptors::reversed) {
135 totalLength += comp.wireEncode(encoder);
138 totalLength += encoder.prependVarNumber(totalLength);
139 totalLength += encoder.prependVarNumber(
tlv::Name);
157 m_wire = buffer.block();
167 BOOST_THROW_EXCEPTION(
tlv::Error(
"Unexpected TLV type when decoding Name"));
176 Name copiedName(*
this);
191 if (i < 0 || static_cast<size_t>(i) >=
size()) {
192 BOOST_THROW_EXCEPTION(
Error(
"Requested component does not exist (out of bounds)"));
203 ssize_t iStart = iStartComponent < 0 ? this->
size() + iStartComponent : iStartComponent;
204 size_t iEnd = this->
size();
206 iStart = std::max(iStart, static_cast<ssize_t>(0));
208 if (nComponents !=
npos)
209 iEnd = std::min(this->
size(), iStart + nComponents);
211 for (
size_t i = iStart; i < iEnd; ++i)
238 for (
size_t i = 0; i < name.
size(); ++i)
250 static uint8_t firstValue[] {0};
252 firstName.
append(firstValue, 1);
267 for (
size_t i = 0; i <
size(); ++i) {
268 if (
get(i) != other.
get(i))
281 for (
size_t i = 0; i <
size(); ++i) {
282 if (
get(i) != other.
get(i))
292 count1 = std::min(count1, this->
size() - pos1);
293 count2 = std::min(count2, other.
size() - pos2);
294 size_t count = std::min(count1, count2);
296 for (
size_t i = 0; i < count; ++i) {
297 int comp =
get(pos1 + i).
compare(other.
get(pos2 + i));
303 return count1 - count2;
315 for (
const auto& component : name) {
326 std::string inputString;
328 name =
Name(inputString);
340 return boost::hash_range(name.
wireEncode().wire(),
Copyright (c) 2011-2015 Regents of the University of California.
Name & appendTimestamp()
Append a timestamp component based on current time.
const element_container & elements() const
Get container of sub elements.
static Component fromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset)
Create name::Component by decoding the escapedString between beginOffset and endOffset according to t...
Name getSuccessor() const
Get the successor of a name.
std::ostream & operator<<(std::ostream &os, const Data &data)
static const size_t npos
indicates "until the end" in getSubName and compare
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Represents a TLV element of NDN packet format.
static time_point now() noexcept
Name & append(const Component &component)
Append a component.
void resetWire()
Reset wire buffer but keep TLV-TYPE and sub elements (if any)
std::string toUri() const
Get URI representation of the name.
a concept check for TLV abstraction with .wireEncode method
const Block & wireEncode() const
Perform wire encoding, or return existing wire encoding.
bool equals(const Name &other) const
Check if this name equals another name.
Name PartialName
Represents an arbitrary sequence of name components.
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Exclude)
size_t size() const
Get number of components.
std::istream & operator>>(std::istream &is, Name &name)
Parse URI from stream as Name.
Represents an absolute name.
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
const Component & at(ssize_t i) const
Get the component at the given index.
void parse() const
Parse TLV-VALUE into sub elements.
uint32_t type() const
Get TLV-TYPE.
Component holds a read-only name component value.
int compare(const Name &other) const
Compare this to the other Name using NDN canonical ordering.
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
Name deepCopy() const
Make a deep copy of the name, reallocating the underlying memory buffer.
bool empty() const
Check if name is empty.
bool hasWire() const
Check if the Block has fully encoded wire.
PartialName getSubName(ssize_t iStartComponent, size_t nComponents=npos) const
Extract some components as a sub-name (PartialName)
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix of the name.
void wireDecode(const Block &wire)
Decode name from wire encoding.
a concept check for TLV abstraction with .wireEncode method
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
const Component & get(ssize_t i) const
Get the component at the given index.
EncodingImpl< EncoderTag > EncodingBuffer
Name & appendVersion()
Append a version component based on current time.
Name()
Create an empty name.
represents an error in TLV encoding or decoding
EncodingImpl< EstimatorTag > EncodingEstimator