|
dimval 0.2.0
Modern C++23 header-only library of dimensional values (units, measures, ranges)
|
Macros that expand into a CRTP unit/measure struct and a runtime auto-registration for it. More...
#include <dimval/base.hpp>#include <dimval/measure.hpp>#include <dimval/registry.hpp>#include <dimval/unit.hpp>#include <commons/color.hpp>#include <commons/icon.hpp>#include <commons/icons.hpp>#include <optional>

Go to the source code of this file.
Macros | |
| #define | DIMVAL_DEFINE_UNIT(Tag, Id, Symbol, ShortName, LongName, Kind, Factor, Icon, Color, ...) |
| Define a unit struct in ::dimval and auto-register its descriptor at static-init time. | |
| #define | DIMVAL_DEFINE_MEASURE(Tag, BaseUnit, Id, Name, Icon, Color, ...) |
| Define a measure struct in ::dimval and auto-register its descriptor. | |
Macros that expand into a CRTP unit/measure struct and a runtime auto-registration for it.
Each unit/measure is its own struct that derives from UnitBase / MeasureBase and publishes its metadata as static constexpr members. The macro arguments fill in those members; optional fields fall through to the defaults declared on UnitBase / MeasureBase unless overridden via VA_ARGS.
The Icon argument is a comms::Icon — prefer a catalog constant such as comms::Icons::mdi::movie_roll (from <commons/icons.hpp>), or build one from any Iconify set with the compile-time validated comms::Icon::from("set:name"). The Color argument is a comms::Color — use a Material UI shade such as comms::Colors::mui::blue[400]. Passing ::std::nullopt for either means "unset / inherit".
Usage from outside the library (custom user units):
Optional fields (offset, formatter, default_precision, no_space_before_symbol) can be supplied as additional macro arguments after the required ones — each one is a static constexpr member declaration that shadows the inherited default:
All macros open namespace dimval internally. The structs they produce therefore live in ::dimval.
| #define DIMVAL_DEFINE_MEASURE | ( | Tag, | |
| BaseUnit, | |||
| Id, | |||
| Name, | |||
| Icon, | |||
| Color, | |||
| ... | |||
| ) |
Define a measure struct in ::dimval and auto-register its descriptor.
BaseUnit is the underlying unit type (must be UnitLike). Icon (a comms::Icon) and Color (a comms::Color) shadow the unit's defaults; pass ::std::nullopt to inherit from the base unit. __VA_ARGS__ is an optional list of static constexpr member declarations that shadow the defaults declared on MeasureBase (e.g. default_precision, formatter).
| #define DIMVAL_DEFINE_UNIT | ( | Tag, | |
| Id, | |||
| Symbol, | |||
| ShortName, | |||
| LongName, | |||
| Kind, | |||
| Factor, | |||
| Icon, | |||
| Color, | |||
| ... | |||
| ) |
Define a unit struct in ::dimval and auto-register its descriptor at static-init time.
Tag is the unqualified identifier (also used to name the auto-registrar). Id, Symbol, ShortName, LongName, Kind are string literals; Factor is a double; Icon is a comms::Icon (e.g. a ::comms::Icons::mdi::* catalog constant) and Color is a comms::Color (e.g. ::comms::Colors::mui::blue[400]) — pass ::std::nullopt to leave unset. __VA_ARGS__ is an optional list of static constexpr member declarations that shadow the defaults declared on UnitBase.