15#include "comms/details/tag.h"
16#include "comms/field/basic/String.h"
17#include "comms/field/details/AdaptBasicField.h"
18#include "comms/field/details/OptionsParser.h"
25#if COMMS_HAS_CPP17_STRING_VIEW
40template <
bool THasOrigDataViewStorage>
41struct StringOrigDataViewStorageType;
44struct StringOrigDataViewStorageType<true>
46#if COMMS_HAS_CPP17_STRING_VIEW
47 using Type = std::string_view;
54struct StringOrigDataViewStorageType<false>
56 using Type = std::string;
59template <
bool THasSequenceFixedSizeUseFixedSizeStorage>
60struct StringFixedSizeUseFixedSizeStorageType;
63struct StringFixedSizeUseFixedSizeStorageType<true>
65 template <
typename TOpt>
70struct StringFixedSizeUseFixedSizeStorageType<false>
72 template <
typename TOpt>
73 using Type =
typename StringOrigDataViewStorageType<TOpt::HasOrigDataView>::Type;
76template <
bool THasFixedSizeStorage>
77struct StringFixedSizeStorageType;
80struct StringFixedSizeStorageType<true>
82 template <
typename TOpt>
87struct StringFixedSizeStorageType<false>
89 template <
typename TOpt>
90 using Type =
typename StringFixedSizeUseFixedSizeStorageType<TOpt::HasSequenceFixedSizeUseFixedSizeStorage>
91 ::template Type<TOpt>;
94template <
bool THasCustomStorage>
95struct StringCustomStringStorageType;
98struct StringCustomStringStorageType<true>
100 template <
typename TOpt>
101 using Type =
typename TOpt::CustomStorageType;
105struct StringCustomStringStorageType<false>
107 template <
typename TOpt>
109 typename StringFixedSizeStorageType<TOpt::HasFixedSizeStorage>::template Type<TOpt>;
112template <
typename TOpt>
113using StringStorageTypeT =
114 typename StringCustomStringStorageType<TOpt::HasCustomStorageType>::template Type<TOpt>;
116template <
typename TFieldBase,
typename... TOptions>
119 basic::String<TFieldBase, StringStorageTypeT<OptionsParser<TOptions...> > >,
158template <
typename TFieldBase,
typename... TOptions>
159class String :
public details::StringBase<TFieldBase, TOptions...>
161 using BaseImpl = details::StringBase<TFieldBase, TOptions...>;
167 using Endian =
typename BaseImpl::Endian;
217 : BaseImpl(
std::move(val))
246 return ParsedOptions::HasFailOnInvalid;
253 return ParsedOptions::HasIgnoreInvalid;
260 return ParsedOptions::HasEmptySerialization;
267 return ParsedOptions::HasFieldType;
274 return ParsedOptions::HasSequenceSizeFieldPrefix;
281 return ParsedOptions::HasSequenceSerLengthFieldPrefix;
288 return ParsedOptions::HasSequenceTerminationFieldSuffix;
295 return ParsedOptions::HasSequenceTrailingFieldSuffix;
302 return ParsedOptions::HasSequenceFixedSize;
309 return ParsedOptions::HasFixedValue;
316 return ParsedOptions::HasName;
324 return ParsedOptions::SequenceFixedSize;
337 template <
typename TIter>
340 auto es = BaseImpl::read(iter, len);
342 typename comms::util::LazyShallowConditional<
343 ParsedOptions::HasSequenceFixedSize
349 adjustValue(TagTmp());
357 return BaseImpl::hasReadNoStatus();
365 template <
typename TIter>
368 BaseImpl::readNoStatus(iter);
370 typename comms::util::LazyShallowConditional<
371 ParsedOptions::HasSequenceFixedSize
377 adjustValue(TagTmp());
383 return BaseImpl::value();
389 return BaseImpl::value();
396 return BaseImpl::getValue();
401 template <
typename U>
404 BaseImpl::setValue(std::forward<U>(val));
410 return BaseImpl::length();
416 return BaseImpl::valid();
423 return BaseImpl::refresh();
429 return BaseImpl::canWrite();
444 template <
typename TIter>
447 return BaseImpl::write(iter, len);
454 return BaseImpl::hasWriteNoStatus();
462 template <
typename TIter>
465 BaseImpl::writeNoStatus(iter);
471 return BaseImpl::minLength();
477 return BaseImpl::maxLength();
487 BaseImpl::forceReadElemCount(count);
496 BaseImpl::clearReadElemCount();
505 return BaseImpl::forceReadLength(count);
514 return BaseImpl::clearReadLengthForcing();
520 return ParsedOptions::HasCustomVersionUpdate || BaseImpl::isVersionDependent();
526 return BaseImpl::hasNonDefaultRefresh();
533 return BaseImpl::getVersion();
540 return BaseImpl::setVersion(
version);
544 using BaseImpl::readData;
545 using BaseImpl::writeData;
548 template <
typename... TParams>
549 using NoAdjustmentTag = comms::details::tag::Tag1<>;
551 template <
typename... TParams>
552 using AdjustmentNeededTag = comms::details::tag::Tag2<>;
554 template <
typename... TParams>
555 using HasResizeTag = comms::details::tag::Tag3<>;
557 template <
typename... TParams>
558 using HasRemoveSuffixTag = comms::details::tag::Tag4<>;
560 template <
typename... TParams>
561 void adjustValue(NoAdjustmentTag<TParams...>)
565 template <
typename... TParams>
566 void adjustValue(AdjustmentNeededTag<TParams...>)
568 std::size_t count = 0;
569 for (
auto iter = BaseImpl::value().begin(); iter != BaseImpl::value().end(); ++iter) {
579 void doResize(std::size_t count)
583 comms::util::detect::hasResizeFunc<ValueType>()
587 comms::util::detect::hasRemoveSuffixFunc<ValueType>()
589 HasRemoveSuffixTag<>,
594 static_assert(!std::is_void<TagTmp>::value,
595 "The string storage value type must have either resize() or remove_suffix() "
597 doResize(count, TagTmp());
600 template <
typename... TParams>
601 void doResize(std::size_t count, HasResizeTag<TParams...>)
603 BaseImpl::value().resize(count);
606 template <
typename... TParams>
607 void doResize(std::size_t count, HasRemoveSuffixTag<TParams...>)
609 BaseImpl::value().remove_suffix(BaseImpl::value().size() - count);
612 static_assert(!ParsedOptions::HasSerOffset,
613 "comms::option::def::NumValueSerOffset option is not applicable to String field");
614 static_assert(!ParsedOptions::HasFixedLengthLimit,
615 "comms::option::def::FixedLength option is not applicable to String field");
616 static_assert(!ParsedOptions::HasFixedBitLengthLimit,
617 "comms::option::def::FixedBitLength option is not applicable to String field");
618 static_assert(!ParsedOptions::HasVarLengthLimits,
619 "comms::option::def::VarLength option is not applicable to String field");
620 static_assert(!ParsedOptions::HasAvailableLengthLimit,
621 "comms::option::def::AvailableLengthLimit option is not applicable to String field");
622 static_assert(!ParsedOptions::HasScalingRatio,
623 "comms::option::def::ScalingRatio option is not applicable to String field");
624 static_assert(!ParsedOptions::HasUnits,
625 "comms::option::def::Units option is not applicable to String field");
626 static_assert(!ParsedOptions::HasMultiRangeValidation,
627 "comms::option::def::ValidNumValueRange (or similar) option is not applicable to String field");
628 static_assert(!ParsedOptions::HasSequenceElemSerLengthFieldPrefix,
629 "comms::option::def::SequenceElemSerLengthFieldPrefix option is not applicable to String field");
630 static_assert(!ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix,
631 "comms::option::def::SequenceElemSerLengthFixedFieldPrefix option is not applicable to String field");
632 static_assert(!ParsedOptions::HasVersionsRange,
633 "comms::option::def::ExistsBetweenVersions (or similar) option is not applicable to String field");
634 static_assert(!ParsedOptions::HasMissingOnReadFail,
635 "comms::option::def::MissingOnReadFail option is not applicable to String field");
636 static_assert(!ParsedOptions::HasMissingOnInvalid,
637 "comms::option::def::MissingOnInvalid option is not applicable to String field");
645template <
typename TFieldBase,
typename... TOptions>
650 return field1.value() == field2.value();
658template <
typename TFieldBase,
typename... TOptions>
663 return field1.value() != field2.value();
672template <
typename TFieldBase,
typename... TOptions>
677 return field1.value() < field2.value();
688 return std::is_same<typename T::CommsTag, tag::String>::value;
694template <
typename TFieldBase,
typename... TOptions>
696String<TFieldBase, TOptions...>&
705template <
typename TFieldBase,
typename... TOptions>
707const 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:160
TFieldBase FieldBase
Base class provided in the first template parameter.
Definition String.h:164
typename ParsedOptions::SequenceTrailingFieldSuffix TrailingFieldSuffix
Type of trailing field suffix specified via comms::option::def::SequenceTrailingFieldSuffix.
Definition String.h:204
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition String.h:244
String(const ValueType &val)
Constructor.
Definition String.h:210
constexpr bool isString()
Compile time check function of whether a provided type is any variant of comms::field::String.
Definition String.h:686
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition String.h:188
static constexpr bool hasTerminationFieldSuffix()
Compile time inquiry of whether comms::option::def::SequenceTerminationFieldSuffix option has been us...
Definition String.h:286
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition String.h:452
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition String.h:265
typename ParsedOptions::SequenceTerminationFieldSuffix TerminationFieldSuffix
Type of termination field suffix specified via comms::option::def::SequenceTerminationFieldSuffix.
Definition String.h:200
static constexpr std::size_t fixedSize()
Compile time inquiry of fixed size provided via comms::option::def::SequenceFixedSize option.
Definition String.h:322
typename ParsedOptions::SequenceSerLengthFieldPrefix SerLengthFieldPrefix
Type of length field prefix specified via comms::option::def::SequenceSerLengthFieldPrefix.
Definition String.h:196
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition String.h:469
ErrorStatus read(TIter &iter, std::size_t len)
Read field value from input data sequence.
Definition String.h:338
static constexpr bool hasSerLengthFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceSerLengthFieldPrefix option has been used...
Definition String.h:279
~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:485
void setValue(U &&val)
Set value.
Definition String.h:402
bool operator!=(const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition String.h:659
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition String.h:427
static constexpr bool hasSizeFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceSizeFieldPrefix option has been used.
Definition String.h:272
VersionType getVersion() const
Get version of the field.
Definition String.h:531
void forceReadLength(std::size_t count)
Force available length for the next read() invocation.
Definition String.h:503
static constexpr bool hasFixedValue()
Compile time inquiry of whether comms::option::def::FixedValue option has been used.
Definition String.h:307
bool setVersion(VersionType version)
Default implementation of version update.
Definition String.h:538
ErrorStatus write(TIter &iter, std::size_t len) const
Write current field value to output data sequence.
Definition String.h:445
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition String.h:251
void clearReadElemCount()
Clear forcing of the number of characters that must be read in the next read() invocation.
Definition String.h:494
const ValueType & getValue() const
Get value.
Definition String.h:394
bool operator<(const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition String.h:673
typename BaseImpl::CommsTag CommsTag
Tag indicating type of the field.
Definition String.h:176
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition String.h:355
typename BaseImpl::ValueType ValueType
Type of underlying value.
Definition String.h:183
bool valid() const
Check validity of the field value.
Definition String.h:414
static constexpr bool hasFixedSize()
Compile time inquiry of whether comms::option::def::SequenceFixedSize option has been used.
Definition String.h:300
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:697
bool refresh()
Refresh the field's value.
Definition String.h:421
String(const char *str)
Constructor.
Definition String.h:222
String()=default
Default constructor.
typename BaseImpl::VersionType VersionType
Version type.
Definition String.h:170
String(String &&)=default
Move constructor.
std::size_t length() const
Get length of serialised data.
Definition String.h:408
details::OptionsParser< TOptions... > ParsedOptions
All the options provided to this class bundled into struct.
Definition String.h:173
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition String.h:258
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition String.h:167
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:708
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition String.h:524
String(ValueType &&val)
Constructor.
Definition String.h:216
typename ParsedOptions::SequenceSizeFieldPrefix SizeFieldPrefix
Type of size field prefix specified via comms::option::def::SequenceSizeFieldPrefix.
Definition String.h:192
void clearReadLengthForcing()
Clear forcing of the available length in the next read() invocation.
Definition String.h:512
ValueType & value()
Get access to the value storage.
Definition String.h:381
static constexpr bool hasTrailingFieldSuffix()
Compile time inquiry of whether comms::option::def::SequenceTrailingFieldSuffix option has been used.
Definition String.h:293
const ValueType & value() const
Get access to the value storage.
Definition String.h:387
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition String.h:463
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition String.h:475
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition String.h:366
bool operator==(const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept
Equality comparison operator.
Definition String.h:646
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition String.h:518
static constexpr bool hasName()
Compile time inquiry of whether comms::option::def::HasName option has been used.
Definition String.h:314
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:29
Replacement to some types from standard type_traits.
Various compile-time detection functions of whether specific member functions and/or types exist.