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
19#pragma once
20
21#include "cc_tools_qt/ToolsField.h"
22
23#include <cstddef>
24#include <type_traits>
25
26namespace cc_tools_qt
27{
28
29namespace details
30{
31
32template <typename TUnderlyingType>
33class ToolsNumericFieldBase : public ToolsField
34{
35 static_assert(std::is_integral<TUnderlyingType>::value || std::is_floating_point<TUnderlyingType>::value,
36 "Underlying type is expected to be integral or floating point.");
37 using Base = ToolsField;
38
39public:
40 using UnderlyingType = TUnderlyingType;
41 using SerialisedSeq = Base::SerialisedSeq;
42
43 ToolsNumericFieldBase() {}
44
45 virtual ~ToolsNumericFieldBase() noexcept = default;
46
47 UnderlyingType getValue() const
48 {
49 return getValueImpl();
50 }
51
52 void setValue(UnderlyingType value)
53 {
54 setValueImpl(value);
55 }
56
57 std::size_t minLength() const
58 {
59 return minLengthImpl();
60 }
61
62 std::size_t maxLength() const
63 {
64 return maxLengthImpl();
65 }
66
67 int minWidth() const
68 {
69 return static_cast<int>(minLength()) * 2;
70 }
71
72 int maxWidth() const
73 {
74 return static_cast<int>(maxLength()) * 2;
75 }
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.