template<typename TFieldBase, typename... TOptions>
class comms::field::String< TFieldBase, TOptions >
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.
- Template Parameters
-
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:
|
|
| 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.
|
|
void | clearReadLengthForcing () |
| Clear forcing of the available length in the next read() invocation.
|
|
void | forceReadElemCount (std::size_t count) |
| Force number of characters that must be read in the next read() invocation.
|
|
void | forceReadLength (std::size_t count) |
| Force available length for the next read() invocation.
|
|
const ValueType & | getValue () const |
| Get value.
|
|
VersionType | getVersion () const |
| Get version of the field.
|
|
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.
|
|
template<typename TIter > |
void | readNoStatus (TIter &iter) |
| Read field value from input data sequence without error check and status report.
|
|
bool | refresh () |
| Refresh the field's value.
|
|
template<typename U > |
void | setValue (U &&val) |
| Set value.
|
|
bool | setVersion (VersionType version) |
| Default implementation of version update.
|
|
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.
|
|
template<typename TIter > |
void | writeNoStatus (TIter &iter) const |
| Write current field value to output data sequence without error check and status report.
|
|
|
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.
|
|
|
(Note that these are not member symbols.)
|
template<typename T > |
constexpr bool | isString () |
| Compile time check function of whether a provided type is any variant of comms::field::String.
|
|
template<typename TFieldBase , typename... TOptions> |
bool | operator!= (const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept |
| Non-equality comparison operator.
|
|
template<typename TFieldBase , typename... TOptions> |
bool | operator< (const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept |
| Equivalence comparison operator.
|
|
template<typename TFieldBase , typename... TOptions> |
bool | operator== (const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept |
| Equality comparison operator.
|
|
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.
|
|
template<typename... TOptions>
template<typename T , typename TIter >
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.
- Template Parameters
-
T | Return type |
TIter | Type of input iterator |
- Parameters
-
[in,out] | iter | Input iterator. |
- Returns
- The integral type value.
- Precondition
- TSize <= sizeof(T)
-
The iterator must be valid and can be successfully dereferenced and incremented at least sizeof(T) times.
- Postcondition
- The iterator is advanced.
- Note
- Thread safety: Safe for distinct stream buffers, unsafe otherwise.
template<typename... TOptions>
template<typename T , std::size_t TSize, typename TIter >
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.
- Template Parameters
-
T | Return type |
TSize | number of bytes to read |
TIter | Type of input iterator |
- Parameters
-
[in,out] | iter | Input iterator. |
- Returns
- The integral type value.
- Precondition
- TSize <= sizeof(T)
-
The iterator must be valid and can be successfully dereferenced and incremented at least TSize times.
- Postcondition
- The internal pointer of the stream buffer is advanced.
- Note
- Thread safety: Safe for distinct stream buffers, unsafe otherwise.
template<typename TFieldBase , typename... TOptions>
template<typename TIter >
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.
- Parameters
-
[in,out] | iter | Iterator to read the data. |
- Postcondition
- Iterator is advanced.
template<typename TFieldBase , typename... TOptions>
template<typename TIter >
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.
- Parameters
-
[in,out] | iter | Iterator to write the data. |
[in] | len | Maximal number of bytes that can be written. |
- Returns
- Status of write operation.
- Postcondition
- Iterator is advanced.
template<typename... TOptions>
template<typename T , typename TIter >
static void comms::Field< TOptions >::writeData |
( |
T |
value, |
|
|
TIter & |
iter |
|
) |
| |
|
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.
- Template Parameters
-
T | Type of the value to write. Must be integral. |
Type | of output iterator |
- Parameters
-
[in] | value | Integral type value to be written. |
[in,out] | iter | Output iterator. |
- Precondition
- The iterator must be valid and can be successfully dereferenced and incremented at least sizeof(T) times.
- Postcondition
- The iterator is advanced.
- Note
- Thread safety: Safe for distinct buffers, unsafe otherwise.
template<typename... TOptions>
template<std::size_t TSize, typename T , typename TIter >
static void comms::Field< TOptions >::writeData |
( |
T |
value, |
|
|
TIter & |
iter |
|
) |
| |
|
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.
- Template Parameters
-
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 |
- Parameters
-
[in] | value | Integral type value to be written. |
[in,out] | iter | Output iterator. |
- Precondition
- TSize <= sizeof(T)
-
The iterator must be valid and can be successfully dereferenced and incremented at least TSize times.
- Postcondition
- The iterator is advanced.
- Note
- Thread safety: Safe for distinct buffers, unsafe otherwise.
template<typename TFieldBase , typename... TOptions>
template<typename TIter >
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.
- Parameters
-
[in,out] | iter | Iterator to write the data. |
- Postcondition
- Iterator is advanced.