22 #ifndef NDN_CXX_NAME_HPP
23 #define NDN_CXX_NAME_HPP
44 class Name :
private boost::totally_ordered<Name>
62 using size_type = std::vector<Component>::size_type;
91 Name(std::string_view uri);
99 :
Name(std::string_view(uri))
109 :
Name(std::string_view(uri))
141 template<encoding::Tag TAG>
192 get(ssize_t i)
const noexcept
195 i +=
static_cast<ssize_t
>(
size());
232 getSubName(ssize_t iStartComponent,
size_t nComponents =
npos)
const;
330 append(uint32_t type, span<const uint8_t> value)
354 template<
class Iterator>
356 append(uint32_t type, Iterator first, Iterator last)
369 template<
class Iterator>
457 appendVersion(
const std::optional<uint64_t>& version = std::nullopt);
467 appendTimestamp(
const std::optional<time::system_clock::time_point>& timestamp = std::nullopt);
546 {
reinterpret_cast<const uint8_t*
>(keyword.data()), keyword.size()}));
645 compare(
size_t pos1,
size_t count1,
646 const Name& other,
size_t pos2 = 0,
size_t count2 =
npos)
const;
656 return lhs.equals(rhs);
680 static constexpr
size_t npos = std::numeric_limits<size_t>::max();
Represents a TLV element of the NDN packet format.
size_t elements_size() const noexcept
Equivalent to elements().size().
const element_container & elements() const noexcept
Get container of sub-elements.
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
void push_back(const Block &element)
Append a sub-element.
Represents an absolute name.
bool equals(const Name &other) const noexcept
Check if this name equals another name.
friend bool operator<(const Name &lhs, const Name &rhs)
Name & appendKeyword(span< const uint8_t > keyword)
Append a keyword component.
Name(const std::string &uri)
Create name from NDN URI.
const_reverse_iterator rend() const noexcept
Reverse end iterator.
Name & appendByteOffset(uint64_t offset)
Append a byte offset component.
Name & append(span< const uint8_t > value)
Append a GenericNameComponent, copying the TLV-VALUE from value.
Name & appendParametersSha256Digest(span< const uint8_t > digestBytes)
Append a ParametersSha256Digest component.
name::Component Component
Name & set(ssize_t i, const Component &component)
Replace the component at the specified index.
Name & appendSequenceNumber(uint64_t seqNo)
Append a sequence number component.
Name & appendTimestamp(const std::optional< time::system_clock::time_point > ×tamp=std::nullopt)
Append a timestamp component.
Name getSuccessor() const
Get the successor of a name.
Name & appendNumber(uint64_t number)
Append a component with a NonNegativeInteger.
Name & append(uint32_t type, Iterator first, Iterator last)
Append a NameComponent of TLV-TYPE type, copying the TLV-VALUE from a range.
PartialName getPrefix(ssize_t nComponents) const
Returns a prefix of the name.
std::reverse_iterator< iterator > reverse_iterator
Name & append(Iterator first, Iterator last)
Append a GenericNameComponent, copying the TLV-VALUE from a range.
int compare(const Name &other) const
Compare this to the other Name using NDN canonical ordering.
Name & appendSegment(uint64_t segmentNo)
Append a segment number (sequential) component.
const Component & operator[](ssize_t i) const noexcept
Equivalent to get().
Name & appendNumberWithMarker(uint8_t marker, uint64_t number)
Append a component with a marked number.
const_reverse_iterator rbegin() const noexcept
Reverse begin iterator.
Name & appendParametersSha256DigestPlaceholder()
Append a placeholder for a ParametersSha256Digest component.
Name & appendVersion(const std::optional< uint64_t > &version=std::nullopt)
Append a version component.
size_t size() const noexcept
Returns the number of components.
static constexpr size_t npos
Indicates "until the end" in getSubName() and compare().
const_iterator begin() const noexcept
Begin iterator.
friend std::ostream & operator<<(std::ostream &os, const Name &name)
Print the URI representation of a name.
Name & appendImplicitSha256Digest(ConstBufferPtr digest)
Append an ImplicitSha256Digest component.
bool hasWire() const noexcept
Check if this instance already has wire encoding.
bool empty() const noexcept
Checks if the name is empty, i.e., has no components.
std::vector< Component >::difference_type difference_type
Name & append(uint32_t type, span< const uint8_t > value)
Append a NameComponent of TLV-TYPE type, copying the TLV-VALUE from value.
void clear()
Remove all components.
Name(const char *uri)
Create name from NDN URI.
Name & appendImplicitSha256Digest(span< const uint8_t > digestBytes)
Append an ImplicitSha256Digest component.
Name & append(const Component &component)
Append a name component.
Name()
Create an empty name.
friend bool operator==(const Name &lhs, const Name &rhs) noexcept
const_iterator end() const noexcept
End iterator.
std::vector< Component >::size_type size_type
Name & appendParametersSha256Digest(ConstBufferPtr digest)
Append a ParametersSha256Digest component.
const Component & at(ssize_t i) const
Returns an immutable reference to the component at the specified index, with bounds checking.
Name deepCopy() const
Make a deep copy of the name, reallocating the underlying memory buffer.
const Block & wireEncode() const
Perform wire encoding, or return existing (cached) wire encoding.
Name & append(Component &&component)
Append a name component.
std::reverse_iterator< const_iterator > const_reverse_iterator
Name & append(const char *str)
Append a GenericNameComponent, copying the TLV-VALUE from a null-terminated string.
PartialName getSubName(ssize_t iStartComponent, size_t nComponents=npos) const
Extracts some components as a sub-name (PartialName).
Name & appendKeyword(std::string_view keyword)
Append a keyword component.
void erase(ssize_t i)
Erase the component at the specified index.
const Component * const_iterator
void toUri(std::ostream &os, name::UriFormat format=name::UriFormat::DEFAULT) const
Write URI representation of the name to the output stream.
bool isPrefixOf(const Name &other) const noexcept
Check if this name is a prefix of another name.
void wireDecode(const Block &wire)
Decode name from wire encoding.
const Component & get(ssize_t i) const noexcept
Returns an immutable reference to the component at the specified index.
Represents a name component.
static Component fromSegment(uint64_t segmentNo)
Create a segment number component using NDN naming conventions.
static Component fromNumber(uint64_t number, uint32_t type=tlv::GenericNameComponent)
Create a component encoded as NonNegativeInteger.
static Component fromSequenceNumber(uint64_t seqNo)
Create a sequence number component using NDN naming conventions.
static Component fromByteOffset(uint64_t offset)
Create a byte offset component using NDN naming conventions.
static Component fromNumberWithMarker(uint8_t marker, uint64_t number)
Create a component encoded as NameComponentWithMarker.
#define NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
UriFormat
Format used for the URI representation of a name.
@ DEFAULT
Use the library's default format; currently equivalent to UriFormat::ENV_OR_ALTERNATE.
@ ParametersSha256DigestComponent
@ ImplicitSha256DigestComponent
std::shared_ptr< const Buffer > ConstBufferPtr
std::istream & operator>>(std::istream &is, Name &name)
Parse URI from stream as Name.