All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ndn::Name Class Reference

A Name holds an array of Name::Component and represents an NDN name. More...

#include <name.hpp>

Inheritance diagram for ndn::Name:
[legend]
Collaboration diagram for ndn::Name:
[legend]

Data Structures

class  Error
 Error that can be thrown from Name. More...
 

Public Types

typedef name::Component Component
 
typedef std::vector< Componentcomponent_container
 
typedef Component value_type
 
typedef void allocator_type
 
typedef Componentreference
 
typedef const Component const_reference
 
typedef Componentpointer
 
typedef const Componentconst_pointer
 
typedef Componentiterator
 
typedef const Componentconst_iterator
 
typedef
boost::reverse_iterator
< iterator
reverse_iterator
 
typedef
boost::reverse_iterator
< const_iterator
const_reverse_iterator
 
typedef
component_container::difference_type 
difference_type
 
typedef
component_container::size_type 
size_type
 

Public Member Functions

 Name ()
 Create a new Name with no components. More...
 
 Name (const Block &wire)
 Create Name object from wire block. More...
 
 Name (const char *uri)
 Parse the uri according to the NDN URI Scheme and create the name with the components. More...
 
 Name (const std::string &uri)
 Parse the uri according to the NDN URI Scheme and create the name with the components. More...
 
template<bool T>
size_t wireEncode (EncodingImpl< T > &block) const
 Fast encoding or block size estimation. More...
 
const BlockwireEncode () const
 
void wireDecode (const Block &wire)
 
bool hasWire () const
 Check if already has wire. More...
 
void set (const char *uri)
 Parse the uri according to the NDN URI Scheme and set the name with the components. More...
 
void set (const std::string &uri)
 Parse the uri according to the NDN URI Scheme and set the name with the components. More...
 
Nameappend (const uint8_t *value, size_t valueLength)
 Append a new component, copying from value of length valueLength. More...
 
template<class InputIterator >
Nameappend (InputIterator begin, InputIterator end)
 Append a new component, copying from value of length valueLength. More...
 
Nameappend (const ConstBufferPtr &value)
 
Nameappend (const Component &value)
 
Nameappend (const char *value)
 Append name component that represented as a string. More...
 
Nameappend (const Block &value)
 
Nameappend (const Name &name)
 Append the components of the given name to this name. More...
 
void clear ()
 Clear all the components. More...
 
Name getSubName (size_t iStartComponent, size_t nComponents) const
 Get a new name, constructed as a subset of components. More...
 
Name getSubName (size_t iStartComponent) const
 Get a new name, constructed as a subset of components starting at iStartComponent until the end of the name. More...
 
Name getPrefix (int nComponents) const
 Return a new Name with the first nComponents components of this Name. More...
 
std::string toUri () const
 Encode this name as a URI. More...
 
NameappendNumber (uint64_t number)
 Append a component with the number encoded as nonNegativeInteger. More...
 
NameappendVersion (uint64_t number)
 An alias for appendNumber(uint64_t) More...
 
NameappendVersion ()
 Append a component with the encoded version number (current UNIX timestamp in milliseconds) More...
 
NameappendSegment (uint64_t number)
 An alias for appendNumber(uint64_t) More...
 
bool equals (const Name &name) const
 Check if this name has the same component count and components as the given name. More...
 
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. More...
 
bool empty () const
 Check if name is emtpy. More...
 
size_t size () const
 Get the number of components. More...
 
const Componentget (ssize_t i) const
 Get the component at the given index. More...
 
const Componentoperator[] (ssize_t i) const
 
const Componentat (ssize_t i) const
 Get component at the specified index. More...
 
int compare (const Name &other) const
 Compare this to the other Name using NDN canonical ordering. More...
 
template<class T >
void push_back (const T &component)
 Append the component. More...
 
bool operator== (const Name &name) const
 Check if this name has the same component count and components as the given name. More...
 
bool operator!= (const Name &name) const
 Check if this name has the same component count and components as the given name. More...
 
bool operator<= (const Name &other) const
 Return true if this is less than or equal to the other Name in the NDN canonical ordering. More...
 
bool operator< (const Name &other) const
 Return true if this is less than the other Name in the NDN canonical ordering. More...
 
bool operator>= (const Name &other) const
 Return true if this is less than or equal to the other Name in the NDN canonical ordering. More...
 
bool operator> (const Name &other) const
 Return true if this is greater than the other Name in the NDN canonical ordering. More...
 
const_iterator begin () const
 Begin iterator (const). More...
 
const_iterator end () const
 End iterator (const). More...
 
const_reverse_iterator rbegin () const
 Reverse begin iterator (const). More...
 
const_reverse_iterator rend () const
 Reverse end iterator (const). More...
 

Detailed Description

A Name holds an array of Name::Component and represents an NDN name.

Definition at line 26 of file name.hpp.

Member Typedef Documentation

Definition at line 45 of file name.hpp.

Definition at line 40 of file name.hpp.

Definition at line 42 of file name.hpp.

Definition at line 51 of file name.hpp.

