VSM C++ SDK
Vehicle Specific Modules SDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ugcs::vsm::Io_buffer Class Reference

Generic I/O buffer. More...

#include <io_buffer.h>

Inheritance diagram for ugcs::vsm::Io_buffer:

Public Types

typedef std::shared_ptr
< Io_buffer
Ptr
 Pointer type.
 
typedef std::weak_ptr< Io_bufferWeak_ptr
 Pointer type.
 

Public Member Functions

 Io_buffer (const Io_buffer &buf, size_t offset=0, size_t len=END)
 Copy constructor. More...
 
 Io_buffer (Io_buffer &&buf)
 Move constructor. More...
 
 Io_buffer (std::shared_ptr< const std::vector< uint8_t >> &&data_vec, size_t offset=0, size_t len=END)
 Construct from data provided in vector. More...
 
 Io_buffer (std::vector< uint8_t > &&data_vec, size_t offset=0, size_t len=END)
 Construct from data provided in vector. More...
 
 Io_buffer ()
 Construct empty buffer. More...
 
 Io_buffer (const std::string &data_str)
 Construct buffer from string. More...
 
 Io_buffer (const void *data, size_t len)
 Construct buffer from provided bytes array. More...
 
Ptr Concatenate (Io_buffer::Ptr buf)
 Concatenate this buffer data with another buffer data and return new buffer object which contains resulted data. More...
 
Ptr Slice (size_t offset, size_t len=END) const
 Take slice from buffer data. More...
 
size_t Get_length () const
 Get length of the contained data. More...
 
const void * Get_data () const
 Get pointer to raw data stored in the buffer. More...
 
std::string Get_string () const
 Get buffer content as string. More...
 
std::string Get_ascii () const
 Get buffer data as string of characters. More...
 
std::string Get_hex () const
 Get buffer data as hex string.
 

Static Public Member Functions

template<typename... Args>
static Ptr Create (Args &&...args)
 Create an instance. More...
 

Static Public Attributes

static const size_t END
 Special value which references data end. More...
 

Detailed Description

Generic I/O buffer.

Used for all I/O operations with network, filesystem, peripheral devices. Should always be passed by Io_buffer::Ptr smart pointer type. This allows anyone to hold reference to the buffer until he needs to access data and release the buffer when it last reference released.

Important: the buffer object is immutable - once it is created its data cannot be modified. It is required not confuse other reference holders. If modified buffer is required it can be easily created based on existing one via different constructors, operators and methods. Create() method should be used for obtaining Io_buffer instance.

Constructor & Destructor Documentation

ugcs::vsm::Io_buffer::Io_buffer ( const Io_buffer buf,
size_t  offset = 0,
size_t  len = END 
)

Copy constructor.

Parameters
bufBuffer to copy from.
offsetOffset in bytes to reference data in the source buffer.
lenLength in bytes of the referenced data. Value END indicates that all remaining data are taken.
Exceptions
Invalid_param_exceptionif the specified offset or length exceeds the source buffer boundary.
ugcs::vsm::Io_buffer::Io_buffer ( Io_buffer &&  buf)

Move constructor.

ugcs::vsm::Io_buffer::Io_buffer ( std::shared_ptr< const std::vector< uint8_t >> &&  data_vec,
size_t  offset = 0,
size_t  len = END 
)
explicit

Construct from data provided in vector.

Typical usage is for data which are firstly received from some I/O call.

Parameters
data_vecVector with data. Should be dynamically allocated by "std::make_shared()". Keep in mind that it can be passed somewhere else only by shared pointer.
offsetOffset in data vector where this buffer data start from.
lenLength of the data referenced in the provided vector. Offset and length should not exceed vector boundary. Value END indicates that all remaining data in vector should be used.
Exceptions
Invalid_param_exceptionif the specified offset or length exceeds the source buffer boundary.
ugcs::vsm::Io_buffer::Io_buffer ( std::vector< uint8_t > &&  data_vec,
size_t  offset = 0,
size_t  len = END 
)

Construct from data provided in vector.

See constructor which accepts "std::shared_ptr<const std::vector<uint8_t>> &&" for more details.

ugcs::vsm::Io_buffer::Io_buffer ( )

Construct empty buffer.

ugcs::vsm::Io_buffer::Io_buffer ( const std::string &  data_str)

Construct buffer from string.

Null terminator is not included in the data. Data are copied.

ugcs::vsm::Io_buffer::Io_buffer ( const void *  data,
size_t  len 
)

Construct buffer from provided bytes array.

Data are copied.

Parameters
dataBytes array with data.
lenNumber of bytes to take from data argument.

Member Function Documentation

Ptr ugcs::vsm::Io_buffer::Concatenate ( Io_buffer::Ptr  buf)

Concatenate this buffer data with another buffer data and return new buffer object which contains resulted data.

Note, that method complexity is linear if lengths of both buffers are not zero.

Parameters
bufBuffer to concatenate with.
Returns
New buffer with data from this buffer and the specified one.
template<typename... Args>
static Ptr ugcs::vsm::Io_buffer::Create ( Args &&...  args)
inlinestatic

Create an instance.

std::string ugcs::vsm::Io_buffer::Get_ascii ( ) const

Get buffer data as string of characters.

Non-printable chars are substituted with '.'

const void* ugcs::vsm::Io_buffer::Get_data ( ) const

Get pointer to raw data stored in the buffer.

Exceptions
Invalid_op_exceptionif the buffer is empty.
size_t ugcs::vsm::Io_buffer::Get_length ( ) const
inline

Get length of the contained data.

std::string ugcs::vsm::Io_buffer::Get_string ( ) const

Get buffer content as string.

Ptr ugcs::vsm::Io_buffer::Slice ( size_t  offset,
size_t  len = END 
) const

Take slice from buffer data.

Parameters
offsetOffset to start slice from.
lenLength of the slice data. Value END indicates that all remaining data should be taken.
Returns
New buffer with sliced data.
Exceptions
Invalid_param_exceptionif the specified offset or length exceeds the source buffer boundary.

Member Data Documentation

const size_t ugcs::vsm::Io_buffer::END
static

Special value which references data end.


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