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