dimval 0.2.0
Modern C++23 header-only library of dimensional values (units, measures, ranges)
Loading...
Searching...
No Matches
descriptor.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <commons/color.hpp>
7#include <commons/icon.hpp>
8
9#include <optional>
10#include <string_view>
11
12namespace dimval {
13
14namespace detail {
19using icon_field_t = std::optional<comms::Icon>;
20using color_field_t = std::optional<comms::Color>;
21} // namespace detail
22
30 std::string_view id;
31 std::string_view symbol;
32 std::string_view short_name;
33 std::string_view long_name;
34 std::string_view
36 double factor{1.0};
37 double offset{0.0};
38 std::string_view formatter{"default"};
41 // The {} default member initializers silence -Wmissing-designated-field-initializers
42 // at aggregate-init sites that omit these optional fields; the NOLINT suppresses the
43 // resulting redundant-member-init tidy warning (same trade-off as `formatter` below).
44 std::optional<comms::Icon> icon{};
46 std::optional<comms::Color> color{};
48
49 [[nodiscard]] friend constexpr bool operator==(const UnitDescriptor&,
50 const UnitDescriptor&) noexcept = default;
51};
52
55 std::string_view id;
56 std::string_view base_unit_id;
57 std::string_view name;
58 std::string_view formatter{};
61 std::optional<comms::Icon>
62 icon{};
64 std::optional<comms::Color>
67
68 [[nodiscard]] friend constexpr bool operator==(const MeasureDescriptor&,
69 const MeasureDescriptor&) noexcept = default;
70};
71
72} // namespace dimval
std::optional< comms::Icon > icon_field_t
Field types for the optional UI metadata.
Definition descriptor.hpp:19
Runtime metadata for a measure (a semantic specialization of a unit).
Definition descriptor.hpp:54
std::string_view id
Stable identifier (e.g. "distance"). Unique per registry.
Definition descriptor.hpp:55
std::string_view formatter
NOLINT(readability-redundant-member-init) Empty falls back to the base unit's formatter.
Definition descriptor.hpp:58
std::string_view name
Human-readable name (e.g. "Distance").
Definition descriptor.hpp:57
std::optional< comms::Color > color
NOLINT(readability-redundant-member-init) Optional UI accent; nullopt falls back to the unit's color.
Definition descriptor.hpp:65
std::string_view base_unit_id
Id of the unit this measure is defined in (e.g. "m").
Definition descriptor.hpp:56
std::optional< comms::Icon > icon
NOLINT(readability-redundant-member-init) Optional UI icon; nullopt falls back to the unit's icon.
Definition descriptor.hpp:62
int default_precision
Empty falls back to the base unit's precision.
Definition descriptor.hpp:60
Runtime metadata for a unit.
Definition descriptor.hpp:29
std::optional< comms::Icon > icon
NOLINT(readability-redundant-member-init) Optional UI icon (Iconify set:name); nullopt = unset.
Definition descriptor.hpp:44
double offset
Additive offset for affine conversions (e.g. Celsius/Kelvin).
Definition descriptor.hpp:37
std::string_view formatter
Formatter id; consumed by std::formatter.
Definition descriptor.hpp:38
std::string_view short_name
Short human-readable name (e.g. "m").
Definition descriptor.hpp:32
int default_precision
Default numeric precision; -1 = unset.
Definition descriptor.hpp:39
std::string_view symbol
Display symbol (e.g. "m"). Often equal to id.
Definition descriptor.hpp:31
std::string_view kind
Compatibility group (e.g. "length"). Two units convert if kinds match.
Definition descriptor.hpp:35
std::optional< comms::Color > color
NOLINT(readability-redundant-member-init) Optional UI accent (RGBA); nullopt = unset.
Definition descriptor.hpp:46
double factor
Linear conversion: canonical = factor * v + offset.
Definition descriptor.hpp:36
bool no_space_before_symbol
Render flush, e.g. "100%" instead of "100 %".
Definition descriptor.hpp:40
std::string_view long_name
Full human-readable name (e.g. "meter").
Definition descriptor.hpp:33
std::string_view id
Stable identifier (e.g. "m"). Unique per registry.
Definition descriptor.hpp:30