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