Public Member Functions | Static Public Member Functions | List of all members
ndn::Name::Component Class Reference

A Name::Component holds a read-only name component value. More...

#include <name.hpp>

Public Member Functions

 Component ()
 Create a new GENERIC Name::Component with a zero-length value.
 
 Component (const std::vector< uint8_t > &value)
 Create a new GENERIC Name::Component, copying the given value. More...
 
 Component (const uint8_t *value, size_t valueLength)
 Create a new GENERIC Name::Component, copying the given value. More...
 
 Component (const char *value)
 Create a new GENERIC Name::Component, copying the bytes from the value string. More...
 
 Component (const std::string &value)
 Create a new GENERIC Name::Component, copying the bytes from the value string. More...
 
 Component (const Blob &value)
 Create a new GENERIC Name::Component, taking another pointer to the Blob value. More...
 
 Component (const NameLite::Component &componentLite)
 Create a new Name::Component, copying bytes from the NameLite::Component value and using its type. More...
 
void get (NameLite::Component &componentLite) const
 Set componentLite to point to this component, without copying any memory. More...
 
const BlobgetValue () const
 
void toEscapedString (std::ostringstream &result) const
 Write this component value to result, escaping characters according to the NDN URI Scheme. More...
 
std::string toEscapedString () const
 Convert this component value by escaping characters according to the NDN URI Scheme. More...
 
bool isSegment () const
 Check if this component is a segment number according to NDN naming conventions for "Segment number" (marker 0x00) and return an integer. More...
 
bool isSegmentOffset () const
 Check if this component is a segment byte offset according to NDN naming conventions for "Byte offset" (marker 0xFB) and return an integer. More...
 
bool isVersion () const
 Check if this component is a version number according to NDN naming conventions for "Versioning" (marker 0xFD) and return an integer. More...
 
bool isTimestamp () const
 Check if this component is a timestamp according to NDN naming conventions for "Timestamp" (marker 0xFC) and return an integer. More...
 
bool isSequenceNumber () const
 Check if this component is a sequence number according to NDN naming conventions for "Sequencing" (marker 0xFE) and return an integer. More...
 
bool isGeneric () const
 Check if this component is a generic component. More...
 
bool isImplicitSha256Digest () const
 Check if this component is an ImplicitSha256Digest component. More...
 
uint64_t toNumber () const
 Interpret this name component as a network-ordered number and return an integer. More...
 
uint64_t toNumberWithMarker (uint8_t marker) const
 Interpret this name component as a network-ordered number with a marker and return an integer. More...
 
uint64_t toNumberWithPrefix (const uint8_t *prefix, size_t prefixLength) const
 Interpret this name component as a network-ordered number with a prefix and return an integer. More...
 
bool hasPrefix (const uint8_t *prefix, size_t prefixLength) const
 Check if this name component begins with the given prefix. More...
 
uint64_t toSegment () const
 Interpret this name component as a segment number according to NDN naming conventions for "Segment number" (marker 0x00). More...
 
uint64_t toSegmentOffset () const
 Interpret this name component as a segment byte offset according to NDN naming conventions for segment "Byte offset" (marker 0xFB). More...
 
uint64_t DEPRECATED_IN_NDN_CPP toSeqNum () const
 
bool DEPRECATED_IN_NDN_CPP isFinalSegment () const
 
uint64_t DEPRECATED_IN_NDN_CPP toFinalSegment () const
 
uint64_t toVersion () const
 Interpret this name component as a version number according to NDN naming conventions for "Versioning" (marker 0xFD). More...
 
uint64_t toTimestamp () const
 Interpret this name component as a timestamp according to NDN naming conventions for "Timestamp" (marker 0xFC). More...
 
uint64_t toSequenceNumber () const
 Interpret this name component as a sequence number according to NDN naming conventions for "Sequencing" (marker 0xFE). More...
 
Component getSuccessor () const
 Get the successor of this component, as described in Name::getSuccessor. More...
 
bool equals (const Component &other) const
 Check if this is the same component as other. More...
 
bool operator== (const Component &other) const
 Check if this is the same component as other. More...
 
bool operator!= (const Component &other) const
 Check if this is not the same component as other. More...
 
