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...> > >,
159template <
typename TFieldBase,
typename... TOptions>
160class String :
public details::StringBase<TFieldBase, TOptions...>
162 using BaseImpl = details::StringBase<TFieldBase, TOptions...>;
168 using Endian =
typename BaseImpl::Endian;
218 : BaseImpl(
std::move(val))
247 return ParsedOptions::HasFailOnInvalid;
254 return ParsedOptions::HasIgnoreInvalid;
261 return ParsedOptions::HasEmptySerialization;
268 return ParsedOptions::HasFieldType;
275 return ParsedOptions::HasSequenceSizeFieldPrefix;
282 return ParsedOptions::HasSequenceSerLengthFieldPrefix;
289 return ParsedOptions::HasSequenceTerminationFieldSuffix;
296 return ParsedOptions::HasSequenceTrailingFieldSuffix;
303 return ParsedOptions::HasSequenceFixedSize;
310 return ParsedOptions::HasFixedValue;
317 return ParsedOptions::HasName;
325 return ParsedOptions::SequenceFixedSize;
338 template <
typename TIter>
341 auto es = BaseImpl::read(iter, len);
343 typename comms::util::LazyShallowConditional<
344 ParsedOptions::HasSequenceFixedSize
350 adjustValue(TagTmp());
358 return BaseImpl::hasReadNoStatus();
366 template <
typename TIter>
369 BaseImpl::readNoStatus(iter);
371 typename comms::util::LazyShallowConditional<
372 ParsedOptions::HasSequenceFixedSize
378 adjustValue(TagTmp());
384 return BaseImpl::value();
390 return BaseImpl::value();
397 return BaseImpl::getValue();
402 template <
typename U>
405 BaseImpl::setValue(std::forward<U>(val));
411 return BaseImpl::length();
417 return BaseImpl::valid();
424 return BaseImpl::refresh();
430 return BaseImpl::canWrite();
445 template <
typename TIter>
448 return BaseImpl::write(iter, len);
455 return BaseImpl::hasWriteNoStatus();
463 template <
typename TIter>
466 BaseImpl::writeNoStatus(iter);
472 return BaseImpl::minLength();
478 return BaseImpl::maxLength();
488 BaseImpl::forceReadElemCount(count);
497 BaseImpl::clearReadElemCount();
506 return BaseImpl::forceReadLength(count);
515 return BaseImpl::clearReadLengthForcing();
521 return ParsedOptions::HasCustomVersionUpdate || BaseImpl::isVersionDependent();
527 return BaseImpl::hasNonDefaultRefresh();
534 return BaseImpl::getVersion();
541 return BaseImpl::setVersion(
version);
545 using BaseImpl::readData;
546 using BaseImpl::writeData;
549 template <
typename... TParams>
550 using NoAdjustmentTag = comms::details::tag::Tag1<>;
552 template <
typename... TParams>
553 using AdjustmentNeededTag = comms::details::tag::Tag2<>;
555 template <
typename... TParams>
556 using HasResizeTag = comms::details::tag::Tag3<>;
558 template <
typename... TParams>
559 using HasRemoveSuffixTag = comms::details::tag::Tag4<>;
561 template <
typename... TParams>
562 void adjustValue(NoAdjustmentTag<TParams...>)
566 template <
typename... TParams>
567 void adjustValue(AdjustmentNeededTag<TParams...>)
569 std::size_t count = 0;
570 for (
auto iter = BaseImpl::value().begin(); iter != BaseImpl::value().end(); ++iter) {
580 void doResize(std::size_t count)
584 comms::util::detect::hasResizeFunc<ValueType>()
588 comms::util::detect::hasRemoveSuffixFunc<ValueType>()
590 HasRemoveSuffixTag<>,
595 static_assert(!std::is_void<TagTmp>::value,
596 "The string storage value type must have either resize() or remove_suffix() "
598 doResize(count, TagTmp());
601 template <
typename... TParams>
602 void doResize(std::size_t count, HasResizeTag<TParams...>)
604 BaseImpl::value().resize(count);
607 template <
typename... TParams>
608 void doResize(std::size_t count, HasRemoveSuffixTag<TParams...>)
610 BaseImpl::value().remove_suffix(BaseImpl::value().size() - count);
613 static_assert(!ParsedOptions::HasSerOffset,
614 "comms::option::def::NumValueSerOffset option is not applicable to String field");
615 static_assert(!ParsedOptions::HasFixedLengthLimit,
616 "comms::option::def::FixedLength option is not applicable to String field");
617 static_assert(!ParsedOptions::HasFixedBitLengthLimit,
618 "comms::option::def::FixedBitLength option is not applicable to String field");
619 static_assert(!ParsedOptions::HasVarLengthLimits,
620 "comms::option::def::VarLength option is not applicable to String field");
621 static_assert(!ParsedOptions::HasAvailableLengthLimit,
622 "comms::option::def::AvailableLengthLimit option is not applicable to String field");
623 static_assert(!ParsedOptions::HasScalingRatio,
624 "comms::option::def::ScalingRatio option is not applicable to String field");
625 static_assert(!ParsedOptions::HasUnits,
626 "comms::option::def::Units option is not applicable to String field");
627 static_assert(!ParsedOptions::HasMultiRangeValidation,
628 "comms::option::def::ValidNumValueRange (or similar) option is not applicable to String field");
629 static_assert(!ParsedOptions::HasSequenceElemSerLengthFieldPrefix,
630 "comms::option::def::SequenceElemSerLengthFieldPrefix option is not applicable to String field");
631 static_assert(!ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix,
632 "comms::option::def::SequenceElemSerLengthFixedFieldPrefix option is not applicable to String field");
633 static_assert(!ParsedOptions::HasVersionsRange,
634 "comms::option::def::ExistsBetweenVersions (or similar) option is not applicable to String field");
635 static_assert(!ParsedOptions::HasMissingOnReadFail,
636 "comms::option::def::MissingOnReadFail option is not applicable to String field");
637 static_assert(!ParsedOptions::HasMissingOnInvalid,
638 "comms::option::def::MissingOnInvalid option is not applicable to String field");
646template <
typename TFieldBase,
typename... TOptions>
651 return field1.value() == field2.value();
659template <
typename TFieldBase,
typename... TOptions>
664 return field1.value() != field2.value();
673template <
typename TFieldBase,
typename... TOptions>
678 return field1.value() < field2.value();
689 return std::is_same<typename T::CommsTag, tag::String>::value;
695template <
typename TFieldBase,
typename... TOptions>
697String<TFieldBase, TOptions...>&
706template <
typename TFieldBase,
typename... TOptions>
708const 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:161
TFieldBase FieldBase
Base class provided in the first template parameter.
Definition String.h:165
typename ParsedOptions::SequenceTrailingFieldSuffix TrailingFieldSuffix
Type of trailing field suffix specified via comms::option::def::SequenceTrailingFieldSuffix.
Definition String.h:205
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition String.h:245
String(const ValueType &val)
Constructor.
Definition String.h:211
constexpr bool isString()
Compile time check function of whether a provided type is any variant of comms::field::String.
Definition String.h:687
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition String.h:189
static constexpr bool hasTerminationFieldSuffix()
Compile time inquiry of whether comms::option::def::SequenceTerminationFieldSuffix option has been us...
Definition String.h:287
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition String.h:453
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition String.h:266
typename ParsedOptions::SequenceTerminationFieldSuffix TerminationFieldSuffix
Type of termination field suffix specified via comms::option::def::SequenceTerminationFieldSuffix.
Definition String.h:201
static constexpr std::size_t fixedSize()
Compile time inquiry of fixed size provided via comms::option::def::SequenceFixedSize option.
Definition String.h:323
typename ParsedOptions::SequenceSerLengthFieldPrefix SerLengthFieldPrefix
Type of length field prefix specified via comms::option::def::SequenceSerLengthFieldPrefix.
Definition String.h:197
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition String.h:470
ErrorStatus read(TIter &iter, std::size_t len)
Read field value from input data sequence.
Definition String.h:339
static constexpr bool hasSerLengthFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceSerLengthFieldPrefix option has been used...
Definition String.h:280
~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:486
void setValue(U &&val)
Set value.
Definition String.h:403
bool operator!=(const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition String.h:660
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition String.h:428
static constexpr bool hasSizeFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceSizeFieldPrefix option has been used.
Definition String.h:273
VersionType getVersion() const
Get version of the field.
Definition String.h:532
void forceReadLength(std::size_t count)
Force available length for the next read() invocation.
Definition String.h:504
static constexpr bool hasFixedValue()
Compile time inquiry of whether comms::option::def::FixedValue option has been used.
Definition String.h:308
bool setVersion(VersionType version)
Default implementation of version update.
Definition String.h:539
ErrorStatus write(TIter &iter, std::size_t len) const
Write current field value to output data sequence.
Definition String.h:446
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition String.h:252
void clearReadElemCount()
Clear forcing of the number of characters that must be read in the next read() invocation.
Definition String.h:495
const ValueType & getValue() const
Get value.
Definition String.h:395
bool operator<(const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition String.h:674
typename BaseImpl::CommsTag CommsTag
Tag indicating type of the field.
Definition String.h:177
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition String.h:356
typename BaseImpl::ValueType ValueType
Type of underlying value.
Definition String.h:184
bool valid() const
Check validity of the field value.
Definition String.h:415
static constexpr bool hasFixedSize()
Compile time inquiry of whether comms::option::def::SequenceFixedSize option has been used.
Definition String.h:301
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:698
bool refresh()
Refresh the field's value.
Definition String.h:422
String(const char *str)
Constructor.
Definition String.h:223
String()=default
Default constructor.
typename BaseImpl::VersionType VersionType
Version type.
Definition String.h:171
String(String &&)=default
Move constructor.
std::size_t length() const
Get length of serialised data.
Definition String.h:409
details::OptionsParser< TOptions... > ParsedOptions
All the options provided to this class bundled into struct.
Definition String.h:174
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition String.h:259
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition String.h:168
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:709
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition String.h:525
String(ValueType &&val)
Constructor.
Definition String.h:217
typename ParsedOptions::SequenceSizeFieldPrefix SizeFieldPrefix
Type of size field prefix specified via comms::option::def::SequenceSizeFieldPrefix.
Definition String.h:193
void clearReadLengthForcing()
Clear forcing of the available length in the next read() invocation.
Definition String.h:513
ValueType & value()
Get access to the value storage.
Definition String.h:382
static constexpr bool hasTrailingFieldSuffix()
Compile time inquiry of whether comms::option::def::SequenceTrailingFieldSuffix option has been used.
Definition String.h:294
const ValueType & value() const
Get access to the value storage.
Definition String.h:388
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition String.h:464
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition String.h:476
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition String.h:367
bool operator==(const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept
Equality comparison operator.
Definition String.h:647
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition String.h:519
static constexpr bool hasName()
Compile time inquiry of whether comms::option::def::HasName option has been used.
Definition String.h:315
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.