COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
FailOnInvalid.h
1//
2// Copyright 2015 - 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 "comms/Assert.h"
11#include "comms/ErrorStatus.h"
12
13namespace comms
14{
15
16namespace field
17{
18
19namespace adapter
20{
21
22template <comms::ErrorStatus TStatus, typename TBase>
23class FailOnInvalid : public TBase
24{
25 using BaseImpl = TBase;
26public:
27
28 using ValueType = typename BaseImpl::ValueType;
29
30 FailOnInvalid() = default;
31
32 explicit FailOnInvalid(const ValueType& val)
33 : BaseImpl(val)
34 {
35 }
36
37 explicit FailOnInvalid(ValueType&& val)
38 : BaseImpl(std::move(val))
39 {
40 }
41
42 FailOnInvalid(const FailOnInvalid&) = default;
43 FailOnInvalid(FailOnInvalid&&) = default;
44 FailOnInvalid& operator=(const FailOnInvalid&) = default;
45 FailOnInvalid& operator=(FailOnInvalid&&) = default;
46
47 template <typename TIter>
48 comms::ErrorStatus read(TIter& iter, std::size_t len)
49 {
50 BaseImpl tmp;
51 auto es = tmp.read(iter, len);
53 return es;
54 }
55
56 if (!tmp.valid()) {
57 return TStatus;
58 }
59
60 static_cast<BaseImpl&>(*this) = std::move(tmp);
62 }
63
64 static constexpr bool hasReadNoStatus()
65 {
66 return false;
67 }
68
69 template <typename TIter>
70 void readNoStatus(TIter& iter) = delete;
71};
72
73} // namespace adapter
74
75} // namespace field
76
77} // namespace comms
78
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:1552
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.
STL namespace.