int compare (const Component &other) const
 Compare this to the other Component using NDN canonical ordering. More...
 
bool operator<= (const Component &other) const
 Return true if this is less than or equal to the other Component in the NDN canonical ordering. More...
 
bool operator< (const Component &other) const
 Return true if this is less than the other Component in the NDN canonical ordering. More...
 
bool operator>= (const Component &other) const
 Return true if this is less than or equal to the other Component in the NDN canonical ordering. More...
 
bool operator> (const Component &other) const
 Return true if this is greater than the other Component in the NDN canonical ordering. More...
 

Static Public Member Functions

static Component fromNumber (uint64_t number)
 Create a GENERIC component whose value is the nonNegativeInteger encoding of the number. More...
 
static Component fromNumberWithMarker (uint64_t number, uint8_t marker)
 Create a GENERIC component whose value is the marker appended with the nonNegativeInteger encoding of the number. More...
 
static Component fromNumberWithPrefix (uint64_t number, const uint8_t *prefix, size_t prefixLength)
 Create a GENERIC component whose value is the prefix appended with the network-ordered encoding of the number. More...
 
static Component fromSegment (uint64_t segment)
 Create a component with the encoded segment number according to NDN naming conventions for "Segment number" (marker 0x00). More...
 
static Component fromSegmentOffset (uint64_t segmentOffset)
 Create a component with the encoded segment byte offset according to NDN naming conventions for segment "Byte offset" (marker 0xFB). More...
 
static Component fromVersion (uint64_t version)
 Create a component with the encoded version number according to NDN naming conventions for "Versioning" (marker 0xFD). More...
 
static Component fromTimestamp (uint64_t timestamp)
 Create a component with the encoded timestamp according to NDN naming conventions for "Timestamp" (marker 0xFC). More...
 
static Component fromSequenceNumber (uint64_t sequenceNumber)
 Create a component with the encoded sequence number according to NDN naming conventions for "Sequencing" (marker 0xFE). More...
 
static Component fromImplicitSha256Digest (const Blob &digest)
 Create a component of type ImplicitSha256DigestComponent, so that isImplicitSha256Digest() is true. More...
 
static Component fromImplicitSha256Digest (const uint8_t *digest, size_t digestLength)
 Create a component of type ImplicitSha256DigestComponent, so that isImplicitSha256Digest() is true. More...
 
static Component fromImplicitSha256Digest (const std::vector< uint8_t > &digest)
 Create a component of type ImplicitSha256DigestComponent, so that isImplicitSha256Digest() is true. More...
 
static const uint8_t * getFinalSegmentPrefix ()
 
static size_t getFinalSegmentPrefixLength ()
 

Detailed Description

A Name::Component holds a read-only name component value.

Constructor & Destructor Documentation

ndn::Name::Component::Component ( const std::vector< uint8_t > &  value)
inline

Create a new GENERIC Name::Component, copying the given value.

(To create an ImplicitSha256Digest component, use fromImplicitSha256Digest.)

Parameters
valueThe value byte array.
ndn::Name::Component::Component ( const uint8_t *  value,
size_t  valueLength 
)
inline

Create a new GENERIC Name::Component, copying the given value.

(To create an ImplicitSha256Digest component, use fromImplicitSha256Digest.)

Parameters
valuePointer to the value byte array.
valueLengthLength of value.
ndn::Name::Component::Component ( const char *  value)
inline

Create a new GENERIC Name::Component, copying the bytes from the value string.

NOTE: This does not escape XX values. If you need to escape, use Name::fromEscapedString. Also, if the string has "/", this does not split into separate components. If you need that then use Name(value).

Parameters
valueA null-terminated string with the bytes to copy.
ndn::Name::Component::Component ( const std::string &  value)
inline

Create a new GENERIC Name::Component, copying the bytes from the value string.

NOTE: This does not escape XX values. If you need to escape, use Name::fromEscapedString. Also, if the string has "/", this does not split into separate components. If you need that then use Name(value).

Parameters
valueA string with the bytes to copy.
ndn::Name::Component::Component ( const Blob value)
inline

Create a new GENERIC Name::Component, taking another pointer to the Blob value.

