WE Core
Loading...
Searching...
No Matches
ParameterDefinition.h
Go to the documentation of this file.
1/*
2 * File: ParameterDefinition.h
3 *
4 * Created: 22/09/2016
5 *
6 * This file is part of WECore.
7 *
8 * WECore is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * WECore is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with WECore. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <unordered_map>
25#include <string>
26
45 template <class T>
46 T BoundsCheck(T val, T min, T max) {
47 if (val < min) val = min;
48 if (val > max) val = max;
49
50 return val;
51 }
52
54 public:
55 BooleanParameter(bool newDefaultValue) : defaultValue(newDefaultValue) {}
56
58 };
59
63 template <class T>
65 public:
66
67 const T minValue;
68 const T maxValue;
69 const T defaultValue;
70
71 BaseParameter() = delete;
72 virtual ~BaseParameter() = default;
73
74 BaseParameter(T newMinValue,
75 T newMaxValue,
76 T newDefaultValue) : minValue(newMinValue),
77 maxValue(newMaxValue),
78 defaultValue(newDefaultValue) {}
79
90 T BoundsCheck(T val) const {
92 }
93 };
94
100 template <class T>
102 public:
103
104 // Inherit the constructor
106
115 T NormalisedToInternal(T val) const {
116 return val * (this->maxValue - this->minValue) + this->minValue;
117 }
118
127 T InternalToNormalised(T val) const {
128 return (val - this->minValue) / (this->maxValue - this->minValue);
129 }
130 };
131}
BaseParameter(T newMinValue, T newMaxValue, T newDefaultValue)
T BoundsCheck(T val, T min, T max)