17#if COMMS_HAS_CPP17_STRING_VIEW
27#include "comms/field/basic/String.h"
28#include "comms/field/details/AdaptBasicField.h"
29#include "comms/field/details/OptionsParser.h"
30#include "comms/details/tag.h"
41template <
bool THasOrigDataViewStorage>
42struct StringOrigDataViewStorageType;
45struct StringOrigDataViewStorageType<true>
47#if COMMS_HAS_CPP17_STRING_VIEW
48 using Type = std::string_view;
55struct StringOrigDataViewStorageType<false>
57 using Type = std::string;
60template <
bool THasSequenceFixedSizeUseFixedSizeStorage>
61struct StringFixedSizeUseFixedSizeStorageType;
64struct StringFixedSizeUseFixedSizeStorageType<true>
66 template <
typename TOpt>
71struct StringFixedSizeUseFixedSizeStorageType<false>
73 template <
typename TOpt>
74 using Type =
typename StringOrigDataViewStorageType<TOpt::HasOrigDataView>::Type;
77template <
bool THasFixedSizeStorage>
78struct StringFixedSizeStorageType;
81struct StringFixedSizeStorageType<true>
83 template <
typename TOpt>
88struct StringFixedSizeStorageType<false>
90 template <
typename TOpt>
91 using Type =
typename StringFixedSizeUseFixedSizeStorageType<TOpt::HasSequenceFixedSizeUseFixedSizeStorage>
92 ::template Type<TOpt>;
95template <
bool THasCustomStorage>
96struct StringCustomStringStorageType;
99struct StringCustomStringStorageType<true>
101 template <
typename TOpt>
102 using Type =
typename TOpt::CustomStorageType;
106struct StringCustomStringStorageType<false>
108 template <
typename TOpt>
110 typename StringFixedSizeStorageType<TOpt::HasFixedSizeStorage>::template Type<TOpt>;
113template <
typename TOpt>
114using StringStorageTypeT =
115 typename StringCustomStringStorageType<TOpt::HasCustomStorageType>::template Type<TOpt>;
117template <
typename TFieldBase,
typename... TOptions>
120 basic::String<TFieldBase, StringStorageTypeT<OptionsParser<TOptions...> > >,
157template <
typename TFieldBase,
typename... TOptions>
158class String :
public details::StringBase<TFieldBase, TOptions...>
160 using BaseImpl = details::StringBase<TFieldBase, TOptions...>;
166 using Endian =
typename BaseImpl::Endian;
216 : BaseImpl(
std::move(val))
245 return ParsedOptions::HasFailOnInvalid;
252 return ParsedOptions::HasIgnoreInvalid;
259 return ParsedOptions::HasEmptySerialization;
266 return ParsedOptions::HasFieldType;
273 return ParsedOptions::HasSequenceSizeFieldPrefix;
280 return ParsedOptions::HasSequenceSerLengthFieldPrefix;
287 return ParsedOptions::HasSequenceTerminationFieldSuffix;
294 return ParsedOptions::HasSequenceTrailingFieldSuffix;
301 return ParsedOptions::HasSequenceFixedSize;
309 return ParsedOptions::SequenceFixedSize;
322 template <
typename TIter>
325 auto es = BaseImpl::read(iter, len);
327 typename comms::util::LazyShallowConditional<
328 ParsedOptions::HasSequenceFixedSize
334 adjustValue(TagTmp());
342 return BaseImpl::hasReadNoStatus();
350 template <
typename TIter>
353 BaseImpl::readNoStatus(iter);
355 typename comms::util::LazyShallowConditional<
356 ParsedOptions::HasSequenceFixedSize
362 adjustValue(TagTmp());
368 return BaseImpl::value();
374 return BaseImpl::value();
381 return BaseImpl::getValue();
386 template <
typename U>
389 BaseImpl::setValue(std::forward<U>(val));
395 return BaseImpl::length();
401 return BaseImpl::valid();
408 return BaseImpl::refresh();
414 return BaseImpl::canWrite();
429 template <
typename TIter>
432 return BaseImpl::write(iter, len);
439 return BaseImpl::hasWriteNoStatus();
447 template <
typename TIter>
450 BaseImpl::writeNoStatus(iter);
456 return BaseImpl::minLength();
462 return BaseImpl::maxLength();
472 BaseImpl::forceReadElemCount(count);
481 BaseImpl::clearReadElemCount();
490 return BaseImpl::forceReadLength(count);
499 return BaseImpl::clearReadLengthForcing();
505 return ParsedOptions::HasCustomVersionUpdate || BaseImpl::isVersionDependent();
511 return BaseImpl::hasNonDefaultRefresh();
518 return BaseImpl::getVersion();
525 return BaseImpl::setVersion(
version);
529 using BaseImpl::readData;
530 using BaseImpl::writeData;
533 template <
typename... TParams>
534 using NoAdjustmentTag = comms::details::tag::Tag1<>;
536 template <
typename... TParams>
537 using AdjustmentNeededTag = comms::details::tag::Tag2<>;
539 template <
typename... TParams>
540 using HasResizeTag = comms::details::tag::Tag3<>;
542 template <
typename... TParams>
543 using HasRemoveSuffixTag = comms::details::tag::Tag4<>;
545 template <
typename... TParams>
546 void adjustValue(NoAdjustmentTag<TParams...>)
550 template <
typename... TParams>
551 void adjustValue(AdjustmentNeededTag<TParams...>)
553 std::size_t count = 0;
554 for (
auto iter = BaseImpl::value().begin(); iter != BaseImpl::value().end(); ++iter) {
564 void doResize(std::size_t count)
568 comms::util::detect::hasResizeFunc<ValueType>()
572 comms::util::detect::hasRemoveSuffixFunc<ValueType>()
574 HasRemoveSuffixTag<>,
579 static_assert(!std::is_void<TagTmp>::value,
580 "The string storage value type must have either resize() or remove_suffix() "
582 doResize(count, TagTmp());
585 template <
typename... TParams>
586 void doResize(std::size_t count, HasResizeTag<TParams...>)
588 BaseImpl::value().resize(count);
591 template <
typename... TParams>
592 void doResize(std::size_t count, HasRemoveSuffixTag<TParams...>)
594 BaseImpl::value().remove_suffix(BaseImpl::value().size() - count);
597 static_assert(!ParsedOptions::HasSerOffset,
598 "comms::option::def::NumValueSerOffset option is not applicable to String field");
599 static_assert(!ParsedOptions::HasFixedLengthLimit,
600 "comms::option::def::FixedLength option is not applicable to String field");
601 static_assert(!ParsedOptions::HasFixedBitLengthLimit,
602 "comms::option::def::FixedBitLength option is not applicable to String field");
603 static_assert(!ParsedOptions::HasVarLengthLimits,
604 "comms::option::def::VarLength option is not applicable to String field");
605 static_assert(!ParsedOptions::HasAvailableLengthLimit,
606 "comms::option::def::AvailableLengthLimit option is not applicable to String field");
607 static_assert(!ParsedOptions::HasScalingRatio,
608 "comms::option::def::ScalingRatio option is not applicable to String field");
609 static_assert(!ParsedOptions::HasUnits,
610 "comms::option::def::Units option is not applicable to String field");
611 static_assert(!ParsedOptions::HasMultiRangeValidation,
612 "comms::option::def::ValidNumValueRange (or similar) option is not applicable to String field");
613 static_assert(!ParsedOptions::HasSequenceElemSerLengthFieldPrefix,
614 "comms::option::def::SequenceElemSerLengthFieldPrefix option is not applicable to String field");
615 static_assert(!ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix,
616 "comms::option::def::SequenceElemSerLengthFixedFieldPrefix option is not applicable to String field");
617 static_assert(!ParsedOptions::HasVersionsRange,
618 "comms::option::def::ExistsBetweenVersions (or similar) option is not applicable to String field");
619 static_assert(!ParsedOptions::HasMissingOnReadFail,
620 "comms::option::def::MissingOnReadFail option is not applicable to String field");
621 static_assert(!ParsedOptions::HasMissingOnInvalid,
622 "comms::option::def::MissingOnInvalid option is not applicable to String field");
630template <
typename TFieldBase,
typename... TOptions>
635 return field1.value() == field2.value();
643template <
typename TFieldBase,
typename... TOptions>
648 return field1.value() != field2.value();
657template <
typename TFieldBase,
typename... TOptions>
662 return field1.value() < field2.value();
673 return std::is_same<typename T::CommsTag, tag::String>::value;
679template <
typename TFieldBase,
typename... TOptions>
681String<TFieldBase, TOptions...>&
690template <
typename TFieldBase,
typename... TOptions>
692const String<TFieldBase, TOptions...>&
Contains various compiler related definitions.
This file contain definition of error statuses used by comms module.
Contains comms::util::StaticString class.
Contains comms::util::StringView class.
Field that represents a string.
Definition String.h:159
TFieldBase FieldBase
Base class provided in the first template parameter.
Definition String.h:163
typename ParsedOptions::SequenceTrailingFieldSuffix TrailingFieldSuffix
Type of trailing field suffix specified via comms::option::def::SequenceTrailingFieldSuffix.
Definition String.h:203
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition String.h:243
String(const ValueType &val)
Constructor.
Definition String.h:209
constexpr bool isString()
Compile time check function of whether a provided type is any variant of comms::field::String.
Definition String.h:671
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition String.h:187
static constexpr bool hasTerminationFieldSuffix()
Compile time inquiry of whether comms::option::def::SequenceTerminationFieldSuffix option has been us...
Definition String.h:285
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition String.h:437
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition String.h:264
typename ParsedOptions::SequenceTerminationFieldSuffix TerminationFieldSuffix
Type of termination field suffix specified via comms::option::def::SequenceTerminationFieldSuffix.
Definition String.h:199
static constexpr std::size_t fixedSize()
Compile time inquiry of fixed size provided via comms::option::def::SequenceFixedSize option.
Definition String.h:307
typename ParsedOptions::SequenceSerLengthFieldPrefix SerLengthFieldPrefix
Type of length field prefix specified via comms::option::def::SequenceSerLengthFieldPrefix.
Definition String.h:195
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition String.h:454
ErrorStatus read(TIter &iter, std::size_t len)
Read field value from input data sequence.
Definition String.h:323
static constexpr bool hasSerLengthFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceSerLengthFieldPrefix option has been used...
Definition String.h:278
~String() noexcept=default
Destructor.
void forceReadElemCount(std::size_t count)
Force number of characters that must be read in the next read() invocation.
Definition String.h:470
void setValue(U &&val)
Set value.
Definition String.h:387
bool operator!=(const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition String.h:644
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition String.h:412
static constexpr bool hasSizeFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceSizeFieldPrefix option has been used.
Definition String.h:271
VersionType getVersion() const
Get version of the field.
Definition String.h:516
void forceReadLength(std::size_t count)
Force available length for the next read() invocation.
Definition String.h:488
bool setVersion(VersionType version)
Default implementation of version update.
Definition String.h:523
ErrorStatus write(TIter &iter, std::size_t len) const
Write current field value to output data sequence.
Definition String.h:430
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition String.h:250
void clearReadElemCount()
Clear forcing of the number of characters that must be read in the next read() invocation.
Definition String.h:479
const ValueType & getValue() const
Get value.
Definition String.h:379
bool operator<(const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition String.h:658
typename BaseImpl::CommsTag CommsTag
Tag indicating type of the field.
Definition String.h:175
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition String.h:340
typename BaseImpl::ValueType ValueType
Type of underlying value.
Definition String.h:182
bool valid() const
Check validity of the field value.
Definition String.h:399
static constexpr bool hasFixedSize()
Compile time inquiry of whether comms::option::def::SequenceFixedSize option has been used.
Definition String.h:299
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 t...
Definition String.h:682
bool refresh()
Refresh the field's value.
Definition String.h:406
String(const char *str)
Constructor.
Definition String.h:221
String()=default
Default constructor.
typename BaseImpl::VersionType VersionType
Version type.
Definition String.h:169
String(String &&)=default
Move constructor.
std::size_t length() const
Get length of serialised data.
Definition String.h:393
details::OptionsParser< TOptions... > ParsedOptions
All the options provided to this class bundled into struct.
Definition String.h:172
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition String.h:257
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition String.h:166
String(const String &)=default
Copy constructor.
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 t...
Definition String.h:693
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition String.h:509
String(ValueType &&val)
Constructor.
Definition String.h:215
typename ParsedOptions::SequenceSizeFieldPrefix SizeFieldPrefix
Type of size field prefix specified via comms::option::def::SequenceSizeFieldPrefix.
Definition String.h:191
void clearReadLengthForcing()
Clear forcing of the available length in the next read() invocation.
Definition String.h:497
ValueType & value()
Get access to the value storage.
Definition String.h:366
static constexpr bool hasTrailingFieldSuffix()
Compile time inquiry of whether comms::option::def::SequenceTrailingFieldSuffix option has been used.
Definition String.h:292
const ValueType & value() const
Get access to the value storage.
Definition String.h:372
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition String.h:448
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition String.h:460
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition String.h:351
bool operator==(const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept
Equality comparison operator.
Definition String.h:631
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition String.h:503
Replacement to std::string when no dynamic memory allocation is allowed.
Definition StaticString.h:789
Describes an object that can refer to a constant contiguous sequence of char-like objects with the fi...
Definition StringView.h:35
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:17
constexpr unsigned version()
Version of the COMMS library as single numeric value.
Definition version.h:64
Contains definition of all the options used by the COMMS library.
Replacement to std::conditional.
Definition type_traits.h:28
Replacement to some types from standard type_traits.
Various compile-time detection functions of whether specific member functions and/or types exist.