25template <
typename TField>
26class Optional :
public
28 comms::option::def::Endian<typename TField::Endian>,
29 comms::option::def::VersionType<typename TField::VersionType>
41 using ValueType = TField;
44 using CommsTag = comms::field::tag::Optional;
48 explicit Optional(
const Field& fieldSrc, Mode mode = Mode::Tentative)
54 explicit Optional(Field&& fieldSrc, Mode mode = Mode::Tentative)
55 : field_(
std::move(fieldSrc)),
60 Optional(
const Optional&) =
default;
62 Optional(Optional&&) =
default;
64 ~Optional() noexcept = default;
66 Optional& operator=(const Optional&) = default;
68 Optional& operator=(Optional&&) = default;
75 const Field& field()
const
85 const ValueType& value()
const
90 const ValueType& getValue()
const
96 void setValue(T&& val)
98 value() = std::forward<T>(val);
106 void setMode(Mode val)
112 std::size_t length()
const
114 if (mode_ != Mode::Exists) {
118 return field_.length();
121 static constexpr std::size_t minLength()
126 static constexpr std::size_t maxLength()
128 return Field::maxLength();
133 if (mode_ == Mode::Missing) {
137 return field_.valid();
141 if (mode_ != Mode::Exists) {
144 return field_.refresh();
147 template <
typename TIter>
150 if (mode_ == Mode::Missing) {
154 if ((mode_ == Mode::Tentative) && (0U == len)) {
155 mode_ = Mode::Missing;
159 auto es = field_.read(iter, len);
161 mode_ = Mode::Exists;
173 if (mode_ != Mode::Exists) {
177 return field_.canWrite();
180 template <
typename TIter>
181 ErrorStatus write(TIter& iter, std::size_t len)
const
183 if (mode_ != Mode::Exists) {
187 return field_.write(iter, len);
195 template <
typename TIter>
196 void writeNoStatus(TIter& iter)
const
198 if (mode_ != Mode::Exists) {
202 field_.writeNoStatus(iter);
222 Mode mode_ = Mode::Tentative;
This file contains classes required for generic custom assertion functionality.
#define COMMS_ASSERT(expr)
Generic assert macro.
Definition Assert.h:170
This file contain definition of error statuses used by comms module.
Contains definition of comms::Field class.
Contains definition of the mode used for comms::field::Optional fields.
Base class to all the field classes.
Definition Field.h:33
static constexpr bool canWrite()
Default check of whether the field has a consistent value for writing.
Definition Field.h:100
static constexpr bool setVersion(VersionType)
Default version update functionality.
Definition Field.h:109
static constexpr bool isVersionDependent()
Default check of whether the field is version dependent.
Definition Field.h:63
static constexpr bool refresh()
Default refresh functionality.
Definition Field.h:56
static constexpr bool hasReadNoStatus()
Default check of whether the field has readNoStatus() member function.
Definition Field.h:77
typename BaseImpl::VersionType VersionType
Version type.
Definition Field.h:42
static constexpr bool hasNonDefaultRefresh()
Default check of whether the field has defines refresh functionality.
Definition Field.h:70
static constexpr bool hasWriteNoStatus()
Default check of whether the field has writeNoStatus() member function.
Definition Field.h:84
static constexpr bool valid()
Default validity check.
Definition Field.h:47
Contains definition of various tag classes.
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
@ Success
Used to indicate successful outcome of the operation.
constexpr unsigned version()
Version of the COMMS library as single numeric value.
Definition version.h:64
Options to specify endian.
Definition options.h:172
Provide type to be used for versioning.
Definition options.h:1159