(To create an ImplicitSha256Digest component, use fromImplicitSha256Digest.)

Parameters
valueA blob with a pointer to an immutable array. The pointer is copied.
ndn::Name::Component::Component ( const NameLite::Component componentLite)
inline

Create a new Name::Component, copying bytes from the NameLite::Component value and using its type.

Parameters
componentLiteA NameLite::Component with the values to copy.

Member Function Documentation

int ndn::Name::Component::compare ( const Component other) const

Compare this to the other Component using NDN canonical ordering.

Parameters
otherThe other Component to compare with.
Returns
0 If they compare equal, -1 if *this comes before other in the canonical ordering, or 1 if *this comes after other in the canonical ordering.
See also
http://named-data.net/doc/0.2/technical/CanonicalOrder.html
bool ndn::Name::Component::equals ( const Component other) const
inline

Check if this is the same component as other.

Parameters
otherThe other Component to compare with.
Returns
true if the components are equal, otherwise false.
Name::Component ndn::Name::Component::fromImplicitSha256Digest ( const Blob digest)
static

Create a component of type ImplicitSha256DigestComponent, so that isImplicitSha256Digest() is true.

Parameters
digestThe SHA-256 digest value.
Returns
The new Component.
Exceptions
runtime_errorIf the digest length is not ndn_SHA256_DIGEST_SIZE bytes.
static Component ndn::Name::Component::fromImplicitSha256Digest ( const uint8_t *  digest,
size_t  digestLength 
)
inlinestatic

Create a component of type ImplicitSha256DigestComponent, so that isImplicitSha256Digest() is true.

Parameters
digestA pointer to the SHA-256 digest value.
digestLengthLength of digest, which must be ndn_SHA256_DIGEST_SIZE.
digestThe SHA-256 digest value.
Returns
The new Component.
Exceptions
runtime_errorIf digestLength is not ndn_SHA256_DIGEST_SIZE bytes.
static Component ndn::Name::Component::fromImplicitSha256Digest ( const std::vector< uint8_t > &  digest)
inlinestatic

Create a component of type ImplicitSha256DigestComponent, so that isImplicitSha256Digest() is true.

Parameters
digestThe SHA-256 digest value.
Returns
The new Component.
Exceptions
runtime_errorIf the digest length is not ndn_SHA256_DIGEST_SIZE bytes.
Name::Component ndn::Name::Component::fromNumber ( uint64_t  number)
static

Create a GENERIC component whose value is the nonNegativeInteger encoding of the number.

Parameters
numberThe number to be encoded.
Returns
The component value.
Name::Component ndn::Name::Component::fromNumberWithMarker ( uint64_t  number,
uint8_t  marker 
)
static

Create a GENERIC component whose value is the marker appended with the nonNegativeInteger encoding of the number.

Parameters
numberThe number to be encoded.
markerThe marker to use as the first byte of the component.
Returns
The component value.
Name::Component ndn::Name::Component::fromNumberWithPrefix ( uint64_t  number,
const uint8_t *  prefix,
size_t  prefixLength 
)
static

Create a GENERIC component whose value is the prefix appended with the network-ordered encoding of the number.

Note: if the number is zero, no bytes are used for the number - the result will have only the prefix.

Parameters
numberThe number to be encoded.
prefixThe prefix to use as the first bytes of the component.
prefixLengthThe length of prefix.
Returns
The component value.
static Component ndn::Name::Component::fromSegment ( uint64_t  segment)
inlinestatic

Create a component with the encoded segment number according to NDN naming conventions for "Segment number" (marker 0x00).

http://named-data.net/doc/tech-memos/naming-conventions.pdf

Parameters
segmentThe segment number.
Returns
The new Component.
static Component ndn::Name::Component::fromSegmentOffset ( uint64_t  segmentOffset)
inlinestatic

Create a component with the encoded segment byte offset according to NDN naming conventions for segment "Byte offset" (marker 0xFB).

http://named-data.net/doc/tech-memos/naming-conventions.pdf

Parameters
segmentOffsetThe segment byte offset.
Returns
The new Component.
static Component ndn::Name::Component::fromSequenceNumber ( uint64_t  sequenceNumber)
inlinestatic

