15#include "details/OptionsParser.h"
17#include "basic/Optional.h"
18#include "details/AdaptBasicField.h"
45template <
typename TField,
typename... TOptions>
46class Optional :
public details::AdaptBasicFieldT<basic::Optional<TField>, TOptions...>
48 using BaseImpl = details::AdaptBasicFieldT<basic::Optional<TField>, TOptions...>;
51 using Endian =
typename BaseImpl::Endian;
75 using FieldType =
typename ParsedOptions::FieldType;
91 : BaseImpl(
std::move(fieldSrc))
114 return ParsedOptions::HasFailOnInvalid;
121 return ParsedOptions::HasIgnoreInvalid;
128 return ParsedOptions::HasEmptySerialization;
135 return ParsedOptions::HasFieldType;
142 return ParsedOptions::HasFixedValue;
149 return ParsedOptions::HasName;
157 return BaseImpl::getMode() == Mode::Tentative;
165 BaseImpl::setMode(Mode::Tentative);
173 return BaseImpl::getMode() == Mode::Missing;
181 BaseImpl::setMode(Mode::Missing);
189 return BaseImpl::getMode() == Mode::Exists;
197 BaseImpl::setMode(Mode::Exists);
203 return BaseImpl::field();
209 return BaseImpl::field();
215 return BaseImpl::value();
221 return BaseImpl::value();
228 return BaseImpl::getValue();
233 template <
typename U>
236 BaseImpl::setValue(std::forward<U>(val));
242 return BaseImpl::getMode();
248 BaseImpl::setMode(val);
258 return BaseImpl::length();
265 return BaseImpl::minLength();
272 return BaseImpl::maxLength();
281 return BaseImpl::valid();
291 return BaseImpl::refresh();
309 template <
typename TIter>
312 return BaseImpl::read(iter, len);
319 return BaseImpl::hasReadNoStatus();
327 template <
typename TIter>
330 BaseImpl::readNoStatus(iter);
336 return BaseImpl::canWrite();
349 template <
typename TIter>
352 return BaseImpl::write(iter, len);
359 return BaseImpl::hasWriteNoStatus();
367 template <
typename TIter>
370 BaseImpl::writeNoStatus(iter);
376 return ParsedOptions::HasCustomVersionUpdate || BaseImpl::isVersionDependent();
382 return BaseImpl::hasNonDefaultRefresh();
389 return BaseImpl::getVersion();
396 return BaseImpl::setVersion(
version);
400 using BaseImpl::readData;
401 using BaseImpl::writeData;
404 static_assert(!ParsedOptions::HasInvalidByDefault,
405 "comms::option::def::InvalidByDefault option is not applicable to Optional field");
413template <
typename TField,
typename... TOptions>
418 if (field1.getMode() != field2.getMode()) {
422 if (field1.isMissing()) {
426 return field1.field() == field2.field();
434template <
typename TField,
typename... TOptions>
439 return !(field1 == field2);
447template <
typename TField,
typename... TOptions>
452 if (field1.isMissing()) {
453 return !field2.isMissing();
456 if (field2.isMissing()) {
460 return field1.field() < field2.field();
468template <
typename TField,
typename... TOptions>
473 return (field2 < field1);
481template <
typename TField,
typename... TOptions>
486 return (field1 < field2) || (field1 == field2);
494template <
typename TField,
typename... TOptions>
499 return field2 <= field1;
510 return std::is_same<typename T::CommsTag, tag::Optional>::value;
516template <
typename TField,
typename... TOptions>
527template <
typename TField,
typename... TOptions>
This file contains classes required for generic custom assertion functionality.
This file contain definition of error statuses used by comms module.
Contains definition of the mode used for comms::field::Optional fields.
Adaptor class to any other field, that makes the field optional.
Definition Optional.h:47
bool operator<(const Optional< TField, TOptions... > &field1, const Optional< TField, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition Optional.h:448
bool operator<=(const Optional< TField, TOptions... > &field1, const Optional< TField, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition Optional.h:482
ErrorStatus read(TIter &iter, std::size_t len)
Read field value from input data sequence.
Definition Optional.h:310
Optional()=default
Default constructor.
Optional(const Field &fieldSrc)
Construct the field.
Definition Optional.h:83
bool operator>(const Optional< TField, TOptions... > &field1, const Optional< TField, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition Optional.h:469
VersionType getVersion() const
Get version of the field.
Definition Optional.h:387
constexpr bool isOptional()
Compile time check function of whether a provided type is any variant of comms::field::Optional.
Definition Optional.h:508
void setExists()
Set mode to Mode::Exists.
Definition Optional.h:195
TField Field
Type of the field.
Definition Optional.h:63
const ValueType & getValue() const
Get value.
Definition Optional.h:226
const Field & field() const
Get an access to the wrapped field object.
Definition Optional.h:207
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition Optional.h:368
Optional(Field &&fieldSrc)
Construct the field.
Definition Optional.h:90
bool isTentative() const
Check whether mode is equivalent to Mode::Tentative.
Definition Optional.h:155
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition Optional.h:328
bool operator>=(const Optional< TField, TOptions... > &field1, const Optional< TField, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition Optional.h:495
Field & field()
Get an access to the wrapped field object.
Definition Optional.h:201
details::OptionsParser< TOptions... > ParsedOptions
All the options provided to this class bundled into struct.
Definition Optional.h:57
bool operator!=(const Optional< TField, TOptions... > &field1, const Optional< TField, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition Optional.h:435
void setMissing()
Set mode to Mode::Missing.
Definition Optional.h:179
typename BaseImpl::CommsTag CommsTag
Tag indicating type of the field.
Definition Optional.h:60
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition Optional.h:133
Optional< TField, TOptions... > & toFieldBase(Optional< TField, TOptions... > &field)
Upcast type of the field definition to its parent comms::field::Optional type in order to have access...
Definition Optional.h:519
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition Optional.h:374
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition Optional.h:270
void setValue(U &&val)
Set value.
Definition Optional.h:234
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition Optional.h:119
static constexpr bool hasName()
Compile time inquiry of whether comms::option::def::HasName option has been used.
Definition Optional.h:147
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition Optional.h:334
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition Optional.h:317
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition Optional.h:380
const ValueType & value() const
Get an access to the wrapped field object.
Definition Optional.h:219
ValueType & value()
Get an access to the wrapped field object.
Definition Optional.h:213
bool doesExist() const
Check whether mode is equivalent to Mode::Exists.
Definition Optional.h:187
static constexpr bool hasFixedValue()
Compile time inquiry of whether comms::option::def::FixedValue option has been used.
Definition Optional.h:140
Mode getMode() const
Get current optional mode.
Definition Optional.h:240
Optional(const Optional &)=default
Copy constructor.
const Optional< TField, TOptions... > & toFieldBase(const Optional< TField, TOptions... > &field)
Upcast type of the field definition to its parent comms::field::Optional type in order to have access...
Definition Optional.h:530
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition Optional.h:51
std::size_t length() const
Get length required to serialise the current field value.
Definition Optional.h:256
~Optional() noexcept=default
Destructor.
void setMode(Mode val)
Get optional mode.
Definition Optional.h:246
bool operator==(const Optional< TField, TOptions... > &field1, const Optional< TField, TOptions... > &field2) noexcept
Equality comparison operator.
Definition Optional.h:414
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition Optional.h:112
bool valid() const
Check validity of the field value.
Definition Optional.h:279
bool isMissing() const
Check whether mode is equivalent to Mode::Missing.
Definition Optional.h:171
Field ValueType
Value type of this field, equal to Field.
Definition Optional.h:66
typename BaseImpl::VersionType VersionType
Version type.
Definition Optional.h:54
ErrorStatus write(TIter &iter, std::size_t len) const
Write current field value to output data sequence.
Definition Optional.h:350
bool refresh()
Refresh the field's value.
Definition Optional.h:289
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition Optional.h:357
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition Optional.h:263
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition Optional.h:126
bool setVersion(VersionType version)
Default implementation of version update.
Definition Optional.h:394
Optional(Optional &&)=default
Move constructor.
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition Optional.h:75
void setTentative()
Set mode to Mode::Tentative.
Definition Optional.h:163
OptionalMode
Mode to be used by comms::field::Optional.
Definition OptionalMode.h:22
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