CppSerdes  1.0
A serialization/deserialization library designed with embedded systems in mind
serdes::array< T, ST > Struct Template Reference

a container for fixed or dynamically sized arrays, with an upper bounds limit for safety More...

#include <serdes_format_modifiers.h>

Public Types

using elem_type = typename detail::has_data_and_size< T >::elem_type
 

Public Member Functions

template<size_t max_elements>
constexpr array (T(&v)[max_elements], const ST &s) noexcept
 Construct a new array object from an existing array and a referenced size. More...
 
template<size_t max_elements>
constexpr array (T(&v)[max_elements], const ST &&s) noexcept
 Construct a new array object from an existing array and a rvalue size. More...
 
constexpr array (T *v, ST &s, const ST max_elements) noexcept
 Construct a new array object from a pointer to the head of the array, a referenced dynamic size, and a constant max size. More...
 
constexpr array (T *v, const ST &&s, const ST max_elements) noexcept
 Construct a new array object from a pointer to the head of the array, a rvalue dynamic size, and a constant max size. More...
 
 array (T &v, const ST &s) noexcept
 Construct a new "dynamically" sized array object from a data container with 'T* data()' and 'size_t size()' methods (such as std::array, or std::list) More...
 
 array (T &v, const ST &&s) noexcept
 Construct a new "fixed" sized array object from a data container with 'T* data()' and 'size_t size()' methods (such as std::array, or std::list) More...
 
 array (T &v) noexcept
 Construct a new "fixed" sized array object from a data container with 'T* data()' and 'size_t size()' methods (such as std::array, or std::list) More...
 

Public Attributes

elem_typevalue
 a pointer to the array head
 
const ST rvalue_size
 holds onto an rvalue size if provide (so that const ST &size can have a local reference)
 
const ST & size
 a reference to a value that contains the dynamic size of the array for fixed sized arrays (where the size term is a rvalue temp), size will just refer to max_size since they're the same in that case if rvalue <= size, otherwise max will be set to 0 to force as size error
 
const size_t max_size
 maximum size of the array (used for bounds checking)
 

Detailed Description

template<typename T, typename ST>
struct serdes::array< T, ST >

a container for fixed or dynamically sized arrays, with an upper bounds limit for safety

Template Parameters
Tthe array element type
STthe type of the variable used by reference to adjust and report the array size
Examples
06_variable_length_formats.cpp, 13_arrays_of_packets.cpp, and 14_custom_types.cpp.

Member Typedef Documentation

◆ elem_type

template<typename T , typename ST >
using serdes::array< T, ST >::elem_type = typename detail::has_data_and_size<T>::elem_type

if the array is from a container with a "P* T.data()" method, elem_type will be P otherwise, elem_type will be T, allowing support for c-arrays (no data method) and std::array, std::list, std::vector, etc. (any c-array abstraction layer with a data() method)

Constructor & Destructor Documentation

◆ array() [1/7]

template<typename T , typename ST >
template<size_t max_elements>
constexpr serdes::array< T, ST >::array ( T(&)  v[max_elements],
const ST &  s 
)
inlineconstexprnoexcept

Construct a new array object from an existing array and a referenced size.

Template Parameters
max_elementsmaximum number of elements in the array
Parameters
vreference to the underlying array
sreference to a value representing the dynamic array size

◆ array() [2/7]

template<typename T , typename ST >
template<size_t max_elements>
constexpr serdes::array< T, ST >::array ( T(&)  v[max_elements],
const ST &&  s 
)
inlineconstexprnoexcept

Construct a new array object from an existing array and a rvalue size.

Template Parameters
max_elements
Parameters
vreference to the underlying array
sa rvalue representing the dynamic array size

◆ array() [3/7]

template<typename T , typename ST >
constexpr serdes::array< T, ST >::array ( T *  v,
ST &  s,
const ST  max_elements 
)
inlineconstexprnoexcept

Construct a new array object from a pointer to the head of the array, a referenced dynamic size, and a constant max size.

Parameters
vpointer to the head of the array
sreference to a value representing the dynamic array size
max_elementsmaximum size of the array

◆ array() [4/7]

template<typename T , typename ST >
constexpr serdes::array< T, ST >::array ( T *  v,
const ST &&  s,
const ST  max_elements 
)
inlineconstexprnoexcept

Construct a new array object from a pointer to the head of the array, a rvalue dynamic size, and a constant max size.

Parameters
vpointer to the head of the array
srvalue representing the dynamic array size
max_elementsmaximum size of the array

◆ array() [5/7]

template<typename T , typename ST >
serdes::array< T, ST >::array ( T &  v,
const ST &  s 
)
inlinenoexcept

Construct a new "dynamically" sized array object from a data container with 'T* data()' and 'size_t size()' methods (such as std::array, or std::list)

Parameters
vreference to the data container whose underlying data should be used as the array
sreference to a value representing the "dynamic" array size

◆ array() [6/7]

template<typename T , typename ST >
serdes::array< T, ST >::array ( T &  v,
const ST &&  s 
)
inlinenoexcept

Construct a new "fixed" sized array object from a data container with 'T* data()' and 'size_t size()' methods (such as std::array, or std::list)

Parameters
vreference to the data container whose underlying data should be used as the array
srvalue representing the "fixed" array size

◆ array() [7/7]

template<typename T , typename ST >
serdes::array< T, ST >::array ( T &  v)
inlinenoexcept

Construct a new "fixed" sized array object from a data container with 'T* data()' and 'size_t size()' methods (such as std::array, or std::list)

Parameters
vreference to the data container whose underlying data should be used as the array

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