Definition at line 49 of file name.hpp.

Definition at line 47 of file name.hpp.

typedef boost::reverse_iterator<const_iterator> ndn::Name::const_reverse_iterator

Definition at line 54 of file name.hpp.

typedef component_container::difference_type ndn::Name::difference_type

Definition at line 56 of file name.hpp.

Definition at line 50 of file name.hpp.

Definition at line 48 of file name.hpp.

Definition at line 46 of file name.hpp.

typedef boost::reverse_iterator<iterator> ndn::Name::reverse_iterator

Definition at line 53 of file name.hpp.

typedef component_container::size_type ndn::Name::size_type

Definition at line 57 of file name.hpp.

Definition at line 44 of file name.hpp.

Constructor & Destructor Documentation

ndn::Name::Name ( )
inline

Create a new Name with no components.

Definition at line 62 of file name.hpp.

ndn::Name::Name ( const Block wire)
inlineexplicit

Create Name object from wire block.

This is a more efficient equivalent for

* Name name;
* name.wireDecode(wire);
*

Definition at line 77 of file name.hpp.

ndn::Name::Name ( const char *  uri)
inline

Parse the uri according to the NDN URI Scheme and create the name with the components.

Parameters
uriThe URI string.

Definition at line 87 of file name.hpp.

ndn::Name::Name ( const std::string &  uri)
inline

Parse the uri according to the NDN URI Scheme and create the name with the components.

Parameters
uriThe URI string.

Definition at line 96 of file name.hpp.

Member Function Documentation

Name& ndn::Name::append ( const uint8_t *  value,
size_t  valueLength 
)
inline

Append a new component, copying from value of length valueLength.

Returns
This name so that you can chain calls to append.

Definition at line 142 of file name.hpp.

template<class InputIterator >
Name& ndn::Name::append ( InputIterator  begin,
InputIterator  end 
)
inline

Append a new component, copying from value of length valueLength.

Returns
This name so that you can chain calls to append.

Definition at line 154 of file name.hpp.

Name& ndn::Name::append ( const ConstBufferPtr value)
inline

Definition at line 161 of file name.hpp.

Name& ndn::Name::append ( const Component value)
inline

Definition at line 168 of file name.hpp.

Name& ndn::Name::append ( const char *  value)
inline

Append name component that represented as a string.

Note that this method is necessary to ensure correctness and unambiguity of append("string") operations (both Component and Name can be implicitly converted from string, each having different outcomes

Definition at line 182 of file name.hpp.

Name& ndn::Name::append ( const Block value)
inline

Definition at line 189 of file name.hpp.

Name & ndn::Name::append ( const Name name)
inline

Append the components of the given name to this name.

Parameters
nameThe Name with components to append.
Returns
This name so that you can chain calls to append.

Definition at line 612 of file name.hpp.

Name& ndn::Name::appendNumber ( uint64_t  number)
inline

Append a component with the number encoded as nonNegativeInteger.

See Also
http://named-data.net/doc/ndn-tlv/tlv.html#non-negative-integer-encoding
Parameters
numberThe non-negative number
Returns
This name so that you can chain calls to append.

Definition at line 264 of file name.hpp.

Name& ndn::Name::appendSegment ( uint64_t  number)
inline

An alias for appendNumber(uint64_t)

Definition at line 290 of file name.hpp.

Name& ndn::Name::appendVersion ( uint64_t  number)
inline

An alias for appendNumber(uint64_t)

Definition at line 274 of file name.hpp.

Name & ndn::Name::appendVersion ( )
inline

Append a component with the encoded version number (current UNIX timestamp in milliseconds)

Definition at line 625 of file name.hpp.

const Component& ndn::Name::at ( ssize_t  i) const
inline

Get component at the specified index.

Unlike get() and operator[] methods, at() checks for out of bounds and will throw Name::Error when it happens

Exceptions
Name::Errorif index out of bounds

Definition at line 363 of file name.hpp.

const_iterator ndn::Name::begin ( ) const
inline

Begin iterator (const).

Definition at line 480 of file name.hpp.

void ndn::Name::clear ( )
inline

Clear all the components.

Definition at line 211 of file name.hpp.

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

Compare this to the other Name using NDN canonical ordering.

If the first components of each name are not equal, this returns -1 if the first comes before the second using the NDN canonical ordering for name components, or 1 if it comes after. If they are equal, this compares the second components of each name, etc. If both names are the same up to the size of the shorter name, this returns -1 if the first name is shorter than the second or 1 if it is longer. For example, if you std::sort gives: /a/b/d /a/b/cc /c /c/a /bb . This is intuitive because all names with the prefix /a are next to each other. But it may be also be counter-intuitive because /c comes before /bb according to NDN canonical ordering since it is shorter.

Parameters
otherThe other Name 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/ndn-tlv/name.html#canonical-order

Definition at line 686 of file name.hpp.

bool ndn::Name::empty ( ) const
inline

Check if name is emtpy.

Definition at line 319 of file name.hpp.

const_iterator ndn::Name::end ( ) const
inline

End iterator (const).

Todo:
Check if this crash when there are no elements in the buffer

Definition at line 491 of file name.hpp.

bool ndn::Name::equals ( const Name name) const
inline

Check if this name has the same component count and components as the given name.

Parameters
nameThe Name to check.
Returns
true if the names are equal, otherwise false.

Definition at line 655 of file name.hpp.

const Component& ndn::Name::get ( ssize_t  i) const
inline

Get the component at the given index.

Parameters
iThe index of the component, starting from 0.
Returns
The name component at the index.

Definition at line 340 of file name.hpp.

Name ndn::Name::getPrefix ( int  nComponents) const
inline

Return a new Name with the first nComponents components of this Name.

Parameters
nComponentsThe number of prefix components. If nComponents is -N then return the prefix up to name.size() - N. For example getPrefix(-1) returns the name without the final component.
Returns
A new Name.

Definition at line 240 of file name.hpp.

Name ndn::Name::getSubName ( size_t  iStartComponent,
size_t  nComponents 
) const
inline

Get a new name, constructed as a subset of components.

Parameters
iStartComponentThe index if the first component to get.
nComponentsThe number of components starting at iStartComponent.
Returns
A new name.

Definition at line 632 of file name.hpp.

Name ndn::Name::getSubName ( size_t  iStartComponent) const
inline

Get a new name, constructed as a subset of components starting at iStartComponent until the end of the name.

Parameters
iStartComponentThe index if the first component to get.
Returns
A new name.

Definition at line 644 of file name.hpp.

bool ndn::Name::hasWire ( ) const
inline

Check if already has wire.

Definition at line 756 of file name.hpp.

bool ndn::Name::isPrefixOf ( const Name name) const
inline

Check if the N components of this name are the same as the first N components of the given name.

Parameters
nameThe Name to check.
Returns
true if this matches the given name, otherwise false. This always returns true if this name is empty.

Definition at line 669 of file name.hpp.

bool ndn::Name::operator!= ( const Name name) const
inline

Check if this name has the same component count and components as the given name.

Parameters
nameThe Name to check.
Returns
true if the names are not equal, otherwise false.

Definition at line 419 of file name.hpp.

bool ndn::Name::operator< ( const Name other) const
inline

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

Parameters
otherThe other Name to compare with.
See Also
http://named-data.net/doc/ndn-tlv/name.html#canonical-order

Definition at line 443 of file name.hpp.

bool ndn::Name::operator<= ( const Name other) const
inline

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

Parameters
otherThe other Name to compare with.
See Also
http://named-data.net/doc/ndn-tlv/name.html#canonical-order

Definition at line 431 of file name.hpp.

bool ndn::Name::operator== ( const Name name) const
inline

Check if this name has the same component count and components as the given name.

Parameters
nameThe Name to check.
Returns
true if the names are equal, otherwise false.

Definition at line 408 of file name.hpp.

bool ndn::Name::operator> ( const Name other) const
inline

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

Parameters
otherThe other Name to compare with.
See Also
http://named-data.net/doc/ndn-tlv/name.html#canonical-order

Definition at line 467 of file name.hpp.

bool ndn::Name::operator>= ( const Name other) const
inline

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

Parameters
otherThe other Name to compare with.
See Also
http://named-data.net/doc/ndn-tlv/name.html#canonical-order

Definition at line 455 of file name.hpp.

const Component& ndn::Name::operator[] ( ssize_t  i) const
inline

Definition at line 349 of file name.hpp.

template<class T >
void ndn::Name::push_back ( const T &  component)
inline

Append the component.

Parameters
componentThe component of type T.

Definition at line 397 of file name.hpp.

const_reverse_iterator ndn::Name::rbegin ( ) const
inline

Reverse begin iterator (const).

Definition at line 500 of file name.hpp.

const_reverse_iterator ndn::Name::rend ( ) const
inline

Reverse end iterator (const).

Definition at line 509 of file name.hpp.

void ndn::Name::set ( const char *  uri)
inline

Parse the uri according to the NDN URI Scheme and set the name with the components.

Parameters
uriThe null-terminated URI string.

Definition at line 555 of file name.hpp.

void ndn::Name::set ( const std::string &  uri)
inline

Parse the uri according to the NDN URI Scheme and set the name with the components.

Parameters
uriThe URI string.

Definition at line 132 of file name.hpp.

size_t ndn::Name::size ( ) const
inline

Get the number of components.

Returns
The number of components.

Definition at line 329 of file name.hpp.

std::string ndn::Name::toUri ( ) const
inline

Encode this name as a URI.

Returns
The encoded URI.

Definition at line 536 of file name.hpp.

void ndn::Name::wireDecode ( const Block wire)
inline

Definition at line 746 of file name.hpp.

template<bool T>
size_t ndn::Name::wireEncode ( EncodingImpl< T > &  block) const
inline

Fast encoding or block size estimation.

Definition at line 711 of file name.hpp.

const Block & ndn::Name::wireEncode ( ) const
inline

Definition at line 728 of file name.hpp.