Class ArrayBuilder

Class Documentation

class ArrayBuilder

template class holding an array and the current index for write commands. Can be used to easily create an array for low level byte streams

The arraybuilder is intended to be used as a conversion queue for low level byte streams. Arbitrary data can be written into the arraybuider by calling the << operator. During this write operation the data will be convertet into a little endian representation regardles of the source architecture. This can be used when a Little Endian byte stream (i.e. for a serial device) is composed of several data types. Example: To send 1 int and to floats via bytestream in little endian ending: ArrayBuilder ab; ab << int << float1 << float2; send(ab.array); To read out values from the arraybuilder you can simply use the << operator. This will automatically convert the little endian representation to the byte order of the host system.

NOTE: As the arraybuilder converts the data during write and read operations the raw data that is read out from the stream has to be appended without any conversion (use appendWithoutConversion). (TODO: Is there a better Solution to this?)

Public Functions

inline ArrayBuilder(size_t array_size = 1)
void reset(size_t array_size = 1)

Resets the Arraybuilder to initial state, all values will be deleted.

Parameters:

array_size – size the array is supposed to have after reset

template<typename T>
inline void appendWithoutConversion(const T &data)

add data without any byte conversion

template<typename T>
inline void appendWithoutConversion(const std::vector<T> &data)

add data in vectors without any byte conversion

template<typename T>
ArrayBuilder &operator<<(const T &data)

Write any type into ArrayBuilder, convert to LittleEndian in process.

template<typename T>
ArrayBuilder &operator<<(const std::vector<T> &data)

Write vectors into ArrayBuilder, each element is written seperately and convert to LittleEndian in process

template<typename T>
ArrayBuilder &operator>>(T &data)

Read a generic data type from the array builder, Endianess is converted to system architecture.

Read arbitrary types from the arraybuilder, endianess is converted during readout.

template<typename T>
ArrayBuilder &operator>>(std::vector<T> &data)

Read a vectors from the array builder, Endianess is converted to system architecture.

Read a vectors from the array builder, Endianess is converted to system architecture, vector has to be initualized

template<typename T>
T readBack()

Read out the last data without removing it from the stream NOTE: This is only implemented for base types

Public Members

size_t write_pos

current write position in array

size_t read_pos

current read position in array

std::vector<uint8_t> array

array of template type TArray