COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
MissingOnInvalid.h
1//
2// Copyright 2019 - 2026 (C). Alex Robenko. All rights reserved.
3//
4// SPDX-License-Identifier: MPL-2.0
5//
6// This Source Code Form is subject to the terms of the Mozilla Public
7// License, v. 2.0. If a copy of the MPL was not distributed with this
8// file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#pragma once
11
12#include "comms/cast.h"
13
14#include <cstddef>
15
16namespace comms
17{
18
19namespace field
20{
21
22namespace adapter
23{
24
25template <typename TBase>
26class MissingOnInvalid : public TBase
27{
28 using BaseImpl = TBase;
29public:
30
31 template <typename TIter>
32 comms::ErrorStatus read(TIter& iter, std::size_t len)
33 {
34 auto iterTmp = iter;
35 auto es = BaseImpl::read(iterTmp, len);
37 return es;
38 }
39
40 if (!BaseImpl::valid()) {
41 BaseImpl::setMode(comms::field::OptionalMode::Missing);
42 return es;
43 }
44
45 iter = iterTmp;
46 return es;
47 }
48
49 static constexpr bool hasReadNoStatus()
50 {
51 return false;
52 }
53
54 template <typename TIter>
55 void readNoStatus(TIter& iter) = delete;
56
57 static constexpr bool hasNonDefaultRefresh()
58 {
59 return true;
60 }
61
62 bool refresh()
63 {
64 bool updated = BaseImpl::refresh();
65 auto mode = BaseImpl::getMode();
66 if (!BaseImpl::valid()) {
68 }
69
70 if (mode == BaseImpl::getMode()) {
71 return updated;
72 }
73
74 BaseImpl::setMode(mode);
75 return true;
76 }
77};
78
79} // namespace adapter
80
81} // namespace field
82
83} // namespace comms
84
Contains definition of various casts.
@ Missing
Field doesn't exist.
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:19
@ Success
Used to indicate successful outcome of the operation.