cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ToolsOptionalFieldImpl.h
1//
2// Copyright 2015 - 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/ToolsOptionalField.h"
24
25#include <memory>
26#include <cassert>
27
28namespace cc_tools_qt
29{
30
31namespace details
32{
33
34template <typename TField>
35class ToolsOptionalFieldImpl : public ToolsFieldBase<cc_tools_qt::field::ToolsOptionalField, TField>
36{
37 using Base = ToolsFieldBase<cc_tools_qt::field::ToolsOptionalField, TField>;
38public:
39
40 using Mode = typename Base::Mode;
41 using Ptr = typename Base::Ptr;
42 using ActPtr = typename Base::ActPtr;
43 using Field = TField;
44
45 explicit ToolsOptionalFieldImpl(Field& fieldRef)
46 : Base(fieldRef)
47 {
48 }
49
50protected:
51 virtual Mode getModeImpl() const override
52 {
53 return Base::field().getMode();
54 }
55
56 virtual void setModeImpl(Mode mode) override
57 {
58 Base::field().setMode(mode);
59 }
60
61 virtual Ptr cloneImpl() override
62 {
63 return ActPtr(new ToolsOptionalFieldImpl<TField>(Base::field()));
64 }
65};
66
67template <typename TField>
68auto makeOptionalField(TField& field)
69{
70 return std::make_unique<ToolsOptionalFieldImpl<TField>>(field);
71}
72
73} // namespace details
74
75} // namespace cc_tools_qt
76
Main namespace for all classes / functions of the shared library.