19 #include <boost/iterator/reverse_iterator.hpp>
26 class Name :
public ptr_lib::enable_shared_from_this<Name>
63 : m_nameBlock(Tlv::
Name)
96 Name(
const std::string& uri)
125 set(
const char* uri);
132 set(
const std::string& uri)
142 append(
const uint8_t* value,
size_t valueLength)
152 template<
class InputIterator>
223 getSubName(
size_t iStartComponent,
size_t nComponents)
const;
321 return m_nameBlock.
elements().empty();
365 if ((i >= 0 && static_cast<size_t>(i) >=
size()) ||
366 (i < 0 && static_cast<size_t>(-i) >
size()))
367 throw Error(
"Requested component does not exist (out of bounds)");
396 template<
class T>
void
515 mutable Block m_nameBlock;
529 i->toEscapedString(os);
538 std::ostringstream os;
546 std::string inputString;
548 name.
set(inputString);
559 std::string uri = uri_cstr;
564 size_t iColon = uri.find(
':');
565 if (iColon != std::string::npos) {
567 size_t iFirstSlash = uri.find(
'/');
568 if (iFirstSlash == std::string::npos || iColon < iFirstSlash) {
570 uri.erase(0, iColon + 1);
577 if (uri.size() >= 2 && uri[1] ==
'/') {
579 size_t iAfterAuthority = uri.find(
'/', 2);
580 if (iAfterAuthority == std::string::npos)
584 uri.erase(0, iAfterAuthority + 1);
594 size_t iComponentStart = 0;
597 while (iComponentStart < uri.size()) {
598 size_t iComponentEnd = uri.find(
"/", iComponentStart);
599 if (iComponentEnd == std::string::npos)
600 iComponentEnd = uri.size();
604 if (!component.
empty())
607 iComponentStart = iComponentEnd + 1;
618 for (
size_t i = 0; i < name.
size(); ++i)
636 size_t iEnd = iStartComponent + nComponents;
637 for (
size_t i = iStartComponent; i < iEnd && i <
size(); ++i)
648 for (
size_t i = iStartComponent; i <
size(); ++i)
660 for (
size_t i = 0; i <
size(); ++i) {
661 if (
at(i) != name.
at(i))
676 for (
size_t i = 0; i <
size(); ++i) {
677 if (
at(i) != name.
at(i))
688 for (
size_t i = 0; i <
size() && i < other.
size(); ++i) {
713 size_t totalLength = 0;
719 totalLength += i->wireEncode(blk);
722 totalLength += blk.prependVarNumber(totalLength);
723 totalLength += blk.prependVarNumber(
Tlv::Name);
739 m_nameBlock = buffer.block();
749 throw Tlv::Error(
"Unexpected TLV type when decoding Name");
static Component fromNumber(uint64_t number)
Create a component encoded as nonNegativeInteger.
void set(const std::string &uri)
Parse the uri according to the NDN URI Scheme and set the name with the components.
Name getSubName(size_t iStartComponent, size_t nComponents) const
Get a new name, constructed as a subset of components.
name::Component Component
bool operator!=(const Name &name) const
Check if this name has the same component count and components as the given name. ...
const_iterator begin() const
Begin iterator (const).
Name getPrefix(int nComponents) const
Return a new Name with the first nComponents components of this Name.
int compare(const Component &other) const
Compare this to the other Component using NDN canonical ordering.
static Component fromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset)
Make a Blob value by decoding the escapedString between beginOffset and endOffset according to the ND...
Name & append(const char *value)
Append name component that represented as a string.
bool operator==(const Name &name) const
Check if this name has the same component count and components as the given name. ...
component_container::size_type size_type
const Component const_reference
Name & append(const Component &value)
Name & append(InputIterator begin, InputIterator end)
Append a new component, copying from value of length valueLength.
std::vector< Component > component_container
const element_container & elements() const
Get all subelements.
Class representing wire element of the NDN packet.
Name & appendSegment(uint64_t number)
An alias for appendNumber(uint64_t)
Name & appendNumber(uint64_t number)
Append a component with the number encoded as nonNegativeInteger.
const Component & operator[](ssize_t i) const
void set(const char *uri)
Parse the uri according to the NDN URI Scheme and set the name with the components.
Error that can be thrown from Name.
std::string toUri() const
Encode this name as a URI.
bool operator>=(const Name &other) const
Return true if this is less than or equal to the other Name in the NDN canonical ordering.
ptr_lib::shared_ptr< const Buffer > ConstBufferPtr
const Block & wireEncode() const
boost::reverse_iterator< iterator > reverse_iterator
const_iterator end() const
End iterator (const).
const Component * const_iterator
const_reverse_iterator rend() const
Reverse end iterator (const).
bool hasWire() const
Check if already has wire.
Name & append(const Block &value)
const Component * const_pointer
bool operator<=(const Name &other) const
Return true if this is less than or equal to the other Name in the NDN canonical ordering.
size_t size() const
Get the number of components.
size_t elements_size() const
A Name holds an array of Name::Component and represents an NDN name.
void push_back(const Block &element)
std::istream & operator>>(std::istream &is, Name &name)
Error(const std::string &what)
void push_back(const T &component)
Append the component.
const_reverse_iterator rbegin() const
Reverse begin iterator (const).
void parse() const
Parse wire buffer into subblocks.
Component holds a read-only name component value.
bool operator>(const Name &other) const
Return true if this is greater than the other Name in the NDN canonical ordering. ...
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.
bool operator<(const Name &other) const
Return true if this is less than the other Name in the NDN canonical ordering.
Name & append(const uint8_t *value, size_t valueLength)
Append a new component, copying from value of length valueLength.
bool empty() const
Check if name is emtpy.
bool hasWire() const
Check if the Block has fully encoded wire.
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
void trim(std::string &str)
Modify str in place to erase whitespace on the left and right.
Name(const char *uri)
Parse the uri according to the NDN URI Scheme and create the name with the components.
component_container::difference_type difference_type
Name & appendVersion(uint64_t number)
An alias for appendNumber(uint64_t)
bool equals(const Name &name) const
Check if this name has the same component count and components as the given name. ...
std::ostream & operator<<(std::ostream &os, const Data &data)
void wireDecode(const Block &wire)
boost::reverse_iterator< const_iterator > const_reverse_iterator
void clear()
Clear all the components.
const Component & at(ssize_t i) const
Get component at the specified index.
Name & appendVersion()
Append a component with the encoded version number (current UNIX timestamp in milliseconds) ...
Name()
Create a new Name with no components.
Class representing wire element of the NDN packet.
Error that can be thrown from name::Component.
Name & append(const ConstBufferPtr &value)
Name(const Block &wire)
Create Name object from wire block.
Name(const std::string &uri)
Parse the uri according to the NDN URI Scheme and create the name with the components.