cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
EnumValueWrapper.h
1//
2// Copyright 2014 - 2024 (C). Alex Robenko. All rights reserved.
3//
4
5// This file is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18
19#pragma once
20
21#include <cstdint>
22#include <cassert>
23#include <memory>
24
25#include "comms/field/EnumValue.h"
26#include "NumericValueWrapper.h"
27
28namespace cc_tools_qt
29{
30
31namespace field_wrapper
32{
33
34class CC_API EnumValueWrapper : public NumericValueWrapper<long long int>
35{
36 using Base = NumericValueWrapper<long long int>;
37public:
38 using UnderlyingType = Base::UnderlyingType;
39 typedef std::unique_ptr<EnumValueWrapper> Ptr;
40
41 EnumValueWrapper();
42 virtual ~EnumValueWrapper() noexcept;
43
44 Ptr clone();
45
46protected:
47 virtual Ptr cloneImpl() = 0;
48
49 void dispatchImpl(FieldWrapperHandler& handler);
50};
51
52template <typename TField>
53class EnumValueWrapperT : public NumericValueWrapperT<EnumValueWrapper, TField>
54{
55 using Base = NumericValueWrapperT<EnumValueWrapper, TField>;
56 using Field = TField;
57 static_assert(comms::field::isEnumValue<Field>(), "Must be of EnumValueField type");
58
59 using ValueType = typename Field::ValueType;
60 using UnderlyingType = typename Base::UnderlyingType;
61 static_assert(sizeof(ValueType) <= sizeof(UnderlyingType), "This wrapper cannot handle provided field.");
62// static_assert(std::is_signed<ValueType>::value || (sizeof(ValueType) < sizeof(UnderlyingType)),
63// "This wrapper cannot handle provided field.");
64
65public:
66 typedef typename Base::Ptr Ptr;
67
68 explicit EnumValueWrapperT(Field& fieldRef)
69 : Base(fieldRef)
70 {
71 }
72
73 EnumValueWrapperT(const EnumValueWrapperT&) = default;
74 EnumValueWrapperT(EnumValueWrapperT&&) = default;
75 virtual ~EnumValueWrapperT() noexcept = default;
76
77 EnumValueWrapperT& operator=(const EnumValueWrapperT&) = delete;
78
79protected:
80 virtual Ptr cloneImpl() override
81 {
82 return Ptr(new EnumValueWrapperT<TField>(Base::field()));
83 }
84
85};
86
87using EnumValueWrapperPtr = std::unique_ptr<EnumValueWrapper>;
88
89template <typename TField>
90EnumValueWrapperPtr
91makeEnumValueWrapper(TField& field)
92{
93 return
94 EnumValueWrapperPtr(
95 new EnumValueWrapperT<TField>(field));
96}
97
98} // namespace field_wrapper
99
100} // namespace cc_tools_qt
Main namespace for all classes / functions of the shared library.