COMMS
Template library intended to help with implementation of communication protocols.
|
#include "comms/field/Bundle.h"
Bundles multiple fields into a single field.
The class wraps nicely multiple fields and provides expected single field API functions, such as length(), read(), write(), valid(). It may be useful when a collection (comms::field::ArrayList) of complex fields is required.
Refer to Bundle Fields for tutorial and usage examples.
TFieldBase | Base class for this field, expected to be a variant of comms::Field. |
TMembers | All wrapped fields bundled together in std::tuple. |
TOptions | Zero or more options that modify/refine default behaviour of the field. Supported options are:
|
Public Types | |
using | CommsTag = typename BaseImpl::CommsTag |
Tag indicating type of the field. | |
using | Endian = typename BaseImpl::Endian |
Endian used for serialisation. | |
using | FieldBase = TFieldBase |
Base class provided in the first template parameter. | |
using | FieldType = typename ParsedOptions::FieldType |
Type of actual extending field specified via comms::option::def::FieldType. | |
using | ParsedOptions = details::OptionsParser< TOptions... > |
All the options provided to this class bundled into struct. | |
using | ValueType = typename BaseImpl::ValueType |
Value type. | |
using | VersionType = typename BaseImpl::VersionType |
Version type. | |
Public Member Functions | |
Bundle ()=default | |
Default constructor. | |
Bundle (const ValueType &val) | |
Constructor. | |
Bundle (ValueType &&val) | |
Constructor. | |
bool | canWrite () const |
Check of whether the field has a consistent value for writing. | |
const ValueType & | getValue () const |
Get value. | |
VersionType | getVersion () const |
Get version of the field. | |
std::size_t | length () const |
Get length required to serialise bundled fields. | |
template<std::size_t TFromIdx> | |
std::size_t | lengthFrom () const |
Get length required to serialise specified bundled member fields. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx> | |
std::size_t | lengthFromUntil () const |
Get length required to serialise specified bundled member fields. | |
template<std::size_t TUntilIdx> | |
std::size_t | lengthUntil () const |
Get length required to serialise specified bundled member fields. | |
template<typename TIter > | |
ErrorStatus | read (TIter &iter, std::size_t size) |
Read field value from input data sequence. | |
template<std::size_t TFromIdx, typename TIter > | |
ErrorStatus | readFrom (TIter &iter, std::size_t len) |
Read selected number of member fields (from specified index). | |
template<std::size_t TFromIdx, typename TIter > | |
ErrorStatus | readFromAndUpdateLen (TIter &iter, std::size_t &len) |
Read selected number of member fields (from specified index) while updating remaining length information. | |
template<std::size_t TFromIdx, typename TIter > | |
void | readFromNoStatus (TIter &iter) |
Read selected member fields from input data sequence without error check and status report. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx, typename TIter > | |
ErrorStatus | readFromUntil (TIter &iter, std::size_t len) |
Read selected number of member fields (between specified indices). | |
template<std::size_t TFromIdx, std::size_t TUntilIdx, typename TIter > | |
ErrorStatus | readFromUntilAndUpdateLen (TIter &iter, std::size_t &len) |
Read selected number of member fields (between specified indices) while updating remaining length information. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx, typename TIter > | |
void | readFromUntilNoStatus (TIter &iter) |
Read selected member fields from input data sequence without error check and status report. | |
template<typename TIter > | |
void | readNoStatus (TIter &iter) |
Read field value from input data sequence without error check and status report. | |
template<std::size_t TUntilIdx, typename TIter > | |
ErrorStatus | readUntil (TIter &iter, std::size_t len) |
Read selected number of member fields (until specified index). | |
template<std::size_t TUntilIdx, typename TIter > | |
ErrorStatus | readUntilAndUpdateLen (TIter &iter, std::size_t &len) |
Read selected number of member fields (until specified index) while updating remaining length information. | |
template<std::size_t TUntilIdx, typename TIter > | |
void | readUntilNoStatus (TIter &iter) |
Read selected member fields from input data sequence without error check and status report. | |
bool | refresh () |
Refresh the field's contents. | |
template<typename U > | |
void | setValue (U &&val) |
Set value. | |
bool | setVersion (VersionType version) |
Default implementation of version update. | |
bool | valid () const |
Check validity of all the bundled fields. | |
ValueType & | value () |
Get access to the stored tuple of fields. | |
const ValueType & | value () const |
Get access to the stored tuple of fields. | |
template<typename TIter > | |
ErrorStatus | write (TIter &iter, std::size_t size) const |
Write current field value to output data sequence. | |
template<std::size_t TFromIdx, typename TIter > | |
ErrorStatus | writeFrom (TIter &iter, std::size_t size) const |
Write selected member fields to output data sequence. | |
template<std::size_t TFromIdx, typename TIter > | |
void | writeFromNoStatus (TIter &iter) |
Write selected member fields to output data sequence without error check and status report. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx, typename TIter > | |
ErrorStatus | writeFromUntil (TIter &iter, std::size_t size) const |
Write selected member fields to output data sequence. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx, typename TIter > | |
void | writeFromUntilNoStatus (TIter &iter) |
Write selected member fields to output data sequence without error check and status report. | |
template<typename TIter > | |
void | writeNoStatus (TIter &iter) const |
Write current field value to output data sequence without error check and status report. | |
template<std::size_t TUntilIdx, typename TIter > | |
ErrorStatus | writeUntil (TIter &iter, std::size_t size) const |
Write selected member fields to output data sequence. | |
template<std::size_t TUntilIdx, typename TIter > | |
void | writeUntilNoStatus (TIter &iter) |
Write selected member fields to output data sequence without error check and status report. | |
Static Public Member Functions | |
static constexpr bool | canWrite () |
Default check of whether the field has a consistent value for writing. | |
static constexpr bool | hasEmptySerialization () |
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used. | |
static constexpr bool | hasFailOnInvalid () |
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used. | |
static constexpr bool | hasFieldType () |
Compile time inquiry of whether comms::option::def::FieldType option has been used. | |
static constexpr bool | hasIgnoreInvalid () |
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used. | |
static constexpr bool | hasNonDefaultRefresh () |
Compile time check if this class has non-default refresh functionality. | |
static constexpr bool | hasReadNoStatus () |
Compile time check of whether the field has proper readNoStatus() member function (or similar). | |
static constexpr bool | hasVarLength () |
Default check of whether the field has variable length definition via comms::option::def::VarLength option. | |
static constexpr bool | hasWriteNoStatus () |
Compile time check of whether the field has proper writeNoStatus() member function. | |
static constexpr bool | isVersionDependent () |
Compile time check if this class is version dependent. | |
static constexpr std::size_t | maxLength () |
Get maximal length that is required to serialise all bundled fields. | |
template<std::size_t TFromIdx> | |
static constexpr std::size_t | maxLengthFrom () |
Get maximal length that is required to serialise specified bundled fields. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx> | |
static constexpr std::size_t | maxLengthFromUntil () |
Get maximal length that is required to serialise specified bundled fields. | |
template<std::size_t TUntilIdx> | |
static constexpr std::size_t | maxLengthUntil () |
Get maximal length that is required to serialise specified bundled fields. | |
static constexpr std::size_t | minLength () |
Get minimal length that is required to serialise all bundled fields. | |
template<std::size_t TFromIdx> | |
static constexpr std::size_t | minLengthFrom () |
Get minimal length that is required to serialise specified bundled fields. | |
template<std::size_t TFromIdx, std::size_t TUntilIdx> | |
static constexpr std::size_t | minLengthFromUntil () |
Get minimal length that is required to serialise specified bundled fields. | |
template<std::size_t TUntilIdx> | |
static constexpr std::size_t | minLengthUntil () |
Get minimal length that is required to serialise specified bundled fields. | |
static constexpr bool | valid () |
Default validity check. | |
Static Protected Member Functions | |
template<typename T , typename TIter > | |
static T | readData (TIter &iter) |
Read data from input buffer. | |
template<typename T , std::size_t TSize, typename TIter > | |
static T | readData (TIter &iter) |
Read partial data from input buffer. | |
template<typename T , typename TIter > | |
static void | writeData (T value, TIter &iter) |
Write data into the output buffer. | |
template<std::size_t TSize, typename T , typename TIter > | |
static void | writeData (T value, TIter &iter) |
Write partial data into the output buffer. | |
Related Symbols | |
(Note that these are not member symbols.) | |
template<typename T > | |
constexpr bool | isBundle () |
Compile time check function of whether a provided type is any variant of comms::field::Bundle. | |
template<typename TFieldBase , typename TMembers , typename... TOptions> | |
bool | operator!= (const Bundle< TFieldBase, TMembers, TOptions... > &field1, const Bundle< TFieldBase, TMembers, TOptions... > &field2) noexcept |
Non-equality comparison operator. | |
template<typename TFieldBase , typename TMembers , typename... TOptions> | |
bool | operator< (const Bundle< TFieldBase, TMembers, TOptions... > &field1, const Bundle< TFieldBase, TMembers, TOptions... > &field2) noexcept |
Equivalence comparison operator. | |
template<typename TFieldBase , typename TMembers , typename... TOptions> | |
bool | operator<= (const Bundle< TFieldBase, TMembers, TOptions... > &field1, const Bundle< TFieldBase, TMembers, TOptions... > &field2) noexcept |
Equivalence comparison operator. | |
template<typename TFieldBase , typename TMembers , typename... TOptions> | |
bool | operator== (const Bundle< TFieldBase, TMembers, TOptions... > &field1, const Bundle< TFieldBase, TMembers, TOptions... > &field2) noexcept |
Equality comparison operator. | |
template<typename TFieldBase , typename TMembers , typename... TOptions> | |
bool | operator> (const Bundle< TFieldBase, TMembers, TOptions... > &field1, const Bundle< TFieldBase, TMembers, TOptions... > &field2) noexcept |
Equivalence comparison operator. | |
template<typename TFieldBase , typename TMembers , typename... TOptions> | |
bool | operator>= (const Bundle< TFieldBase, TMembers, TOptions... > &field1, const Bundle< TFieldBase, TMembers, TOptions... > &field2) noexcept |
Equivalence comparison operator. | |
using comms::field::Bundle< TFieldBase, TMembers, TOptions >::FieldType = typename ParsedOptions::FieldType |
Type of actual extending field specified via comms::option::def::FieldType.
void if comms::option::def::FieldType hasn't been applied.
using comms::field::Bundle< TFieldBase, TMembers, TOptions >::ValueType = typename BaseImpl::ValueType |
Value type.
Same as TMemebers template argument, i.e. it is std::tuple of all the wrapped fields.
|
default |
Default constructor.
Invokes default constructor of every wrapped field
|
staticconstexprinherited |
Default check of whether the field has a consistent value for writing.
const ValueType & comms::field::Bundle< TFieldBase, TMembers, TOptions >::getValue | ( | ) | const |
Get value.
Implemented by calling value(), but can be overriden in the derived class
VersionType comms::field::Bundle< TFieldBase, TMembers, TOptions >::getVersion | ( | ) | const |
Get version of the field.
Exists only if comms::option::def::VersionStorage option has been provided.
|
staticconstexprinherited |
Default check of whether the field has variable length definition via comms::option::def::VarLength option.
std::size_t comms::field::Bundle< TFieldBase, TMembers, TOptions >::length | ( | ) | const |
Get length required to serialise bundled fields.
Summarises all the results returned by the call to length() for every field in the bundle.
std::size_t comms::field::Bundle< TFieldBase, TMembers, TOptions >::lengthFrom | ( | ) | const |
Get length required to serialise specified bundled member fields.
Summarises all the results returned by the call to length() for every specified field in the bundle.
TFromIdx | Index of the field (included) from which the counting must start. |
std::size_t comms::field::Bundle< TFieldBase, TMembers, TOptions >::lengthFromUntil | ( | ) | const |
Get length required to serialise specified bundled member fields.
Summarises all the results returned by the call to length() for every specified field in the bundle.
TFromIdx | Index of the field (included) from which the counting must start. |
TUntilIdx | Index of the field (not included) until which the counting must be performed. |
std::size_t comms::field::Bundle< TFieldBase, TMembers, TOptions >::lengthUntil | ( | ) | const |
Get length required to serialise specified bundled member fields.
Summarises all the results returned by the call to length() for every specified field in the bundle.
TUntilIdx | Index of the field (not included) until which the counting must be performed. |
|
staticconstexpr |
Get maximal length that is required to serialise all bundled fields.
|
staticconstexpr |
Get maximal length that is required to serialise specified bundled fields.
TFromIdx | Index of the field (included) from which the counting must start. |
|
staticconstexpr |
Get maximal length that is required to serialise specified bundled fields.
TFromIdx | Index of the field (included) from which the counting must start. |
TUntilIdx | Index of the field (not included) until which the counting must be performed. |
|
staticconstexpr |
Get maximal length that is required to serialise specified bundled fields.
TUntilIdx | Index of the field (not included) until which the counting must be performed. |
|
staticconstexpr |
Get minimal length that is required to serialise all bundled fields.
|
staticconstexpr |
Get minimal length that is required to serialise specified bundled fields.
TFromIdx | Index of the field (included) from which the counting must start. |
|
staticconstexpr |
Get minimal length that is required to serialise specified bundled fields.
TFromIdx | Index of the field (included) from which the counting must start. |
TUntilIdx | Index of the field (not included) until which the counting must be performed. |
|
staticconstexpr |
Get minimal length that is required to serialise specified bundled fields.
TUntilIdx | Index of the field (not included) until which the counting must be performed. |
ErrorStatus comms::field::Bundle< TFieldBase, TMembers, TOptions >::read | ( | TIter & | iter, |
std::size_t | size | ||
) |
Read field value from input data sequence.
Invokes read() member function over every bundled field.
[in,out] | iter | Iterator to read the data. |
[in] | size | Number of bytes available for reading. |
|
staticprotectedinherited |
Read data from input buffer.
Use this function to read data from the intput buffer maintained by the caller. The endianness of the data will be as specified in options of the class.
T | Return type |
TIter | Type of input iterator |
[in,out] | iter | Input iterator. |
|
staticprotectedinherited |
Read partial data from input buffer.
Use this function to read data from the intput buffer maintained by the caller. The endianness of the data will be as specified in options of the class.
T | Return type |
TSize | number of bytes to read |
TIter | Type of input iterator |
[in,out] | iter | Input iterator. |
ErrorStatus comms::field::Bundle< TFieldBase, TMembers, TOptions >::readFrom | ( | TIter & | iter, |
std::size_t | len | ||
) |
Read selected number of member fields (from specified index).
Similar to read(), but invokes read() member function of only selected member fields.
TFromIdx | Index of the member field (included) from which the "read" operation starts |
[in,out] | iter | Iterator to read the data. |
[in] | len | Number of bytes available for reading. |
ErrorStatus comms::field::Bundle< TFieldBase, TMembers, TOptions >::readFromAndUpdateLen | ( | TIter & | iter, |
std::size_t & | len | ||
) |
Read selected number of member fields (from specified index) while updating remaining length information.
Similar to readFrom(), but updates provided length information. Number of consumed bytes are subsctruced from provided length value.
TFromIdx | Index of the member field (included) from which the "read" operation starts |
[in,out] | iter | Iterator to read the data. |
[in,out] | len | Number of bytes available for reading. |
void comms::field::Bundle< TFieldBase, TMembers, TOptions >::readFromNoStatus | ( | TIter & | iter | ) |
Read selected member fields from input data sequence without error check and status report.
Similar to readNoStatus(), but invokes readNoStatus() of only selected member fields.
TFromIdx | Index of the member field (included) from which the "read" operation starts |
[in,out] | iter | Iterator to read the data. |
ErrorStatus comms::field::Bundle< TFieldBase, TMembers, TOptions >::readFromUntil | ( | TIter & | iter, |
std::size_t | len | ||
) |
Read selected number of member fields (between specified indices).
Similar to read(), but invokes read() member function of only selected member fields.
TFromIdx | Index of the member field (included) from which the "read" operation starts |
TUntilIdx | Index of the member field (NOT included) until which the "read" operation continues. |
[in,out] | iter | Iterator to read the data. |
[in] | len | Number of bytes available for reading. |
ErrorStatus comms::field::Bundle< TFieldBase, TMembers, TOptions >::readFromUntilAndUpdateLen | ( | TIter & | iter, |
std::size_t & | len | ||
) |
Read selected number of member fields (between specified indices) while updating remaining length information.
Similar to readFromUntil(), but updates provided length information. Number of consumed bytes are subsctruced from provided length value.
TFromIdx | Index of the member field (included) from which the "read" operation starts |
TUntilIdx | Index of the member field (NOT included) until which the "read" operation continues. |
[in,out] | iter | Iterator to read the data. |
[in,out] | len | Number of bytes available for reading. |
void comms::field::Bundle< TFieldBase, TMembers, TOptions >::readFromUntilNoStatus | ( | TIter & | iter | ) |
Read selected member fields from input data sequence without error check and status report.
Similar to readNoStatus(), but invokes readNoStatus() of only selected member fields.
TFromIdx | Index of the member field (included) from which the "read" operation starts |
TUntilIdx | Index of the member field (NOT included) until which the "read" operation continues. |
[in,out] | iter | Iterator to read the data. |
void comms::field::Bundle< TFieldBase, TMembers, TOptions >::readNoStatus | ( | TIter & | iter | ) |
Read field value from input data sequence without error check and status report.
Similar to read(), but doesn't perform any correctness checks and doesn't report any failures.
[in,out] | iter | Iterator to read the data. |
ErrorStatus comms::field::Bundle< TFieldBase, TMembers, TOptions >::readUntil | ( | TIter & | iter, |
std::size_t | len | ||
) |
Read selected number of member fields (until specified index).
Similar to read(), but invokes read() member function of only selected member fields.
TUntilIdx | Index of the member field (NOT included) until which the "read" operation continues. |
[in,out] | iter | Iterator to read the data. |
[in] | len | Number of bytes available for reading. |
ErrorStatus comms::field::Bundle< TFieldBase, TMembers, TOptions >::readUntilAndUpdateLen | ( | TIter & | iter, |
std::size_t & | len | ||
) |
Read selected number of member fields (until specified index) while updating remaining length information.
Similar to readUntil(), but updates provided length information. Number of consumed bytes are subsctruced from provided length value.
TUntilIdx | Index of the member field (NOT included) until which the "read" operation continues. |
[in,out] | iter | Iterator to read the data. |
[in,out] | len | Number of bytes available for reading. |
void comms::field::Bundle< TFieldBase, TMembers, TOptions >::readUntilNoStatus | ( | TIter & | iter | ) |
Read selected member fields from input data sequence without error check and status report.
Similar to readNoStatus(), but invokes readNoStatus() of only selected member fields.
TUntilIdx | Index of the member field (NOT included) until which the "read" operation continues. |
[in,out] | iter | Iterator to read the data. |
bool comms::field::Bundle< TFieldBase, TMembers, TOptions >::refresh | ( | ) |
Refresh the field's contents.
Calls refresh() member function on every member field, will return true if any of the calls returns true.
void comms::field::Bundle< TFieldBase, TMembers, TOptions >::setValue | ( | U && | val | ) |
Set value.
Implemented as re-assigning to value(), but can be overriden in the derived class.
bool comms::field::Bundle< TFieldBase, TMembers, TOptions >::setVersion | ( | VersionType | version | ) |
Default implementation of version update.
|
staticconstexprinherited |
Default validity check.
Always returns true, can be overriden by the derived class
ErrorStatus comms::field::Bundle< TFieldBase, TMembers, TOptions >::write | ( | TIter & | iter, |
std::size_t | size | ||
) | const |
Write current field value to output data sequence.
Invokes write() member function over every bundled field.
[in,out] | iter | Iterator to write the data. |
[in] | size | Maximal number of bytes that can be written. |
|
staticprotectedinherited |
Write data into the output buffer.
Use this function to write data to the the buffer maintained by the caller. The endianness of the data will be as specified in the options provided to the class.
T | Type of the value to write. Must be integral. |
Type | of output iterator |
[in] | value | Integral type value to be written. |
[in,out] | iter | Output iterator. |
|
staticprotectedinherited |
Write partial data into the output buffer.
Use this function to write partial data to the buffer maintained by the caller. The endianness of the data will be as specified the class options.
TSize | Length of the value in bytes known in compile time. |
T | Type of the value to write. Must be integral. |
TIter | Type of output iterator |
[in] | value | Integral type value to be written. |
[in,out] | iter | Output iterator. |
ErrorStatus comms::field::Bundle< TFieldBase, TMembers, TOptions >::writeFrom | ( | TIter & | iter, |
std::size_t | size | ||
) | const |
Write selected member fields to output data sequence.
Similar to write(), but invokes write member function of only selected member fields.
TFromIdx | Index of the member field (included) from which the "write" operation starts. |
[in,out] | iter | Iterator to write the data. |
[in] | size | Maximal number of bytes that can be written. |
void comms::field::Bundle< TFieldBase, TMembers, TOptions >::writeFromNoStatus | ( | TIter & | iter | ) |
Write selected member fields to output data sequence without error check and status report.
Similar to writeNoStatus(), but invokes writeNoStatus() of only selected member fields.
TFromIdx | Index of the member field (included) from which the "write" operation starts |
[in,out] | iter | Iterator to read the data. |
ErrorStatus comms::field::Bundle< TFieldBase, TMembers, TOptions >::writeFromUntil | ( | TIter & | iter, |
std::size_t | size | ||
) | const |
Write selected member fields to output data sequence.
Similar to write(), but invokes write member function of only selected member fields.
TFromIdx | Index of the member field (included) from which the "write" operation starts. |
TUntilIdx | Index of the member field (NOT included) until which the "write" operation continues. |
[in,out] | iter | Iterator to write the data. |
[in] | size | Maximal number of bytes that can be written. |
void comms::field::Bundle< TFieldBase, TMembers, TOptions >::writeFromUntilNoStatus | ( | TIter & | iter | ) |
Write selected member fields to output data sequence without error check and status report.
Similar to writeNoStatus(), but invokes writeNoStatus() of only selected member fields.
TFromIdx | Index of the member field (included) from which the "write" operation starts |
TUntilIdx | Index of the member field (NOT included) until which the "write" operation continues. |
[in,out] | iter | Iterator to read the data. |
void comms::field::Bundle< TFieldBase, TMembers, TOptions >::writeNoStatus | ( | TIter & | iter | ) | const |
Write current field value to output data sequence without error check and status report.
Similar to write(), but doesn't perform any correctness checks and doesn't report any failures.
[in,out] | iter | Iterator to write the data. |
ErrorStatus comms::field::Bundle< TFieldBase, TMembers, TOptions >::writeUntil | ( | TIter & | iter, |
std::size_t | size | ||
) | const |
Write selected member fields to output data sequence.
Similar to write(), but invokes write member function of only selected member fields.
TUntilIdx | Index of the member field (NOT included) until which the "write" operation continues. |
[in,out] | iter | Iterator to write the data. |
[in] | size | Maximal number of bytes that can be written. |
void comms::field::Bundle< TFieldBase, TMembers, TOptions >::writeUntilNoStatus | ( | TIter & | iter | ) |
Write selected member fields to output data sequence without error check and status report.
Similar to writeNoStatus(), but invokes writeNoStatus() of only selected member fields.
TUntilIdx | Index of the member field (NOT included) until which the "write" operation continues. |
[in,out] | iter | Iterator to read the data. |
|
related |
Compile time check function of whether a provided type is any variant of comms::field::Bundle.
T | Any type. |
|
related |
Non-equality comparison operator.
[in] | field1 | First field. |
[in] | field2 | Second field. |
|
related |
Equivalence comparison operator.
[in] | field1 | First field. |
[in] | field2 | Second field. |
|
related |
Equivalence comparison operator.
[in] | field1 | First field. |
[in] | field2 | Second field. |
|
related |
Equality comparison operator.
[in] | field1 | First field. |
[in] | field2 | Second field. |
|
related |
Equivalence comparison operator.
[in] | field1 | First field. |
[in] | field2 | Second field. |
|
related |
Equivalence comparison operator.
[in] | field1 | First field. |
[in] | field2 | Second field. |