32 #include <boost/functional/hash.hpp> 33 #include <boost/range/adaptor/reversed.hpp> 34 #include <boost/range/concepts.hpp> 38 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Name>));
39 BOOST_CONCEPT_ASSERT((WireEncodable<Name>));
40 BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<Name>));
41 BOOST_CONCEPT_ASSERT((WireDecodable<Name>));
42 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::iterator>));
43 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::const_iterator>));
44 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::reverse_iterator>));
45 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Name::const_reverse_iterator>));
46 BOOST_CONCEPT_ASSERT((boost::RandomAccessRangeConcept<Name>));
47 static_assert(std::is_base_of<tlv::Error, Name::Error>::value,
48 "Name::Error must inherit from tlv::Error");
50 const size_t Name::npos = std::numeric_limits<size_t>::max();
75 size_t iColon = uri.find(
':');
76 if (iColon != std::string::npos) {
78 size_t iFirstSlash = uri.find(
'/');
79 if (iFirstSlash == std::string::npos || iColon < iFirstSlash) {
81 uri.erase(0, iColon + 1);
87 if (uri.size() >= 2 && uri[1] ==
'/') {
89 size_t iAfterAuthority = uri.find(
'/', 2);
90 if (iAfterAuthority == std::string::npos)
94 uri.erase(0, iAfterAuthority + 1);
102 size_t iComponentStart = 0;
105 while (iComponentStart < uri.size()) {
106 size_t iComponentEnd = uri.find(
"/", iComponentStart);
107 if (iComponentEnd == std::string::npos)
108 iComponentEnd = uri.size();
111 iComponentStart = iComponentEnd + 1;
118 std::ostringstream os;
123 template<encoding::Tag TAG>
127 size_t totalLength = 0;
128 for (
const Component& comp : *
this | boost::adaptors::reversed) {
129 totalLength += comp.wireEncode(encoder);
132 totalLength += encoder.prependVarNumber(totalLength);
133 totalLength += encoder.prependVarNumber(
tlv::Name);
151 m_wire = buffer.block();
170 Name copiedName(*
this);
185 if (i < 0 || static_cast<size_t>(i) >=
size()) {
186 NDN_THROW(
Error(
"Requested component does not exist (out of bounds)"));
197 ssize_t iStart = iStartComponent < 0 ? this->
size() + iStartComponent : iStartComponent;
198 size_t iEnd = this->
size();
200 iStart = std::max(iStart, static_cast<ssize_t>(0));
202 if (nComponents !=
npos)
203 iEnd = std::min(this->
size(), iStart + nComponents);
205 for (
size_t i = iStart; i < iEnd; ++i)
232 for (
size_t i = 0; i < name.
size(); ++i)
244 return Name(
"/sha256digest=0000000000000000000000000000000000000000000000000000000000000000");
258 for (
size_t i = 0; i <
size(); ++i) {
259 if (
get(i) != other.
get(i))
272 for (
size_t i = 0; i <
size(); ++i) {
273 if (
get(i) != other.
get(i))
283 count1 = std::min(count1, this->
size() - pos1);
284 count2 = std::min(count2, other.
size() - pos2);
285 size_t count = std::min(count1, count2);
287 for (
size_t i = 0; i < count; ++i) {
288 int comp =
get(pos1 + i).
compare(other.
get(pos2 + i));
294 return count1 - count2;
306 for (
const auto& component : name) {
317 std::string inputString;
319 name =
Name(inputString);
329 hash<ndn::Name>::operator()(
const ndn::Name& name)
const 331 return boost::hash_range(name.
wireEncode().wire(),
name::Component::Error Error
const element_container & elements() const
Get container of sub-elements.
Name getSuccessor() const
Get the successor of a name.
std::ostream & operator<<(std::ostream &os, const Data &data)
static Component fromTimestamp(const time::system_clock::TimePoint &timePoint)
Create sequence number component using NDN naming conventions.
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.
void resetWire() noexcept
Reset wire buffer but keep TLV-TYPE and sub-elements (if any)
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
static time_point now() noexcept
Name & append(const Component &component)
Append a component.
Name & appendVersion(optional< uint64_t > version=nullopt)
Append a version component.
std::string toUri() const
Get URI representation of the name.
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.
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.
#define NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
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.
Name & appendTimestamp(optional< time::system_clock::TimePoint > timestamp=nullopt)
Append a timestamp component.
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
Return the TLV-TYPE of the Block.
Represents a name component.
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.
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.
static Component fromVersion(uint64_t version)
Create version component using NDN naming conventions.
void wireDecode(const Block &wire)
Decode name from wire encoding.
const Component & get(ssize_t i) const
Get the component at the given index.
EncodingImpl< EncoderTag > EncodingBuffer
Name()
Create an empty name.
represents an error in TLV encoding or decoding
EncodingImpl< EstimatorTag > EncodingEstimator