cc_tools_qt
Common Environment for Protocol Analysis.
Loading...
Searching...
No Matches
ToolsNumericFieldBase.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/ToolsField.h"
23
24#include <cstddef>
25#include <type_traits>
26
27namespace cc_tools_qt
28{
29
30namespace details
31{
32
33template <typename TUnderlyingType>
34class ToolsNumericFieldBase : public ToolsField
35{
36 static_assert(std::is_integral<TUnderlyingType>::value || std::is_floating_point<TUnderlyingType>::value,
37 "Underlying type is expected to be integral or floating point.");
38 using Base = ToolsField;
39
40public:
41 using UnderlyingType = TUnderlyingType;
42 using SerialisedSeq = Base::SerialisedSeq;
43
44 ToolsNumericFieldBase() {}
45
46 virtual ~ToolsNumericFieldBase() noexcept = default;
47
48 UnderlyingType getValue() const
49 {
50 return getValueImpl();
51 }
52
53 void setValue(UnderlyingType value)
54 {
55 setValueImpl(value);
56 }
57
58 std::size_t minLength() const
59 {
60 return minLengthImpl();
61 }
62
63 std::size_t maxLength() const
64 {
65 return maxLengthImpl();
66 }
67
68 int minWidth() const
69 {
70 return static_cast<int>(minLength()) * 2;
71 }
72
73 int maxWidth() const
74 {
75 return static_cast<int>(maxLength()) * 2;
76 }
77
78private:
79 virtual UnderlyingType getValueImpl() const = 0;
80 virtual void setValueImpl(UnderlyingType value) = 0;
81 virtual std::size_t minLengthImpl() const = 0;
82 virtual std::size_t maxLengthImpl() const = 0;
83};
84
85} // namespace details
86
87} // namespace cc_tools_qt
Main namespace for all classes / functions of the shared library.