COMMS
Template library intended to help with implementation of communication protocols.
|
#include "comms/field/String.h"
Field that represents a string.
By default uses std::string, for internal storage, unless comms::option::app::FixedSizeStorage option is used, which forces usage of comms::util::StaticString instead.
TFieldBase | Base class for this field, expected to be a variant of comms::Field. |
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. More... | |
using | ParsedOptions = details::OptionsParser< TOptions... > |
All the options provided to this class bundled into struct. | |
using | SerLengthFieldPrefix = typename ParsedOptions::SequenceSerLengthFieldPrefix |
Type of length field prefix specified via comms::option::def::SequenceSerLengthFieldPrefix. More... | |
using | SizeFieldPrefix = typename ParsedOptions::SequenceSizeFieldPrefix |
Type of size field prefix specified via comms::option::def::SequenceSizeFieldPrefix. More... | |
using | TerminationFieldSuffix = typename ParsedOptions::SequenceTerminationFieldSuffix |
Type of termination field suffix specified via comms::option::def::SequenceTerminationFieldSuffix. More... | |
using | TrailingFieldSuffix = typename ParsedOptions::SequenceTrailingFieldSuffix |
Type of trailing field suffix specified via comms::option::def::SequenceTrailingFieldSuffix. More... | |
using | ValueType = typename BaseImpl::ValueType |
Type of underlying value. More... | |
using | VersionType = typename BaseImpl::VersionType |
Version type. | |
Public Member Functions | |
String ()=default | |
Default constructor. | |
String (const char *str) | |
Constructor. | |
String (const String &)=default | |
Copy constructor. | |
String (const ValueType &val) | |
Constructor. | |
String (String &&)=default | |
Move constructor. | |
String (ValueType &&val) | |
Constructor. | |
~String () noexcept=default | |
Destructor. | |
bool | canWrite () const |
Check of whether the field has a consistent value for writing. | |
void | clearReadElemCount () |
Clear forcing of the number of characters that must be read in the next read() invocation. More... | |
void | clearReadLengthForcing () |
Clear forcing of the available length in the next read() invocation. More... | |
void | forceReadElemCount (std::size_t count) |
Force number of characters that must be read in the next read() invocation. More... | |
void | forceReadLength (std::size_t count) |
Force available length for the next read() invocation. More... | |
const ValueType & | getValue () const |
Get value. More... | |
VersionType | getVersion () const |
Get version of the field. More... | |
std::size_t | length () const |
Get length of serialised data. | |
String & | operator= (const String &)=default |
Copy assignment. | |
String & | operator= (String &&)=default |
Move assignment. | |
template<typename TIter > | |
ErrorStatus | read (TIter &iter, std::size_t len) |
Read field value from input data sequence. More... | |
template<typename TIter > | |
void | readNoStatus (TIter &iter) |
Read field value from input data sequence without error check and status report. More... | |
bool | refresh () |
Refresh the field's value. More... | |
template<typename U > | |
void | setValue (U &&val) |
Set value. More... | |
bool | setVersion (VersionType version) |
Default implementation of version update. More... | |
bool | valid () const |
Check validity of the field value. | |
ValueType & | value () |
Get access to the value storage. | |
const ValueType & | value () const |
Get access to the value storage. | |
template<typename TIter > | |
ErrorStatus | write (TIter &iter, std::size_t len) const |
Write current field value to output data sequence. More... | |
template<typename TIter > | |
void | writeNoStatus (TIter &iter) const |
Write current field value to output data sequence without error check and status report. More... | |
Static Public Member Functions | |
static constexpr bool | canWrite () |
Default check of whether the field has a consistent value for writing. More... | |
static constexpr bool | fixedSize () |
Compile time inquiry of fixed size provided via comms::option::def::SequenceFixedSize option. More... | |
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 | hasFixedSize () |
Compile time inquiry of whether comms::option::def::SequenceFixedSize 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. | |
static constexpr bool | hasSerLengthFieldPrefix () |
Compile time inquiry of whether comms::option::def::SequenceSerLengthFieldPrefix option has been used. | |
static constexpr bool | hasSizeFieldPrefix () |
Compile time inquiry of whether comms::option::def::SequenceSizeFieldPrefix option has been used. | |
static constexpr bool | hasTerminationFieldSuffix () |
Compile time inquiry of whether comms::option::def::SequenceTerminationFieldSuffix option has been used. | |
static constexpr bool | hasTrailingFieldSuffix () |
Compile time inquiry of whether comms::option::def::SequenceTrailingFieldSuffix option has been used. | |
static constexpr bool | hasVarLength () |
Default check of whether the field has variable length definition via comms::option::def::VarLength option. More... | |
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 field of this type. | |
static constexpr std::size_t | minLength () |
Get minimal length that is required to serialise field of this type. | |
static constexpr bool | valid () |
Default validity check. More... | |
Static Protected Member Functions | |
template<typename T , typename TIter > | |
static T | readData (TIter &iter) |
Read data from input buffer. More... | |
template<typename T , std::size_t TSize, typename TIter > | |
static T | readData (TIter &iter) |
Read partial data from input buffer. More... | |
template<typename T , typename TIter > | |
static void | writeData (T value, TIter &iter) |
Write data into the output buffer. More... | |
template<std::size_t TSize, typename T , typename TIter > | |
static void | writeData (T value, TIter &iter) |
Write partial data into the output buffer. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename T > | |
constexpr bool | isString () |
Compile time check function of whether a provided type is any variant of comms::field::String. More... | |
template<typename TFieldBase , typename... TOptions> | |
bool | operator!= (const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept |
Non-equality comparison operator. More... | |
template<typename TFieldBase , typename... TOptions> | |
bool | operator< (const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept |
Equivalence comparison operator. More... | |
template<typename TFieldBase , typename... TOptions> | |
bool | operator== (const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept |
Equality comparison operator. More... | |
template<typename TFieldBase , typename... TOptions> | |
const String< TFieldBase, TOptions... > & | toFieldBase (const String< TFieldBase, TOptions... > &field) |
Upcast type of the field definition to its parent comms::field::String type in order to have access to its internal types. | |
template<typename TFieldBase , typename... TOptions> | |
String< TFieldBase, TOptions... > & | toFieldBase (String< TFieldBase, TOptions... > &field) |
Upcast type of the field definition to its parent comms::field::String type in order to have access to its internal types. | |
using comms::field::String< TFieldBase, 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::String< TFieldBase, TOptions >::SerLengthFieldPrefix = typename ParsedOptions::SequenceSerLengthFieldPrefix |
Type of length field prefix specified via comms::option::def::SequenceSerLengthFieldPrefix.
void if comms::option::def::SequenceSerLengthFieldPrefix is not used.
using comms::field::String< TFieldBase, TOptions >::SizeFieldPrefix = typename ParsedOptions::SequenceSizeFieldPrefix |
Type of size field prefix specified via comms::option::def::SequenceSizeFieldPrefix.
void if comms::option::def::SequenceSizeFieldPrefix is not used.
using comms::field::String< TFieldBase, TOptions >::TerminationFieldSuffix = typename ParsedOptions::SequenceTerminationFieldSuffix |
Type of termination field suffix specified via comms::option::def::SequenceTerminationFieldSuffix.
void if comms::option::def::SequenceTerminationFieldSuffix is not used.
using comms::field::String< TFieldBase, TOptions >::TrailingFieldSuffix = typename ParsedOptions::SequenceTrailingFieldSuffix |
Type of trailing field suffix specified via comms::option::def::SequenceTrailingFieldSuffix.
void if comms::option::def::SequenceTrailingFieldSuffix is not used.
using comms::field::String< TFieldBase, TOptions >::ValueType = typename BaseImpl::ValueType |
Type of underlying value.
If comms::option::app::FixedSizeStorage option is NOT used, the ValueType is std::string, otherwise it becomes comms::util::StaticString<TSize>, where TSize is a size provided to comms::option::app::FixedSizeStorage option.
|
staticconstexprinherited |
Default check of whether the field has a consistent value for writing.
void comms::field::String< TFieldBase, TOptions >::clearReadElemCount | ( | ) |
Clear forcing of the number of characters that must be read in the next read() invocation.
Exists only if comms::option::def::SequenceSizeForcingEnabled option has been used.
void comms::field::String< TFieldBase, TOptions >::clearReadLengthForcing | ( | ) |
Clear forcing of the available length in the next read() invocation.
Exists only if comms::option::def::SequenceLengthForcingEnabled option has been used.
|
staticconstexpr |
Compile time inquiry of fixed size provided via comms::option::def::SequenceFixedSize option.
If the comms::option::def::SequenceFixedSize option hasn't been used std::numeric_limits<std::size_t>::max() is returned.
void comms::field::String< TFieldBase, TOptions >::forceReadElemCount | ( | std::size_t | count | ) |
Force number of characters that must be read in the next read() invocation.
Exists only if comms::option::def::SequenceSizeForcingEnabled option has been used.
[in] | count | Number of elements to read during following read operation. |
void comms::field::String< TFieldBase, TOptions >::forceReadLength | ( | std::size_t | count | ) |
Force available length for the next read() invocation.
Exists only if comms::option::def::SequenceLengthForcingEnabled option has been used.
[in] | count | Number of elements to read during following read operation. |
const ValueType& comms::field::String< TFieldBase, TOptions >::getValue | ( | ) | const |
Get value.
Implemented by calling value(), but can be overriden in the derived class
VersionType comms::field::String< TFieldBase, 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.
ErrorStatus comms::field::String< TFieldBase, TOptions >::read | ( | TIter & | iter, |
std::size_t | len | ||
) |
Read field value from input data sequence.
By default, the read operation will try to consume all the data available, unless size limiting option (such as comms::option::def::SequenceSizeFieldPrefix, comms::option::def::SequenceFixedSize, comms::option::def::SequenceSizeForcingEnabled, comms::option::def::SequenceLengthForcingEnabled) is used.
[in,out] | iter | Iterator to read the data. |
[in] | len | 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. |
void comms::field::String< TFieldBase, 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. |
bool comms::field::String< TFieldBase, TOptions >::refresh | ( | ) |
Refresh the field's value.
void comms::field::String< TFieldBase, TOptions >::setValue | ( | U && | val | ) |
Set value.
Implemented as re-assigning to value(), but can be overriden in the derived class.
bool comms::field::String< TFieldBase, 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::String< TFieldBase, TOptions >::write | ( | TIter & | iter, |
std::size_t | len | ||
) | const |
Write current field value to output data sequence.
By default, the write operation will write all the characters the field contains. If comms::option::def::SequenceFixedSize option is used, the number of characters, that is going to be written, is exactly as the option specifies. If underlying string storage doesn't contain enough data, the '\0' characters will be appended to the written sequence until the required amount of elements is reached.
[in,out] | iter | Iterator to write the data. |
[in] | len | 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. |
void comms::field::String< TFieldBase, 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. |
|
related |
Compile time check function of whether a provided type is any variant of comms::field::String.
T | Any type. |
|
related |
Non-equality comparison operator.
[in] | field1 | First field. |
[in] | field2 | Second field. |
|
related |
Equivalence comparison operator.
Performs lexicographical compare of two string values.
[in] | field1 | First field. |
[in] | field2 | Second field. |
|
related |
Equality comparison operator.
[in] | field1 | First field. |
[in] | field2 | Second field. |