ndn::Buffer Class Reference

General-purpose automatically managed/resized buffer. More...

#include <ndn-cxx/encoding/buffer.hpp>

+ Inheritance diagram for ndn::Buffer:
+ Collaboration diagram for ndn::Buffer:

Public Member Functions

 Buffer ()=default
 Creates an empty Buffer. More...
 
 Buffer (Buffer &&) noexcept
 Move constructor. More...
 
 Buffer (const Buffer &)
 Copy constructor. More...
 
 Buffer (const void *buf, size_t length)
 Creates a Buffer by copying contents from a raw buffer. More...
 
template<class InputIt >
 Buffer (InputIt first, InputIt last)
 Creates a Buffer by copying the elements of the range [first, last) More...
 
 Buffer (size_t size)
 Creates a Buffer with pre-allocated size. More...
 
 Buffer (std::initializer_list< uint8_t > il)
 Creates a Buffer with the contents of an initializer list. More...
 
template<class T >
const T * get () const noexcept
 
template<class T >
T * get () noexcept
 
Bufferoperator= (Buffer &&) noexcept
 Move assignment operator. More...
 
Bufferoperator= (const Buffer &)
 Copy assignment operator. More...
 

Public Attributes

elements
 STL member. More...
 

Detailed Description

General-purpose automatically managed/resized buffer.

In most respect, the Buffer class is equivalent to a std::vector<uint8_t>, and it in fact uses the latter as a base class. In addition to that, it provides the get<T>() helper method that automatically casts the returned pointer to the requested type.

Definition at line 42 of file buffer.hpp.

Constructor & Destructor Documentation

◆ Buffer() [1/7]

ndn::Buffer::Buffer ( )
default

Creates an empty Buffer.

◆ Buffer() [2/7]

ndn::Buffer::Buffer ( const Buffer )
inlinedefault

Copy constructor.

◆ Buffer() [3/7]

ndn::Buffer::Buffer ( Buffer &&  )
inlinedefaultnoexcept

Move constructor.

◆ Buffer() [4/7]

ndn::Buffer::Buffer ( size_t  size)
inlineexplicit

Creates a Buffer with pre-allocated size.

Parameters
sizesize of the Buffer to be allocated

Definition at line 71 of file buffer.hpp.

◆ Buffer() [5/7]

ndn::Buffer::Buffer ( const void *  buf,
size_t  length 
)
inline

Creates a Buffer by copying contents from a raw buffer.

Parameters
bufconst pointer to buffer to copy
lengthlength of the buffer to copy

Definition at line 80 of file buffer.hpp.

◆ Buffer() [6/7]

template<class InputIt >
ndn::Buffer::Buffer ( InputIt  first,
InputIt  last 
)
inline

Creates a Buffer by copying the elements of the range [first, last)

Parameters
firstan input iterator to the first element to copy
lastan input iterator to the element immediately following the last element to copy

Definition at line 91 of file buffer.hpp.

◆ Buffer() [7/7]

ndn::Buffer::Buffer ( std::initializer_list< uint8_t >  il)
inline

Creates a Buffer with the contents of an initializer list.

Definition at line 98 of file buffer.hpp.

Member Function Documentation

◆ get() [1/2]

template<class T >
const T* ndn::Buffer::get ( ) const
inlinenoexcept
Returns
const pointer to the first byte of the buffer, cast to the requested type T

Definition at line 116 of file buffer.hpp.

◆ get() [2/2]

template<class T >
T* ndn::Buffer::get ( )
inlinenoexcept
Returns
pointer to the first byte of the buffer, cast to the requested type T

Definition at line 107 of file buffer.hpp.

◆ operator=() [1/2]

Buffer & ndn::Buffer::operator= ( Buffer &&  )
inlinedefaultnoexcept

Move assignment operator.

◆ operator=() [2/2]

Buffer & ndn::Buffer::operator= ( const Buffer )
inlinedefault

Copy assignment operator.

Member Data Documentation

◆ elements

T std::vector< T >::elements
inherited

STL member.