COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
FailOnInvalid.h
1//
2// Copyright 2015 - 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/Assert.h"
13#include "comms/ErrorStatus.h"
14
15#include <cstddef>
16#include <utility>
17
18namespace comms
19{
20
21namespace field
22{
23
24namespace adapter
25{
26
27template <comms::ErrorStatus TStatus, typename TBase>
28class FailOnInvalid : public TBase
29{
30 using BaseImpl = TBase;
31public:
32
33 using ValueType = typename BaseImpl::ValueType;
34
35 FailOnInvalid() = default;
36
37 explicit FailOnInvalid(const ValueType& val)
38 : BaseImpl(val)
39 {
40 }
41
42 explicit FailOnInvalid(ValueType&& val)
43 : BaseImpl(std::move(val))
44 {
45 }
46
47 FailOnInvalid(const FailOnInvalid&) = default;
48 FailOnInvalid(FailOnInvalid&&) = default;
49 FailOnInvalid& operator=(const FailOnInvalid&) = default;
50 FailOnInvalid& operator=(FailOnInvalid&&) = default;
51
52 template <typename TIter>
53 comms::ErrorStatus read(TIter& iter, std::size_t len)
54 {
55 BaseImpl tmp;
56 auto es = tmp.read(iter, len);
58 return es;
59 }
60
61 if (!tmp.valid()) {
62 return TStatus;
63 }
64
65 static_cast<BaseImpl&>(*this) = std::move(tmp);
67 }
68
69 static constexpr bool hasReadNoStatus()
70 {
71 return false;
72 }
73
74 template <typename TIter>
75 void readNoStatus(TIter& iter) = delete;
76};
77
78} // namespace adapter
79
80} // namespace field
81
82} // namespace comms
83
This file contains classes required for generic custom assertion functionality.
This file contain definition of error statuses used by comms module.
comms::option::def::FailOnInvalid< TStatus > FailOnInvalid
Same as comms::option::def::FailOnInvalid.
Definition options.h:1617
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.
STL namespace.