cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
BitfieldWrapper.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#include <vector>
25
26#include "comms/field/Bitfield.h"
27#include "FieldWrapper.h"
28
29namespace cc_tools_qt
30{
31
32namespace field_wrapper
33{
34
35class CC_API BitfieldWrapper : public FieldWrapper
36{
37 using Base = FieldWrapper;
38public:
39 typedef std::vector<FieldWrapperPtr> Members;
40
41 typedef unsigned long long UnderlyingType;
42 typedef std::unique_ptr<BitfieldWrapper> Ptr;
43
44 BitfieldWrapper();
45 BitfieldWrapper(const BitfieldWrapper&) = delete;
46 BitfieldWrapper& operator=(const BitfieldWrapper&) = delete;
47
48 virtual ~BitfieldWrapper() noexcept;
49
50 Members& getMembers();
51
52 const Members& getMembers() const;
53
54 void setMembers(Members&& members);
55
56 Ptr clone();
57
58protected:
59 virtual Ptr cloneImpl() = 0;
60
61 void dispatchImpl(FieldWrapperHandler& handler);
62
63private:
64 Members m_members;
65};
66
67template <typename TField>
68class BitfieldWrapperT : public FieldWrapperT<BitfieldWrapper, TField>
69{
70 using Base = FieldWrapperT<BitfieldWrapper, TField>;
71 using Field = TField;
72 static_assert(comms::field::isBitfield<Field>(), "Must be of Bitfield field type");
73
74 using UnderlyingType = typename Base::UnderlyingType;
75public:
76 typedef typename Base::Ptr Ptr;
77
78 explicit BitfieldWrapperT(Field& fieldRef)
79 : Base(fieldRef)
80 {
81 }
82
83 BitfieldWrapperT(const BitfieldWrapperT&) = default;
84 BitfieldWrapperT(BitfieldWrapperT&&) = default;
85 virtual ~BitfieldWrapperT() noexcept = default;
86
87 BitfieldWrapperT& operator=(const BitfieldWrapperT&) = delete;
88
89protected:
90 virtual Ptr cloneImpl() override
91 {
92 return Ptr(new BitfieldWrapperT<TField>(Base::field()));
93 }
94
95};
96
97using BitfieldWrapperPtr = BitfieldWrapper::Ptr;
98
99template <typename TField>
100BitfieldWrapperPtr
101makeBitfieldWrapper(TField& field)
102{
103 return
104 BitfieldWrapperPtr(
105 new BitfieldWrapperT<TField>(field));
106}
107
108} // namespace field_wrapper
109
110} // namespace cc_tools_qt
Main namespace for all classes / functions of the shared library.