COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
IgnoreInvalid.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 <typename TBase>
28class IgnoreInvalid : public TBase
29{
30 using BaseImpl = TBase;
31public:
32
33 using ValueType = typename BaseImpl::ValueType;
34
35 IgnoreInvalid() = default;
36
37 explicit IgnoreInvalid(const ValueType& val)
38 : BaseImpl(val)
39 {
40 }
41
42 explicit IgnoreInvalid(ValueType&& val)
43 : BaseImpl(std::move(val))
44 {
45 }
46
47 IgnoreInvalid(const IgnoreInvalid&) = default;
48 IgnoreInvalid(IgnoreInvalid&&) = default;
49 IgnoreInvalid& operator=(const IgnoreInvalid&) = default;
50 IgnoreInvalid& operator=(IgnoreInvalid&&) = 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 static_cast<BaseImpl&>(*this) = std::move(tmp);
63 }
64
66 }
67
68 template <typename TIter>
69 void readNoStatus(TIter& iter)
70 {
71 BaseImpl tmp;
72 tmp.readNoStatus(iter);
73
74 if (tmp.valid()) {
75 static_cast<BaseImpl&>(*this) = std::move(tmp);
76 }
77 }
78};
79
80} // namespace adapter
81
82} // namespace field
83
84} // namespace comms
85
This file contains classes required for generic custom assertion functionality.
This file contain definition of error statuses used by comms module.
comms::option::def::IgnoreInvalid IgnoreInvalid
Same as comms::option::def::IgnoreInvalid.
Definition options.h:1621
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.