17#include "comms/details/tag.h"
18#include "comms/field/basic/String.h"
19#include "comms/field/details/AdaptBasicField.h"
20#include "comms/field/details/OptionsParser.h"
32#if COMMS_HAS_CPP17_STRING_VIEW
48template <
bool THasOrigDataViewStorage>
49struct StringOrigDataViewStorageType;
52struct StringOrigDataViewStorageType<true>
54#if COMMS_HAS_CPP17_STRING_VIEW
55 using Type = std::string_view;
62struct StringOrigDataViewStorageType<false>
64 using Type = std::string;
67template <
bool THasSequenceFixedSizeUseFixedSizeStorage>
68struct StringFixedSizeUseFixedSizeStorageType;
71struct StringFixedSizeUseFixedSizeStorageType<true>
73 template <
typename TOpt>
78struct StringFixedSizeUseFixedSizeStorageType<false>
80 template <
typename TOpt>
81 using Type =
typename StringOrigDataViewStorageType<TOpt::HasOrigDataView>::Type;
84template <
bool THasFixedSizeStorage>
85struct StringFixedSizeStorageType;
88struct StringFixedSizeStorageType<true>
90 template <
typename TOpt>
95struct StringFixedSizeStorageType<false>
97 template <
typename TOpt>
98 using Type =
typename StringFixedSizeUseFixedSizeStorageType<TOpt::HasSequenceFixedSizeUseFixedSizeStorage>
99 ::template Type<TOpt>;
102template <
bool THasCustomStorage>
103struct StringCustomStringStorageType;
106struct StringCustomStringStorageType<true>
108 template <
typename TOpt>
109 using Type =
typename TOpt::CustomStorageType;
113struct StringCustomStringStorageType<false>
115 template <
typename TOpt>
117 typename StringFixedSizeStorageType<TOpt::HasFixedSizeStorage>::template Type<TOpt>;
120template <
typename TOpt>
121using StringStorageTypeT =
122 typename StringCustomStringStorageType<TOpt::HasCustomStorageType>::template Type<TOpt>;
124template <
typename TFieldBase,
typename... TOptions>
127 basic::String<TFieldBase, StringStorageTypeT<OptionsParser<TOptions...> > >,
166template <
typename TFieldBase,
typename... TOptions>
167class String :
public details::StringBase<TFieldBase, TOptions...>
169 using BaseImpl = details::StringBase<TFieldBase, TOptions...>;
175 using Endian =
typename BaseImpl::Endian;
225 : BaseImpl(
std::move(val))
254 return ParsedOptions::HasFailOnInvalid;
261 return ParsedOptions::HasIgnoreInvalid;
268 return ParsedOptions::HasEmptySerialization;
275 return ParsedOptions::HasFieldType;
282 return ParsedOptions::HasSequenceSizeFieldPrefix;
289 return ParsedOptions::HasSequenceSerLengthFieldPrefix;
296 return ParsedOptions::HasSequenceTerminationFieldSuffix;
303 return ParsedOptions::HasSequenceTrailingFieldSuffix;
310 return ParsedOptions::HasSequenceFixedSize;
317 return ParsedOptions::HasFixedValue;
324 return ParsedOptions::HasName;
332 return ParsedOptions::SequenceFixedSize;
345 template <
typename TIter>
348 auto es = BaseImpl::read(iter, len);
350 typename comms::util::LazyShallowConditional<
351 ParsedOptions::HasSequenceFixedSize
357 adjustValue(TagTmp());
365 return BaseImpl::hasReadNoStatus();
373 template <
typename TIter>
376 BaseImpl::readNoStatus(iter);
378 typename comms::util::LazyShallowConditional<
379 ParsedOptions::HasSequenceFixedSize
385 adjustValue(TagTmp());
391 return BaseImpl::value();
397 return BaseImpl::value();
404 return BaseImpl::getValue();
409 template <
typename U>
412 BaseImpl::setValue(std::forward<U>(val));
418 return BaseImpl::length();
424 return BaseImpl::valid();
431 return BaseImpl::refresh();
437 return BaseImpl::canWrite();
452 template <
typename TIter>
455 return BaseImpl::write(iter, len);
462 return BaseImpl::hasWriteNoStatus();
470 template <
typename TIter>
473 BaseImpl::writeNoStatus(iter);
479 return BaseImpl::minLength();
485 return BaseImpl::maxLength();
495 BaseImpl::forceReadElemCount(count);
504 BaseImpl::clearReadElemCount();
513 return BaseImpl::forceReadLength(count);
522 return BaseImpl::clearReadLengthForcing();
528 return ParsedOptions::HasCustomVersionUpdate || BaseImpl::isVersionDependent();
534 return BaseImpl::hasNonDefaultRefresh();
541 return BaseImpl::getVersion();
548 return BaseImpl::setVersion(
version);
552 using BaseImpl::readData;
553 using BaseImpl::writeData;
556 template <
typename... TParams>
557 using NoAdjustmentTag = comms::details::tag::Tag1<>;
559 template <
typename... TParams>
560 using AdjustmentNeededTag = comms::details::tag::Tag2<>;
562 template <
typename... TParams>
563 using HasResizeTag = comms::details::tag::Tag3<>;
565 template <
typename... TParams>
566 using HasRemoveSuffixTag = comms::details::tag::Tag4<>;
568 template <
typename... TParams>
569 void adjustValue(NoAdjustmentTag<TParams...>)
573 template <
typename... TParams>
574 void adjustValue(AdjustmentNeededTag<TParams...>)
576 std::size_t count = 0;
577 for (
auto iter = BaseImpl::value().begin(); iter != BaseImpl::value().end(); ++iter) {
587 void doResize(std::size_t count)
591 comms::util::detect::hasResizeFunc<ValueType>()
595 comms::util::detect::hasRemoveSuffixFunc<ValueType>()
597 HasRemoveSuffixTag<>,
602 static_assert(!std::is_void<TagTmp>::value,
603 "The string storage value type must have either resize() or remove_suffix() "
605 doResize(count, TagTmp());
608 template <
typename... TParams>
609 void doResize(std::size_t count, HasResizeTag<TParams...>)
611 BaseImpl::value().resize(count);
614 template <
typename... TParams>
615 void doResize(std::size_t count, HasRemoveSuffixTag<TParams...>)
617 BaseImpl::value().remove_suffix(BaseImpl::value().size() - count);
620 static_assert(!ParsedOptions::HasSerOffset,
621 "comms::option::def::NumValueSerOffset option is not applicable to String field");
622 static_assert(!ParsedOptions::HasFixedLengthLimit,
623 "comms::option::def::FixedLength option is not applicable to String field");
624 static_assert(!ParsedOptions::HasFixedBitLengthLimit,
625 "comms::option::def::FixedBitLength option is not applicable to String field");
626 static_assert(!ParsedOptions::HasVarLengthLimits,
627 "comms::option::def::VarLength option is not applicable to String field");
628 static_assert(!ParsedOptions::HasAvailableLengthLimit,
629 "comms::option::def::AvailableLengthLimit option is not applicable to String field");
630 static_assert(!ParsedOptions::HasScalingRatio,
631 "comms::option::def::ScalingRatio option is not applicable to String field");
632 static_assert(!ParsedOptions::HasUnits,
633 "comms::option::def::Units option is not applicable to String field");
634 static_assert(!ParsedOptions::HasMultiRangeValidation,
635 "comms::option::def::ValidNumValueRange (or similar) option is not applicable to String field");
636 static_assert(!ParsedOptions::HasSequenceElemSerLengthFieldPrefix,
637 "comms::option::def::SequenceElemSerLengthFieldPrefix option is not applicable to String field");
638 static_assert(!ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix,
639 "comms::option::def::SequenceElemSerLengthFixedFieldPrefix option is not applicable to String field");
640 static_assert(!ParsedOptions::HasVersionsRange,
641 "comms::option::def::ExistsBetweenVersions (or similar) option is not applicable to String field");
642 static_assert(!ParsedOptions::HasMissingOnReadFail,
643 "comms::option::def::MissingOnReadFail option is not applicable to String field");
644 static_assert(!ParsedOptions::HasMissingOnInvalid,
645 "comms::option::def::MissingOnInvalid option is not applicable to String field");
653template <
typename TFieldBase,
typename... TOptions>
658 return field1.value() == field2.value();
666template <
typename TFieldBase,
typename... TOptions>
671 return field1.value() != field2.value();
680template <
typename TFieldBase,
typename... TOptions>
685 return field1.value() < field2.value();
696 return std::is_same<typename T::CommsTag, tag::String>::value;
702template <
typename TFieldBase,
typename... TOptions>
704String<TFieldBase, TOptions...>&
713template <
typename TFieldBase,
typename... TOptions>
715const 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:168
TFieldBase FieldBase
Base class provided in the first template parameter.
Definition String.h:172
typename ParsedOptions::SequenceTrailingFieldSuffix TrailingFieldSuffix
Type of trailing field suffix specified via comms::option::def::SequenceTrailingFieldSuffix.
Definition String.h:212
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition String.h:252
String(const ValueType &val)
Constructor.
Definition String.h:218
constexpr bool isString()
Compile time check function of whether a provided type is any variant of comms::field::String.
Definition String.h:694
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition String.h:196
static constexpr bool hasTerminationFieldSuffix()
Compile time inquiry of whether comms::option::def::SequenceTerminationFieldSuffix option has been us...
Definition String.h:294
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition String.h:460
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition String.h:273
typename ParsedOptions::SequenceTerminationFieldSuffix TerminationFieldSuffix
Type of termination field suffix specified via comms::option::def::SequenceTerminationFieldSuffix.
Definition String.h:208
static constexpr std::size_t fixedSize()
Compile time inquiry of fixed size provided via comms::option::def::SequenceFixedSize option.
Definition String.h:330
typename ParsedOptions::SequenceSerLengthFieldPrefix SerLengthFieldPrefix
Type of length field prefix specified via comms::option::def::SequenceSerLengthFieldPrefix.
Definition String.h:204
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition String.h:477
ErrorStatus read(TIter &iter, std::size_t len)
Read field value from input data sequence.
Definition String.h:346
static constexpr bool hasSerLengthFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceSerLengthFieldPrefix option has been used...
Definition String.h:287
~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:493
void setValue(U &&val)
Set value.
Definition String.h:410
bool operator!=(const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition String.h:667
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition String.h:435
static constexpr bool hasSizeFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceSizeFieldPrefix option has been used.
Definition String.h:280
VersionType getVersion() const
Get version of the field.
Definition String.h:539
void forceReadLength(std::size_t count)
Force available length for the next read() invocation.
Definition String.h:511
static constexpr bool hasFixedValue()
Compile time inquiry of whether comms::option::def::FixedValue option has been used.
Definition String.h:315
bool setVersion(VersionType version)
Default implementation of version update.
Definition String.h:546
ErrorStatus write(TIter &iter, std::size_t len) const
Write current field value to output data sequence.
Definition String.h:453
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition String.h:259
void clearReadElemCount()
Clear forcing of the number of characters that must be read in the next read() invocation.
Definition String.h:502
const ValueType & getValue() const
Get value.
Definition String.h:402
bool operator<(const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition String.h:681
typename BaseImpl::CommsTag CommsTag
Tag indicating type of the field.
Definition String.h:184
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition String.h:363
typename BaseImpl::ValueType ValueType
Type of underlying value.
Definition String.h:191
bool valid() const
Check validity of the field value.
Definition String.h:422
static constexpr bool hasFixedSize()
Compile time inquiry of whether comms::option::def::SequenceFixedSize option has been used.
Definition String.h:308
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:705
bool refresh()
Refresh the field's value.
Definition String.h:429
String(const char *str)
Constructor.
Definition String.h:230
String()=default
Default constructor.
typename BaseImpl::VersionType VersionType
Version type.
Definition String.h:178
String(String &&)=default
Move constructor.
std::size_t length() const
Get length of serialised data.
Definition String.h:416
details::OptionsParser< TOptions... > ParsedOptions
All the options provided to this class bundled into struct.
Definition String.h:181
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition String.h:266
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition String.h:175
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:716
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition String.h:532
String(ValueType &&val)
Constructor.
Definition String.h:224
typename ParsedOptions::SequenceSizeFieldPrefix SizeFieldPrefix
Type of size field prefix specified via comms::option::def::SequenceSizeFieldPrefix.
Definition String.h:200
void clearReadLengthForcing()
Clear forcing of the available length in the next read() invocation.
Definition String.h:520
ValueType & value()
Get access to the value storage.
Definition String.h:389
static constexpr bool hasTrailingFieldSuffix()
Compile time inquiry of whether comms::option::def::SequenceTrailingFieldSuffix option has been used.
Definition String.h:301
const ValueType & value() const
Get access to the value storage.
Definition String.h:395
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition String.h:471
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition String.h:483
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition String.h:374
bool operator==(const String< TFieldBase, TOptions... > &field1, const String< TFieldBase, TOptions... > &field2) noexcept
Equality comparison operator.
Definition String.h:654
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition String.h:526
static constexpr bool hasName()
Compile time inquiry of whether comms::option::def::HasName option has been used.
Definition String.h:322
Replacement to std::string when no dynamic memory allocation is allowed.
Definition StaticString.h:791
Describes an object that can refer to a constant contiguous sequence of char-like objects with the fi...
Definition StringView.h:37
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:19
constexpr unsigned version()
Version of the COMMS library as single numeric value.
Definition version.h:66
Contains definition of all the options used by the COMMS library.
Replacement to std::conditional.
Definition type_traits.h:32
Replacement to some types from standard type_traits.
Various compile-time detection functions of whether specific member functions and/or types exist.