COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
FieldType.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"
14
15namespace comms
16{
17
18namespace field
19{
20
21namespace adapter
22{
23
24template <typename TActField, typename TBase>
25class FieldType : public TBase
26{
27 using BaseImpl = TBase;
28public:
29 using ValueType = typename BaseImpl::ValueType;
30
31 bool valid() const
32 {
33 if (m_entered) {
34 return BaseImpl::valid();
35 }
36
37 m_entered = true;
38 auto onExit =
39 comms::util::makeScopeGuard(
40 [this]()
41 {
42 m_entered = false;
43 });
44
45 return static_cast<const TActField*>(this)->valid();
46 }
47
48private:
49 mutable bool m_entered = false;
50};
51
52} // namespace adapter
53
54} // namespace field
55
56} // namespace comms
57
Contains definition of the "Scope Guard" idiom, see comms::util::ScopeGuard.
Contains definition of various casts.
comms::option::def::FieldType< TMsg > FieldType
Same as comms::option::def::FieldType.
Definition options.h:1505
Main namespace for all classes / functions of COMMS library.