15#include "details/OptionsParser.h"
17#include "basic/Optional.h"
18#include "details/AdaptBasicField.h"
43template <
typename TField,
typename... TOptions>
44class Optional :
public details::AdaptBasicFieldT<basic::Optional<TField>, TOptions...>
46 using BaseImpl = details::AdaptBasicFieldT<basic::Optional<TField>, TOptions...>;
49 using Endian =
typename BaseImpl::Endian;
73 using FieldType =
typename ParsedOptions::FieldType;
89 : BaseImpl(
std::move(fieldSrc))
112 return ParsedOptions::HasFailOnInvalid;
119 return ParsedOptions::HasIgnoreInvalid;
126 return ParsedOptions::HasEmptySerialization;
133 return ParsedOptions::HasFieldType;
141 return BaseImpl::getMode() == Mode::Tentative;
149 BaseImpl::setMode(Mode::Tentative);
157 return BaseImpl::getMode() == Mode::Missing;
165 BaseImpl::setMode(Mode::Missing);
173 return BaseImpl::getMode() == Mode::Exists;
181 BaseImpl::setMode(Mode::Exists);
187 return BaseImpl::field();
193 return BaseImpl::field();
199 return BaseImpl::value();
205 return BaseImpl::value();
212 return BaseImpl::getValue();
217 template <
typename U>
220 BaseImpl::setValue(std::forward<U>(val));
226 return BaseImpl::getMode();
232 BaseImpl::setMode(val);
242 return BaseImpl::length();
249 return BaseImpl::minLength();
256 return BaseImpl::maxLength();
265 return BaseImpl::valid();
275 return BaseImpl::refresh();
293 template <
typename TIter>
296 return BaseImpl::read(iter, len);
303 return BaseImpl::hasReadNoStatus();
311 template <
typename TIter>
314 BaseImpl::readNoStatus(iter);
320 return BaseImpl::canWrite();
333 template <
typename TIter>
336 return BaseImpl::write(iter, len);
343 return BaseImpl::hasWriteNoStatus();
351 template <
typename TIter>
354 BaseImpl::writeNoStatus(iter);
360 return ParsedOptions::HasCustomVersionUpdate || BaseImpl::isVersionDependent();
366 return BaseImpl::hasNonDefaultRefresh();
373 return BaseImpl::getVersion();
380 return BaseImpl::setVersion(
version);
384 using BaseImpl::readData;
385 using BaseImpl::writeData;
388 static_assert(!ParsedOptions::HasInvalidByDefault,
389 "comms::option::def::InvalidByDefault option is not applicable to Optional field");
397template <
typename TField,
typename... TOptions>
402 if (field1.getMode() != field2.getMode()) {
406 if (field1.isMissing()) {
410 return field1.field() == field2.field();
418template <
typename TField,
typename... TOptions>
423 return !(field1 == field2);
431template <
typename TField,
typename... TOptions>
436 if (field1.isMissing()) {
437 return !field2.isMissing();
440 if (field2.isMissing()) {
444 return field1.field() < field2.field();
452template <
typename TField,
typename... TOptions>
457 return (field2 < field1);
465template <
typename TField,
typename... TOptions>
470 return (field1 < field2) || (field1 == field2);
478template <
typename TField,
typename... TOptions>
483 return field2 <= field1;
494 return std::is_same<typename T::CommsTag, tag::Optional>::value;
500template <
typename TField,
typename... TOptions>
511template <
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:45
bool operator<(const Optional< TField, TOptions... > &field1, const Optional< TField, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition Optional.h:432
bool operator<=(const Optional< TField, TOptions... > &field1, const Optional< TField, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition Optional.h:466
ErrorStatus read(TIter &iter, std::size_t len)
Read field value from input data sequence.
Definition Optional.h:294
Optional()=default
Default constructor.
Optional(const Field &fieldSrc)
Construct the field.
Definition Optional.h:81
bool operator>(const Optional< TField, TOptions... > &field1, const Optional< TField, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition Optional.h:453
VersionType getVersion() const
Get version of the field.
Definition Optional.h:371
constexpr bool isOptional()
Compile time check function of whether a provided type is any variant of comms::field::Optional.
Definition Optional.h:492
void setExists()
Set mode to Mode::Exists.
Definition Optional.h:179
TField Field
Type of the field.
Definition Optional.h:61
const ValueType & getValue() const
Get value.
Definition Optional.h:210
const Field & field() const
Get an access to the wrapped field object.
Definition Optional.h:191
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition Optional.h:352
Optional(Field &&fieldSrc)
Construct the field.
Definition Optional.h:88
bool isTentative() const
Check whether mode is equivalent to Mode::Tentative.
Definition Optional.h:139
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition Optional.h:312
bool operator>=(const Optional< TField, TOptions... > &field1, const Optional< TField, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition Optional.h:479
Field & field()
Get an access to the wrapped field object.
Definition Optional.h:185
details::OptionsParser< TOptions... > ParsedOptions
All the options provided to this class bundled into struct.
Definition Optional.h:55
bool operator!=(const Optional< TField, TOptions... > &field1, const Optional< TField, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition Optional.h:419
void setMissing()
Set mode to Mode::Missing.
Definition Optional.h:163
typename BaseImpl::CommsTag CommsTag
Tag indicating type of the field.
Definition Optional.h:58
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition Optional.h:131
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:503
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition Optional.h:358
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition Optional.h:254
void setValue(U &&val)
Set value.
Definition Optional.h:218
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition Optional.h:117
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition Optional.h:318
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition Optional.h:301
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition Optional.h:364
const ValueType & value() const
Get an access to the wrapped field object.
Definition Optional.h:203
ValueType & value()
Get an access to the wrapped field object.
Definition Optional.h:197
bool doesExist() const
Check whether mode is equivalent to Mode::Exists.
Definition Optional.h:171
Mode getMode() const
Get current optional mode.
Definition Optional.h:224
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:514
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition Optional.h:49
std::size_t length() const
Get length required to serialise the current field value.
Definition Optional.h:240
~Optional() noexcept=default
Destructor.
void setMode(Mode val)
Get optional mode.
Definition Optional.h:230
bool operator==(const Optional< TField, TOptions... > &field1, const Optional< TField, TOptions... > &field2) noexcept
Equality comparison operator.
Definition Optional.h:398
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition Optional.h:110
bool valid() const
Check validity of the field value.
Definition Optional.h:263
bool isMissing() const
Check whether mode is equivalent to Mode::Missing.
Definition Optional.h:155
Field ValueType
Value type of this field, equal to Field.
Definition Optional.h:64
typename BaseImpl::VersionType VersionType
Version type.
Definition Optional.h:52
ErrorStatus write(TIter &iter, std::size_t len) const
Write current field value to output data sequence.
Definition Optional.h:334
bool refresh()
Refresh the field's value.
Definition Optional.h:273
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition Optional.h:341
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition Optional.h:247
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition Optional.h:124
bool setVersion(VersionType version)
Default implementation of version update.
Definition Optional.h:378
Optional(Optional &&)=default
Move constructor.
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition Optional.h:73
void setTentative()
Set mode to Mode::Tentative.
Definition Optional.h:147
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