dimval 0.2.0
Modern C++23 header-only library of dimensional values (units, measures, ranges)
Loading...
Searching...
No Matches
define.hpp
Go to the documentation of this file.
1#pragma once
2
49
50#include <dimval/base.hpp>
51#include <dimval/measure.hpp>
52#include <dimval/registry.hpp>
53#include <dimval/unit.hpp>
54
55#include <commons/color.hpp>
56#include <commons/icon.hpp>
57#include <commons/icons.hpp>
58
59#include <optional>
60
61#define DIMVAL_DETAIL_CAT2(a, b) a##b
62#define DIMVAL_DETAIL_CAT(a, b) DIMVAL_DETAIL_CAT2(a, b)
63
72#define DIMVAL_DEFINE_UNIT(Tag, Id, Symbol, ShortName, LongName, Kind, Factor, Icon, Color, ...) \
73 namespace dimval { \
74 struct Tag : ::dimval::UnitBase<Tag> { \
75 static constexpr ::std::string_view id = Id; \
76 static constexpr ::std::string_view symbol = Symbol; \
77 static constexpr ::std::string_view short_name = ShortName; \
78 static constexpr ::std::string_view long_name = LongName; \
79 static constexpr ::std::string_view kind = Kind; \
80 static constexpr double factor = Factor; \
81 static constexpr ::dimval::detail::icon_field_t icon = Icon; \
82 static constexpr ::dimval::detail::color_field_t color = Color; \
83 __VA_ARGS__ \
84 }; \
85 using DIMVAL_DETAIL_CAT(Tag, Value) = ::dimval::UnitValue<Tag>; \
86 using DIMVAL_DETAIL_CAT(Tag, ValueUnique) = ::std::unique_ptr<DIMVAL_DETAIL_CAT(Tag, Value)>; \
87 using DIMVAL_DETAIL_CAT(Tag, ValueShared) = ::std::shared_ptr<DIMVAL_DETAIL_CAT(Tag, Value)>; \
88 using DIMVAL_DETAIL_CAT(Tag, RangeValue) = ::dimval::UnitRangeValue<Tag>; \
89 } \
90 namespace dimval::detail { \
91 [[maybe_unused]] inline const int DIMVAL_DETAIL_CAT(_dimval_unit_reg_, Tag) = \
92 ::dimval::detail::register_unit_tag<::dimval::Tag>(); \
93 }
94
102#define DIMVAL_DEFINE_MEASURE(Tag, BaseUnit, Id, Name, Icon, Color, ...) \
103 namespace dimval { \
104 struct Tag : ::dimval::MeasureBase<Tag, BaseUnit> { \
105 static constexpr ::std::string_view id = Id; \
106 static constexpr ::std::string_view name = Name; \
107 static constexpr ::dimval::detail::icon_field_t icon = Icon; \
108 static constexpr ::dimval::detail::color_field_t color = Color; \
109 __VA_ARGS__ \
110 }; \
111 using DIMVAL_DETAIL_CAT(Tag, Value) = ::dimval::MeasureValue<Tag>; \
112 using DIMVAL_DETAIL_CAT(Tag, ValueUnique) = ::std::unique_ptr<DIMVAL_DETAIL_CAT(Tag, Value)>; \
113 using DIMVAL_DETAIL_CAT(Tag, ValueShared) = ::std::shared_ptr<DIMVAL_DETAIL_CAT(Tag, Value)>; \
114 using DIMVAL_DETAIL_CAT(Tag, RangeValue) = ::dimval::MeasureRangeValue<Tag>; \
115 } \
116 namespace dimval::detail { \
117 [[maybe_unused]] inline const int DIMVAL_DETAIL_CAT(_dimval_measure_reg_, Tag) = \
118 ::dimval::detail::register_measure_tag<::dimval::Tag>(); \
119 }
CRTP bases that turn unit/measure tag structs into self-describing types.
MeasureValue<M,T>: a UnitValue tagged with an additional semantic measure.
Thread-safe runtime registries of unit and measure descriptors.
UnitValue<U,T>: a strongly-typed value carrying a compile-time unit tag.