cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ToolsBitfieldFieldImpl.h
1//
2// Copyright 2014 - 2025 (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#pragma once
19
20#include "cc_tools_qt/details/ToolsFieldBase.h"
21#include "cc_tools_qt/field/ToolsBitfieldField.h"
22
23#include <cstdint>
24#include <cassert>
25#include <memory>
26#include <vector>
27
28#include "comms/field/Bitfield.h"
29
30namespace cc_tools_qt
31{
32
33namespace details
34{
35
36template <typename TField>
37class ToolsBitfieldFieldImpl : public ToolsFieldBase<cc_tools_qt::field::ToolsBitfieldField, TField>
38{
39 using Base = ToolsFieldBase<cc_tools_qt::field::ToolsBitfieldField, TField>;
40
41 using Field = TField;
42 static_assert(comms::field::isBitfield<Field>(), "Must be of Bitfield field type");
43
44public:
45 using Ptr = typename Base::Ptr;
46 using ActPtr = typename Base::ActPtr;
47
48 explicit ToolsBitfieldFieldImpl(Field& fieldRef)
49 : Base(fieldRef)
50 {
51 }
52
53 ToolsBitfieldFieldImpl(const ToolsBitfieldFieldImpl&) = default;
54 ToolsBitfieldFieldImpl(ToolsBitfieldFieldImpl&&) = default;
55 virtual ~ToolsBitfieldFieldImpl() noexcept = default;
56
57 ToolsBitfieldFieldImpl& operator=(const ToolsBitfieldFieldImpl&) = delete;
58
59protected:
60 virtual Ptr cloneImpl() override
61 {
62 return ActPtr(new ToolsBitfieldFieldImpl<TField>(Base::field()));
63 }
64
65 virtual void membersUpdatedImpl() override
66 {
67 auto& mems = Base::getMembers();
68 for (auto& m : mems) {
69 assert(m);
70 m->forceHiddenSerialization();
71 }
72 }
73
74};
75
76template <typename TField>
77auto makeBitfieldField(TField& field)
78{
79 return std::make_unique<ToolsBitfieldFieldImpl<TField>>(field);
80}
81
82} // namespace details
83
84} // namespace cc_tools_qt
Main namespace for all classes / functions of the shared library.