COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
FieldType.h
1//
2// Copyright 2019 - 2025 (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/cast.h"
12
13#include <type_traits>
14#include <utility>
15
16namespace comms
17{
18
19namespace field
20{
21
22namespace adapter
23{
24
25template <typename TActField, typename TBase>
26class FieldType : public TBase
27{
28 using BaseImpl = TBase;
29public:
30 using ValueType = typename BaseImpl::ValueType;
31
32 bool valid() const
33 {
34 if (m_entered) {
35 return BaseImpl::valid();
36 }
37
38 m_entered = true;
39 auto onExit =
40 comms::util::makeScopeGuard(
41 [this]()
42 {
43 m_entered = false;
44 });
45
46 return static_cast<const TActField*>(this)->valid();
47 }
48
49private:
50 mutable bool m_entered = false;
51};
52
53} // namespace adapter
54
55} // namespace field
56
57} // namespace comms
58
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:1503
Main namespace for all classes / functions of COMMS library.