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