3#include <pulp/format/detail/locale_independent_float.hpp>
21 return info.to_string(value);
27 if (!info.value_labels.empty()) {
28 const float step = info.range.step > 0.0f ? info.range.step : 1.0f;
29 const auto raw = std::llround((value - info.range.min) / step);
30 const auto index =
static_cast<std::size_t
>(std::clamp<int64_t>(
31 raw, 0,
static_cast<int64_t
>(info.value_labels.size() - 1)));
32 return info.value_labels[index];
37 const auto converted = std::to_chars(number, number +
sizeof(number), value,
38 std::chars_format::fixed, precision);
39 if (converted.ec != std::errc{})
return {};
40 std::string result(number, converted.ptr);
41 if (!info.unit.empty()) {
53 std::string_view text) {
54 if (info.from_string) {
56 const float parsed = info.from_string(std::string(text));
65 !info.value_labels.empty())
69 const auto result = detail::parse_double_c_locale(text, parsed);
70 if (result.consumed == 0 || result.range_error || !std::isfinite(parsed))
73 auto suffix = text.substr(result.consumed);
74 while (!suffix.empty() && std::isspace(
static_cast<unsigned char>(suffix.front())))
75 suffix.remove_prefix(1);
76 while (!suffix.empty() && std::isspace(
static_cast<unsigned char>(suffix.back())))
77 suffix.remove_suffix(1);
78 if (!suffix.empty() && suffix != info.unit)
return std::nullopt;
Portable try/catch macros for source that must also compile with C++ exceptions disabled (-fno-except...
#define PULP_TRY
Definition exceptions.hpp:42
#define PULP_CATCH_ALL
Definition exceptions.hpp:43
@ Continuous
Definition parameter.hpp:74
@ Toggle
Definition parameter.hpp:76
@ Enum
Definition parameter.hpp:77
float constrain_param_value(const ParamInfo &info, float value)
Definition parameter.hpp:475
std::optional< float > param_value_for_label(const ParamInfo &info, std::string_view text)
Definition parameter.hpp:488
Immutable parameter metadata, registered once at plugin initialization.
Definition parameter.hpp:316