Create a component with the encoded sequence number according to NDN naming conventions for "Sequencing" (marker 0xFE).

http://named-data.net/doc/tech-memos/naming-conventions.pdf

Parameters
sequenceNumberThe sequence number.
Returns
The new Component.
static Component ndn::Name::Component::fromTimestamp ( uint64_t  timestamp)
inlinestatic

Create a component with the encoded timestamp according to NDN naming conventions for "Timestamp" (marker 0xFC).

http://named-data.net/doc/tech-memos/naming-conventions.pdf

Parameters
timestampThe number of microseconds since the UNIX epoch (Thursday, 1 January 1970) not counting leap seconds.
Returns
The new Component.
static Component ndn::Name::Component::fromVersion ( uint64_t  version)
inlinestatic

Create a component with the encoded version number according to NDN naming conventions for "Versioning" (marker 0xFD).

http://named-data.net/doc/tech-memos/naming-conventions.pdf Note that this encodes the exact value of version without converting from a time representation.

Parameters
versionThe version number.
Returns
The new Component.
void ndn::Name::Component::get ( NameLite::Component componentLite) const

Set componentLite to point to this component, without copying any memory.

WARNING: The resulting pointer in componentLite is invalid after a further use of this object which could reallocate memory.

Parameters
componentLiteThe NameLite::Component to receive the pointer.
static const uint8_t* ndn::Name::Component::getFinalSegmentPrefix ( )
inlinestatic
static size_t ndn::Name::Component::getFinalSegmentPrefixLength ( )
inlinestatic
Name::Component ndn::Name::Component::getSuccessor ( ) const

Get the successor of this component, as described in Name::getSuccessor.

Returns
A new Name::Component which is the successor of this.
bool ndn::Name::Component::hasPrefix ( const uint8_t *  prefix,
size_t  prefixLength 
) const

Check if this name component begins with the given prefix.

Parameters
prefixThe required prefix of the component.
prefixLengthThe length of prefix.
Returns
true if this component begins with the prefix.
bool DEPRECATED_IN_NDN_CPP ndn::Name::Component::isFinalSegment ( ) const
inline
bool ndn::Name::Component::isGeneric ( ) const
inline

Check if this component is a generic component.

Returns
True if this is an generic component.
bool ndn::Name::Component::isImplicitSha256Digest ( ) const
inline

Check if this component is an ImplicitSha256Digest component.

Returns
True if this is an ImplicitSha256Digest component.
bool ndn::Name::Component::isSegment ( ) const
inline

Check if this component is a segment number according to NDN naming conventions for "Segment number" (marker 0x00) and return an integer.

http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns
True if this is a segment number.
bool ndn::Name::Component::isSegmentOffset ( ) const
inline

Check if this component is a segment byte offset according to NDN naming conventions for "Byte offset" (marker 0xFB) and return an integer.

http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns
True if this is a segment byte offset.
bool ndn::Name::Component::isSequenceNumber ( ) const
inline

Check if this component is a sequence number according to NDN naming conventions for "Sequencing" (marker 0xFE) and return an integer.

http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns
True if this is a sequence number.
bool ndn::Name::Component::isTimestamp ( ) const
inline

Check if this component is a timestamp according to NDN naming conventions for "Timestamp" (marker 0xFC) and return an integer.

http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns
True if this is a timestamp.
bool ndn::Name::Component::isVersion ( ) const
inline

Check if this component is a version number according to NDN naming conventions for "Versioning" (marker 0xFD) and return an integer.

http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns
True if this is a version number.
bool ndn::Name::Component::operator!= ( const Component other) const
inline

Check if this is not the same component as other.

Parameters
otherThe other Component to compare with.
Returns
true if the components are not equal, otherwise false.
bool ndn::Name::Component::operator< ( const Component other) const
inline

Return true if this is less than the other Component in the NDN canonical ordering.

Parameters
otherThe other Component to compare with.
See also
http://named-data.net/doc/0.2/technical/CanonicalOrder.html
bool ndn::Name::Component::operator<= ( const Component other) const
inline

Return true if this is less than or equal to the other Component in the NDN canonical ordering.

