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