dimval 0.2.0
Modern C++23 header-only library of dimensional values (units, measures, ranges)
Loading...
Searching...
No Matches
parse.hpp File Reference

Parse string literals like "42.5 m" into UnitValue / MeasureValue. More...

#include <dimval/core.hpp>
#include <dimval/measure.hpp>
#include <dimval/parse_detail.hpp>
#include <dimval/registry.hpp>
#include <dimval/traits.hpp>
#include <dimval/unit.hpp>
#include <expected>
#include <string>
#include <string_view>
Include dependency graph for parse.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  dimval::DynamicUnitValue
 Type-erased dynamic parse result. More...
 

Functions

template<UnitLike U, NumericValue T = double>
std::expected< UnitValue< U, T >, ParseErrordimval::parse_unit_value (std::string_view input)
 Parse a string of the form "42.5 m" into a UnitValue<U,T>.
 
template<MeasureLike M, NumericValue T = double>
std::expected< MeasureValue< M, T >, ParseErrordimval::parse_measure_value (std::string_view input)
 Parse a string of the form "42.5 m" into a MeasureValue<M,T>.
 
std::expected< DynamicUnitValue, ParseErrordimval::parse_dynamic_unit_value (std::string_view input)
 Parse a string of the form "42.5 m" against the runtime registry.
 

Detailed Description

Parse string literals like "42.5 m" into UnitValue / MeasureValue.

Function Documentation

◆ parse_dynamic_unit_value()

std::expected< DynamicUnitValue, ParseError > dimval::parse_dynamic_unit_value ( std::string_view  input)
inline

Parse a string of the form "42.5 m" against the runtime registry.

Returns a (descriptor*, value) pair. Useful when the target unit isn't known at compile time (e.g. parsing config files with arbitrary user units).

◆ parse_measure_value()

template<MeasureLike M, NumericValue T = double>
std::expected< MeasureValue< M, T >, ParseError > dimval::parse_measure_value ( std::string_view  input)

Parse a string of the form "42.5 m" into a MeasureValue<M,T>.

Thin forward to MeasureValue<M,T>::parse.

◆ parse_unit_value()

template<UnitLike U, NumericValue T = double>
std::expected< UnitValue< U, T >, ParseError > dimval::parse_unit_value ( std::string_view  input)

Parse a string of the form "42.5 m" into a UnitValue<U,T>.

Thin forward to UnitValue<U,T>::parse so this free-function form stays available.