Parameters
otherThe other Component to compare with.
See also
http://named-data.net/doc/0.2/technical/CanonicalOrder.html
bool ndn::Name::Component::operator== ( const Component other) const
inline

Check if this is the same component as other.

Parameters
otherThe other Component to compare with.
Returns
true if the components are equal, otherwise false.
bool ndn::Name::Component::operator> ( const Component other) const
inline

Return true if this is greater than the other Component in the NDN canonical ordering.

Parameters
otherThe other Component to compare with.
See also
http://named-data.net/doc/0.2/technical/CanonicalOrder.html
bool ndn::Name::Component::operator>= ( const Component other) const
inline

Return true if this is less than or equal to the other Component in the NDN canonical ordering.

Parameters
otherThe other Component to compare with.
See also
http://named-data.net/doc/0.2/technical/CanonicalOrder.html
void ndn::Name::Component::toEscapedString ( std::ostringstream &  result) const

Write this component value to result, escaping characters according to the NDN URI Scheme.

This also adds "..." to a value with zero or more ".". This adds a type code prefix as needed, such as "sha256digest=".

Parameters
resultthe string stream to write to.
std::string ndn::Name::Component::toEscapedString ( ) const

Convert this component value by escaping characters according to the NDN URI Scheme.

This also adds "..." to a value with zero or more ".". This adds a type code prefix as needed, such as "sha256digest=".

Returns
The escaped string.
uint64_t DEPRECATED_IN_NDN_CPP ndn::Name::Component::toFinalSegment ( ) const
inline
uint64_t ndn::Name::Component::toNumber ( ) const

Interpret this name component as a network-ordered number and return an integer.

Returns
The integer number.
uint64_t ndn::Name::Component::toNumberWithMarker ( uint8_t  marker) const

Interpret this name component as a network-ordered number with a marker and return an integer.

Parameters
markerThe required first byte of the component.
Returns
The integer number.
Exceptions
runtime_errorIf the first byte of the component does not equal the marker.
uint64_t ndn::Name::Component::toNumberWithPrefix ( const uint8_t *  prefix,
size_t  prefixLength 
) const

Interpret this name component as a network-ordered number with a prefix and return an integer.

Parameters
prefixThe required prefix of the component.
prefixLengthThe length of prefix.
Returns
The integer number.
Exceptions
runtime_errorIf the first bytes of the component do not equal the prefix.
uint64_t ndn::Name::Component::toSegment ( ) const
inline

Interpret this name component as a segment number according to NDN naming conventions for "Segment number" (marker 0x00).

http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns
The integer segment number.
Exceptions
runtime_errorIf the first byte of the component is not the expected marker.
uint64_t ndn::Name::Component::toSegmentOffset ( ) const
inline

Interpret this name component as a segment byte offset according to NDN naming conventions for segment "Byte offset" (marker 0xFB).

http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns
The integer segment byte offset.
Exceptions
runtime_errorIf the first byte of the component is not the expected marker.
uint64_t DEPRECATED_IN_NDN_CPP ndn::Name::Component::toSeqNum ( ) const
inline
Deprecated:
Use toSegment.
uint64_t ndn::Name::Component::toSequenceNumber ( ) const
inline

Interpret this name component as a sequence number according to NDN naming conventions for "Sequencing" (marker 0xFE).

http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns
The integer sequence number.
Exceptions
runtime_errorIf the first byte of the component is not the expected marker.
uint64_t ndn::Name::Component::toTimestamp ( ) const
inline

Interpret this name component as a timestamp according to NDN naming conventions for "Timestamp" (marker 0xFC).

http://named-data.net/doc/tech-memos/naming-conventions.pdf

Returns
The number of microseconds since the UNIX epoch (Thursday, 1 January 1970) not counting leap seconds.
Exceptions
runtime_errorIf the first byte of the component is not the expected marker.
uint64_t ndn::Name::Component::toVersion ( ) const
inline

Interpret this name component as a version number according to NDN naming conventions for "Versioning" (marker 0xFD).

Note that this returns the exact number from the component without converting it to a time representation.

Returns
The integer version number.
Exceptions
runtime_errorIf the first byte of the component is not the expected marker.

The documentation for this class was generated from the following files: