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

Component holds a read-only name component value. More...

#include <name-component.hpp>

Inheritance diagram for ndn::name::Component:
[legend]
Collaboration diagram for ndn::name::Component:
[legend]

Data Structures

class  Error
 Error that can be thrown from name::Component. More...
 

Public Types

typedef std::vector< Blockelement_container
 
typedef element_container::iterator element_iterator
 
typedef
element_container::const_iterator 
element_const_iterator
 

Public Member Functions

 Component ()
 Create a new Name::Component with a null value. More...
 
 Component (const Block &wire)
 Directly create component from wire block. More...
 
 Component (const ConstBufferPtr &buffer)
 Create a new Name::Component, taking another pointer to the Blob value. More...
 
 Component (const Buffer &value)
 Create a new Name::Component, copying the given value. More...
 
 Component (const uint8_t *value, size_t valueLen)
 Create a new Name::Component, copying the given value. More...
 
template<class InputIterator >
 Component (InputIterator begin, InputIterator end)
 
 Component (const char *str)
 
 Component (const std::string &str)
 
template<bool T>
size_t wireEncode (EncodingImpl< T > &block) const
 Fast encoding or block size estimation. More...
 
const BlockwireEncode () const
 Encode to a wire format. More...
 
void wireDecode (const Block &wire)
 Decode from the wire format. More...
 
void toEscapedString (std::ostream &result) const
 Write the value to result, escaping characters according to the NDN URI Scheme. More...
 
std::string toEscapedString () const
 Convert the value by escaping characters according to the NDN URI Scheme. More...
 
void toUri (std::ostream &result) const
 
std::string toUri () const
 
uint64_t toNumber () const
 Interpret this name component as nonNegativeInteger. More...
 
uint64_t toVersion () const
 An alias for toNumber() More...
 
uint64_t toSegment () const
 An alias for toNumber() More...
 
bool equals (const Component &other) const
 Check if this is the same component as other. More...
 
bool empty () const
 
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...
 
bool hasWire () const
 Check if the Block has fully encoded wire. More...
 
bool hasValue () const
 Check if the Block has value block (no type and length are encoded) More...
 
void reset ()
 Reset wire buffer of the element. More...
 
void resetWire ()
 Reset wire buffer but keep sub elements (if any) More...
 
void parse () const
 Parse wire buffer into subblocks. More...
 
void encode ()
 Encode subblocks into wire buffer. More...
 
uint32_t type () const
 
const Blockget (uint32_t type) const
 Get the first subelement of the requested type. More...
 
element_const_iterator find (uint32_t type) const
 
void remove (uint32_t type)
 
element_iterator erase (element_iterator position)
 
element_iterator erase (element_iterator first, element_iterator last)
 
void push_back (const Block &element)
 
Buffer::const_iterator begin () const
 
Buffer::const_iterator end () const
 
const uint8_t * wire () const
 
size_t size () const
 
Buffer::const_iterator value_begin () const
 
Buffer::const_iterator value_end () const
 
const uint8_t * value () const
 
size_t value_size () const
 
const element_containerelements () const
 Get all subelements. More...
 
element_const_iterator elements_begin () const
 
element_const_iterator elements_end () const
 
size_t elements_size () const
 
Block blockFromValue () const
 
bool operator== (const Block &other) const
 
bool operator!= (const Block &other) const
 

Static Public Member Functions

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 NDN URI Scheme. More...
 
static Component fromEscapedString (const char *escapedString)
 Make a Blob value by decoding the escapedString according to the NDN URI Scheme. More...
 
static Component fromEscapedString (const std::string &escapedString)
 Make a Blob value by decoding the escapedString according to the NDN URI Scheme. More...
 
static Component fromNumber (uint64_t number)
 Create a component encoded as nonNegativeInteger. More...
 
static bool fromBuffer (const ConstBufferPtr &wire, size_t offset, Block &block)
 Try to construct block from Buffer, referencing data block pointed by wire. More...
 
static bool fromBuffer (const uint8_t *buffer, size_t maxSize, Block &block)
 Try to construct block from Buffer, referencing data block pointed by wire. More...
 

Protected Attributes

ConstBufferPtr m_buffer
 
uint32_t m_type
 
Buffer::const_iterator m_begin
 
Buffer::const_iterator m_end
 
uint32_t m_size
 
Buffer::const_iterator m_value_begin
 
Buffer::const_iterator m_value_end
 
element_container m_subBlocks
 

Detailed Description

Component holds a read-only name component value.

Definition at line 24 of file name-component.hpp.

Member Typedef Documentation

typedef element_container::const_iterator ndn::Block::element_const_iterator
inherited

Definition at line 31 of file block.hpp.

typedef std::vector<Block> ndn::Block::element_container
inherited

Definition at line 29 of file block.hpp.

typedef element_container::iterator ndn::Block::element_iterator
inherited

Definition at line 30 of file block.hpp.

Constructor & Destructor Documentation

ndn::name::Component::Component ( )
inline

Create a new Name::Component with a null value.

Definition at line 310 of file name-component.hpp.

ndn::name::Component::Component ( const Block wire)
inline

Directly create component from wire block.

Any block can be implicitly converted to name::Component

Exceptions
Errorif wire.type() is not Tlv::Component

Definition at line 316 of file name-component.hpp.

ndn::name::Component::Component ( const ConstBufferPtr buffer)
inlineexplicit

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

Parameters
valueA blob with a pointer to an immutable array. The pointer is copied.

Definition at line 324 of file name-component.hpp.

ndn::name::Component::Component ( const Buffer value)
inlineexplicit

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

Parameters
valueThe value byte array.

Definition at line 330 of file name-component.hpp.

ndn::name::Component::Component ( const uint8_t *  value,
size_t  valueLen 
)
inline

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

Parameters
valuePointer to the value byte array.
valueLenLength of value.

Definition at line 336 of file name-component.hpp.

template<class InputIterator >
ndn::name::Component::Component ( InputIterator  begin,
InputIterator  end 
)
inline

Definition at line 343 of file name-component.hpp.

ndn::name::Component::Component ( const char *  str)
inlineexplicit

Definition at line 349 of file name-component.hpp.

ndn::name::Component::Component ( const std::string &  str)
inlineexplicit

Definition at line 355 of file name-component.hpp.

Member Function Documentation

Buffer::const_iterator ndn::Block::begin ( ) const
inlineinherited

Definition at line 397 of file block.hpp.

Block ndn::Block::blockFromValue ( ) const
inherited

Definition at line 352 of file block.cpp.

int ndn::name::Component::compare ( const Component other) const
inline

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

Definition at line 455 of file name-component.hpp.

const Block::element_container & ndn::Block::elements ( ) const
inlineinherited

Get all subelements.

Definition at line 464 of file block.hpp.

Block::element_const_iterator ndn::Block::elements_begin ( ) const
inlineinherited

Definition at line 470 of file block.hpp.

Block::element_const_iterator ndn::Block::elements_end ( ) const
inlineinherited

Definition at line 476 of file block.hpp.

size_t ndn::Block::elements_size ( ) const
inlineinherited

Definition at line 482 of file block.hpp.

bool ndn::name::Component::empty ( ) const
inline

Definition at line 228 of file name-component.hpp.

void ndn::Block::encode ( )
inherited

Encode subblocks into wire buffer.

Definition at line 298 of file block.cpp.

Buffer::const_iterator ndn::Block::end ( ) const
inlineinherited

Definition at line 406 of file block.hpp.

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.

Definition at line 215 of file name-component.hpp.

Block::element_iterator ndn::Block::erase ( Block::element_iterator  position)
inlineinherited

Definition at line 375 of file block.hpp.

Block::element_iterator ndn::Block::erase ( Block::element_iterator  first,
Block::element_iterator  last 
)
inlineinherited

Definition at line 382 of file block.hpp.

Block::element_const_iterator ndn::Block::find ( uint32_t  type) const
inlineinherited

Definition at line 343 of file block.hpp.

bool ndn::Block::fromBuffer ( const ConstBufferPtr wire,
size_t  offset,
Block block 
)
staticinherited

Try to construct block from Buffer, referencing data block pointed by wire.

Exceptions
Thismethod never throws an exception
Returns
true if Block successfully created, false if block cannot be created

Definition at line 209 of file block.cpp.

bool ndn::Block::fromBuffer ( const uint8_t *  buffer,
size_t  maxSize,
Block block 
)
staticinherited

Try to construct block from Buffer, referencing data block pointed by wire.

Exceptions
Thismethod never throws an exception
Returns
true if Block successfully created, false if block cannot be created

Definition at line 236 of file block.cpp.

Component ndn::name::Component::fromEscapedString ( const char *  escapedString,
size_t  beginOffset,
size_t  endOffset 
)
inlinestatic

Make a Blob value by decoding the escapedString between beginOffset and endOffset according to the NDN URI Scheme.

If the escaped string is "", "." or ".." then return a Blob with a null pointer, which means the component should be skipped in a URI name.

Parameters
escapedStringThe escaped string. It does not need to be null-terminated because we only scan to endOffset.
beginOffsetThe offset in escapedString of the beginning of the portion to decode.
endOffsetThe offset in escapedString of the end of the portion to decode.
Returns
The Blob value. If the escapedString is not a valid escaped component, then the Blob is a null pointer.

Definition at line 362 of file name-component.hpp.

static Component ndn::name::Component::fromEscapedString ( const char *  escapedString)
inlinestatic

Make a Blob value by decoding the escapedString according to the NDN URI Scheme.

If the escaped string is "", "." or ".." then return a Blob with a null pointer, which means the component should be skipped in a URI name.

Parameters
escapedStringThe null-terminated escaped string.
Returns
The Blob value. If the escapedString is not a valid escaped component, then the Blob is a null pointer.

Definition at line 123 of file name-component.hpp.

static Component ndn::name::Component::fromEscapedString ( const std::string &  escapedString)
inlinestatic

Make a Blob value by decoding the escapedString according to the NDN URI Scheme.

If the escaped string is "", "." or ".." then return a Blob with a null pointer, which means the component should be skipped in a URI name.

Parameters
escapedStringThe escaped string.
Returns
The Blob value. If the escapedString is not a valid escaped component, then the Blob is a null pointer.

Definition at line 136 of file name-component.hpp.

Component ndn::name::Component::fromNumber ( uint64_t  number)
inlinestatic

Create a component encoded as nonNegativeInteger.

See Also
http://named-data.net/doc/ndn-tlv/tlv.html#non-negative-integer-encoding
Parameters
numberThe non-negative number
Returns
The component value.
Todo:
Change to Tlv::NumberComponent

Definition at line 427 of file name-component.hpp.

const Block & ndn::Block::get ( uint32_t  type) const
inlineinherited

Get the first subelement of the requested type.

Definition at line 326 of file block.hpp.

bool ndn::Block::hasValue ( ) const
inlineinherited

Check if the Block has value block (no type and length are encoded)

Definition at line 294 of file block.hpp.

bool ndn::Block::hasWire ( ) const
inlineinherited

Check if the Block has fully encoded wire.

Definition at line 288 of file block.hpp.

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.

Definition at line 247 of file name-component.hpp.

bool ndn::Block::operator!= ( const Block other) const
inlineinherited

Definition at line 495 of file block.hpp.

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

Definition at line 276 of file name-component.hpp.

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

Definition at line 267 of file name-component.hpp.

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.

Definition at line 239 of file name-component.hpp.

bool ndn::Block::operator== ( const Block other) const
inlineinherited

Definition at line 488 of file block.hpp.

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

Definition at line 294 of file name-component.hpp.

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

Definition at line 285 of file name-component.hpp.

void ndn::Block::parse ( ) const
inherited

Parse wire buffer into subblocks.

This method is not really const, but it does not modify any data. It simply parses contents of the buffer into subblocks

Definition at line 265 of file block.cpp.

void ndn::Block::push_back ( const Block element)
inlineinherited

Definition at line 390 of file block.hpp.

void ndn::Block::remove ( uint32_t  type)
inlineinherited

Definition at line 358 of file block.hpp.

void ndn::Block::reset ( )
inlineinherited

Reset wire buffer of the element.

Definition at line 300 of file block.hpp.

void ndn::Block::resetWire ( )
inlineinherited

Reset wire buffer but keep sub elements (if any)

Definition at line 310 of file block.hpp.

size_t ndn::Block::size ( ) const
inlineinherited

Definition at line 415 of file block.hpp.

void ndn::name::Component::toEscapedString ( std::ostream &  result) const
inline

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

This also adds "..." to a value with zero or more ".".

Parameters
valuethe buffer with the value to escape
resultthe string stream to write to.

Definition at line 383 of file name-component.hpp.

std::string ndn::name::Component::toEscapedString ( ) const
inline

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

This also adds "..." to a value with zero or more ".".

Parameters
valuethe buffer with the value to escape
Returns
The escaped string.

Definition at line 157 of file name-component.hpp.

uint64_t ndn::name::Component::toNumber ( ) const
inline

Interpret this name component as nonNegativeInteger.

See Also
http://named-data.net/doc/ndn-tlv/tlv.html#non-negative-integer-encoding
Returns
The integer number.
Todo:
Check if Component is of Tlv::NumberComponent type

Definition at line 435 of file name-component.hpp.

uint64_t ndn::name::Component::toSegment ( ) const
inline

An alias for toNumber()

Definition at line 449 of file name-component.hpp.

void ndn::name::Component::toUri ( std::ostream &  result) const
inline

Definition at line 165 of file name-component.hpp.

std::string ndn::name::Component::toUri ( ) const
inline

Definition at line 171 of file name-component.hpp.

uint64_t ndn::name::Component::toVersion ( ) const
inline

An alias for toNumber()

Definition at line 443 of file name-component.hpp.

uint32_t ndn::Block::type ( ) const
inlineinherited

Definition at line 320 of file block.hpp.

const uint8_t * ndn::Block::value ( ) const
inlineinherited

Definition at line 446 of file block.hpp.

Buffer::const_iterator ndn::Block::value_begin ( ) const
inlineinherited

Definition at line 425 of file block.hpp.

Buffer::const_iterator ndn::Block::value_end ( ) const
inlineinherited

Definition at line 431 of file block.hpp.

size_t ndn::Block::value_size ( ) const
inlineinherited

Definition at line 455 of file block.hpp.

const uint8_t * ndn::Block::wire ( ) const
inlineinherited

Definition at line 437 of file block.hpp.

void ndn::name::Component::wireDecode ( const Block wire)
inline

Decode from the wire format.

Definition at line 506 of file name-component.hpp.

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

Fast encoding or block size estimation.

Definition at line 473 of file name-component.hpp.

const Block & ndn::name::Component::wireEncode ( ) const
inline

Encode to a wire format.

Definition at line 487 of file name-component.hpp.

Field Documentation

Buffer::const_iterator ndn::Block::m_begin
protectedinherited

Definition at line 265 of file block.hpp.

ConstBufferPtr ndn::Block::m_buffer
protectedinherited

Definition at line 261 of file block.hpp.

Buffer::const_iterator ndn::Block::m_end
protectedinherited

Definition at line 266 of file block.hpp.

uint32_t ndn::Block::m_size
protectedinherited

Definition at line 267 of file block.hpp.

element_container ndn::Block::m_subBlocks
mutableprotectedinherited

Definition at line 272 of file block.hpp.

uint32_t ndn::Block::m_type
protectedinherited

Definition at line 263 of file block.hpp.

Buffer::const_iterator ndn::Block::m_value_begin
protectedinherited

Definition at line 269 of file block.hpp.

Buffer::const_iterator ndn::Block::m_value_end
protectedinherited

Definition at line 270 of file block.hpp.