cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ToolsBitfieldFieldImpl.h
1//
2// Copyright 2014 - 2026 (C). Alex Robenko. All rights reserved.
3//
4// SPDX-License-Identifier: GPL-3.0-or-later
5//
6
7// This file is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20#pragma once
21
22#include "cc_tools_qt/details/ToolsFieldBase.h"
23#include "cc_tools_qt/field/ToolsBitfieldField.h"
24
25#include <cstdint>
26#include <cassert>
27#include <memory>
28#include <vector>
29
30#include "comms/field/Bitfield.h"
31
32namespace cc_tools_qt
33{
34
35namespace details
36{
37
38template <typename TField>
39class ToolsBitfieldFieldImpl : public ToolsFieldBase<cc_tools_qt::field::ToolsBitfieldField, TField>
40{
41 using Base = ToolsFieldBase<cc_tools_qt::field::ToolsBitfieldField, TField>;
42
43 using Field = TField;
44 static_assert(comms::field::isBitfield<Field>(), "Must be of Bitfield field type");
45
46public:
47 using Ptr = typename Base::Ptr;
48 using ActPtr = typename Base::ActPtr;
49
50 explicit ToolsBitfieldFieldImpl(Field& fieldRef)
51 : Base(fieldRef)
52 {
53 }
54
55 ToolsBitfieldFieldImpl(const ToolsBitfieldFieldImpl&) = default;
56 ToolsBitfieldFieldImpl(ToolsBitfieldFieldImpl&&) = default;
57 virtual ~ToolsBitfieldFieldImpl() noexcept = default;
58
59 ToolsBitfieldFieldImpl& operator=(const ToolsBitfieldFieldImpl&) = delete;
60
61protected:
62 virtual Ptr cloneImpl() override
63 {
64 return ActPtr(new ToolsBitfieldFieldImpl<TField>(Base::field()));
65 }
66
67 virtual void membersUpdatedImpl() override
68 {
69 auto& mems = Base::getMembers();
70 for (auto& m : mems) {
71 assert(m);
72 m->forceHiddenSerialization();
73 }
74 }
75
76};
77
78template <typename TField>
79auto makeBitfieldField(TField& field)
80{
81 return std::make_unique<ToolsBitfieldFieldImpl<TField>>(field);
82}
83
84} // namespace details
85
86} // namespace cc_tools_qt
Main namespace for all classes / functions of the shared library.