55template<
typename Traits>
59 static constexpr double MIN = Traits::MIN;
61 static constexpr double MAX = Traits::MAX;
78 const double physicalValue =
static_cast<double>(value);
79 const double clampedValue = std::clamp(physicalValue,
MIN,
MAX);
81 double scaled = clampedValue -
MIN;
83 scaled *= (
static_cast<double>(Traits::RAW_MAX) -
static_cast<double>(Traits::RAW_MIN));
84 scaled +=
static_cast<double>(Traits::RAW_MIN);
106 return value_ >= Traits::RAW_MIN && value_ <= Traits::RAW_MAX;
114 double scaled =
static_cast<double>(value_) -
static_cast<double>(Traits::RAW_MIN);
115 scaled /= (
static_cast<double>(Traits::RAW_MAX) -
static_cast<double>(Traits::RAW_MIN));
140 std::ostringstream oss;
141 if constexpr (std::is_integral_v<TargetType>) {
142 oss << static_cast<long long>(
getValue());
144 oss << std::fixed << std::setprecision(getPrecision()) <<
getValue();
151 return value_ == other.value_;
154 return value_ != other.value_;
157 return value_ < other.value_;
160 return value_ <= other.value_;
163 return value_ > other.value_;
166 return value_ >= other.value_;
180 static constexpr int getPrecision() noexcept {
184 while (r < 1.0 && p < 15) { r *= 10; p++; }
190 static constexpr double MIN = 0;
191 static constexpr double MAX = 4.295e7;
199 static constexpr double MIN = 0;
200 static constexpr double MAX = 655.32;
208 static constexpr double MIN = 0;
209 static constexpr double MAX = 2 * M_PI;
217 static constexpr double MIN = -M_PI;
218 static constexpr double MAX = M_PI;
226 static constexpr double MIN = 0;
227 static constexpr double MAX = 15;
235 static constexpr double MIN = 0;
236 static constexpr double MAX = 255;
244 static constexpr double MIN = -90;
245 static constexpr double MAX = 90;
253 static constexpr double MIN = -180;
254 static constexpr double MAX = 180;
262 static constexpr double MIN = -67;
263 static constexpr double MAX = 67;
271 static constexpr double MIN = -327.64;
272 static constexpr double MAX = 327.64;
Strongly typed numeric wrapper for NMEA 2000 custom data types.
constexpr bool operator!=(const DataType &other) const noexcept
typename Traits::RawType RawType
Raw external type.
constexpr bool operator>(const DataType &other) const noexcept
RawType getRaw() const noexcept
Converts physical value to raw integer representation.
constexpr bool operator>=(const DataType &other) const noexcept
static constexpr double MIN
Minimum representable value for this type.
static constexpr double RESOLUTION
Resolution (least significant physical unit step).
constexpr bool operator<=(const DataType &other) const noexcept
constexpr bool isValid() const noexcept
Checks whether the stored value is within configured bounds.
constexpr bool operator<(const DataType &other) const noexcept
static constexpr DataType fromRaw(RawType raw) noexcept
Constructs from a raw value.
static constexpr double MAX
Maximum representable value for this type.
typename Traits::TargetType TargetType
Target type for higher-level fields that expect a specific physical type.
constexpr bool operator==(const DataType &other) const noexcept
static DataType fromValue(TargetType value)
Constructs from a physical value.
constexpr TargetType getValue() const noexcept
Returns the normalized physical value.
std::string toString() const
Converts the value to a fixed-point string.
static constexpr RawType RAW_MAX
static constexpr double MIN
static constexpr double RESOLUTION
static constexpr RawType RAW_MIN
static constexpr double MAX
static constexpr double MIN
static constexpr RawType RAW_MIN
static constexpr RawType RAW_MAX
static constexpr double MAX
static constexpr double RESOLUTION
static constexpr double RESOLUTION
static constexpr double MAX
static constexpr double MIN
static constexpr RawType RAW_MIN
static constexpr RawType RAW_MAX
static constexpr double MAX
static constexpr RawType RAW_MAX
static constexpr double MIN
static constexpr double RESOLUTION
static constexpr RawType RAW_MIN
static constexpr double RESOLUTION
static constexpr RawType RAW_MAX
static constexpr double MIN
static constexpr double MAX
static constexpr RawType RAW_MIN
static constexpr RawType RAW_MIN
static constexpr RawType RAW_MAX
static constexpr double MIN
static constexpr double RESOLUTION
static constexpr double MAX
static constexpr double MAX
static constexpr RawType RAW_MIN
static constexpr double MIN
static constexpr RawType RAW_MAX
static constexpr double RESOLUTION
static constexpr RawType RAW_MIN
static constexpr double MAX
static constexpr RawType RAW_MAX
static constexpr double RESOLUTION
static constexpr double MIN
static constexpr RawType RAW_MAX
static constexpr double MIN
static constexpr double RESOLUTION
static constexpr RawType RAW_MIN
static constexpr double MAX
static constexpr double MAX
static constexpr RawType RAW_MIN
static constexpr RawType RAW_MAX
static constexpr double RESOLUTION
static constexpr double MIN