33 #include <boost/functional/hash.hpp> 34 #include <boost/range/adaptor/reversed.hpp> 35 #include <boost/range/concepts.hpp> 39 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Name>));
43 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::iterator>));
44 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::const_iterator>));
45 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::reverse_iterator>));
46 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::const_reverse_iterator>));
47 BOOST_CONCEPT_ASSERT((boost::RandomAccessRangeConcept<Name>));
48 static_assert(std::is_base_of<tlv::Error, Name::Error>::value,
49 "Name::Error must inherit from tlv::Error");
51 const size_t Name::npos = std::numeric_limits<size_t>::max();
76 size_t iColon = uri.find(
':');
77 if (iColon != std::string::npos) {
79 size_t iFirstSlash = uri.find(
'/');
80 if (iFirstSlash == std::string::npos || iColon < iFirstSlash) {
82 uri.erase(0, iColon + 1);
88 if (uri.size() >= 2 && uri[1] ==
'/') {
90 size_t iAfterAuthority = uri.find(
'/', 2);
91 if (iAfterAuthority == std::string::npos)
95 uri.erase(0, iAfterAuthority + 1);
103 size_t iComponentStart = 0;
106 while (iComponentStart < uri.size()) {
107 size_t iComponentEnd = uri.find(
"/", iComponentStart);
108 if (iComponentEnd == std::string::npos)
109 iComponentEnd = uri.size();
112 iComponentStart = iComponentEnd + 1;
119 std::ostringstream os;
124 template<encoding::Tag TAG>
128 size_t totalLength = 0;
129 for (
const Component& comp : *
this | boost::adaptors::reversed) {
130 totalLength += comp.wireEncode(encoder);
133 totalLength += encoder.prependVarNumber(totalLength);
134 totalLength += encoder.prependVarNumber(
tlv::Name);
152 m_wire = buffer.block();
162 BOOST_THROW_EXCEPTION(
tlv::Error(
"Unexpected TLV type when decoding Name"));
171 Name copiedName(*
this);
186 if (i < 0 || static_cast<size_t>(i) >=
size()) {
187 BOOST_THROW_EXCEPTION(
Error(
"Requested component does not exist (out of bounds)"));
198 ssize_t iStart = iStartComponent < 0 ? this->
size() + iStartComponent : iStartComponent;
199 size_t iEnd = this->
size();
201 iStart = std::max(iStart, static_cast<ssize_t>(0));
203 if (nComponents !=
npos)
204 iEnd = std::min(this->
size(), iStart + nComponents);
206 for (
size_t i = iStart; i < iEnd; ++i)
233 for (
size_t i = 0; i <
name.size(); ++i)
245 static uint8_t firstValue[] {0};
247 firstName.
append(firstValue, 1);
262 for (
size_t i = 0; i <
size(); ++i) {
263 if (
get(i) != other.
get(i))
276 for (
size_t i = 0; i <
size(); ++i) {
277 if (
get(i) != other.
get(i))
287 count1 = std::min(count1, this->
size() - pos1);
288 count2 = std::min(count2, other.
size() - pos2);
289 size_t count = std::min(count1, count2);
291 for (
size_t i = 0; i < count; ++i) {
292 int comp =
get(pos1 + i).
compare(other.
get(pos2 + i));
298 return count1 - count2;
310 for (
const auto& component :
name) {
321 std::string inputString;
335 return boost::hash_range(
name.wireEncode().wire(),
336 name.wireEncode().wire() +
name.wireEncode().size());
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix of the name.
bool hasWire() const
Check if the Block has fully encoded wire.
Copyright (c) 2011-2015 Regents of the University of California.
Name & appendTimestamp()
Append a timestamp component based on current time.
std::string toUri() const
Get URI representation of the name.
bool equals(const Name &other) const
Check if this name equals another name.
const Block & wireEncode() const
Perform wire encoding, or return existing wire encoding.
const Component & get(ssize_t i) const
Get the component at the given index.
std::ostream & operator<<(std::ostream &os, const Data &data)
bool isPrefixOf(const Name &other) const
Check if this name is a prefix of another name.
size_t operator()(const ndn::Name &name) const
Name getSuccessor() const
Get the successor of a name.
static const size_t npos
indicates "until the end" in getSubName and compare
void parse() const
Parse TLV-VALUE into sub elements.
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)
const element_container & elements() const
Get container of sub elements.
const Component & at(ssize_t i) const
Get the component at the given index.
a concept check for TLV abstraction with .wireEncode method
int compare(const Name &other) const
Compare this to the other Name using NDN canonical ordering.
static Component fromEscapedString(const char *input, size_t beginOffset, size_t endOffset)
Decode NameComponent from a URI component.
Name PartialName
Represents an arbitrary sequence of name components.
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Exclude)
std::istream & operator>>(std::istream &is, Name &name)
Parse URI from stream as Name.
Represents an absolute name.
size_t size() const
Get number of components.
Represents a name component.
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
bool empty() const
Check if name is empty.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Name deepCopy() const
Make a deep copy of the name, reallocating the underlying memory buffer.
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 ...
PartialName getSubName(ssize_t iStartComponent, size_t nComponents=npos) const
Extract some components as a sub-name (PartialName)
EncodingImpl< EncoderTag > EncodingBuffer
uint32_t type() const
Get TLV-TYPE.
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