11#include " common.hpp"
2+ #include " fluxgraph/graph/param_utils.hpp"
23#include < algorithm>
34#include < cctype>
45#include < cmath>
56#include < stdexcept>
67
78namespace fluxgraph ::compiler_internal {
89
9- namespace {
10-
11- std::string variant_type_name (const Variant &value) {
12- if (std::holds_alternative<double >(value)) {
13- return " double" ;
14- }
15- if (std::holds_alternative<int64_t >(value)) {
16- return " int64" ;
17- }
18- if (std::holds_alternative<bool >(value)) {
19- return " bool" ;
20- }
21- return " string" ;
22- }
23-
24- } // namespace
25-
26- const Variant &require_param (const std::map<std::string, Variant> ¶ms,
27- const std::string &name,
28- const std::string &context) {
10+ const ParamValue &require_param (const ParamMap ¶ms, const std::string &name,
11+ const std::string &context) {
2912 auto it = params.find (name);
3013 if (it == params.end ()) {
3114 throw std::runtime_error (" Missing required parameter at " + context + " /" +
@@ -34,31 +17,16 @@ const Variant &require_param(const std::map<std::string, Variant> ¶ms,
3417 return it->second ;
3518}
3619
37- double as_double (const Variant &value, const std::string &path) {
38- if (std::holds_alternative<double >(value)) {
39- return std::get<double >(value);
40- }
41- if (std::holds_alternative<int64_t >(value)) {
42- return static_cast <double >(std::get<int64_t >(value));
43- }
44- throw std::runtime_error (" Type error at " + path + " : expected number, got " +
45- variant_type_name (value));
20+ double as_double (const ParamValue &value, const std::string &path) {
21+ return param::as_double (value, path);
4622}
4723
48- int64_t as_int64 (const Variant &value, const std::string &path) {
49- if (std::holds_alternative<int64_t >(value)) {
50- return std::get<int64_t >(value);
51- }
52- throw std::runtime_error (" Type error at " + path + " : expected int64, got " +
53- variant_type_name (value));
24+ int64_t as_int64 (const ParamValue &value, const std::string &path) {
25+ return param::as_int64 (value, path);
5426}
5527
56- std::string as_string (const Variant &value, const std::string &path) {
57- if (std::holds_alternative<std::string>(value)) {
58- return std::get<std::string>(value);
59- }
60- throw std::runtime_error (" Type error at " + path + " : expected string, got " +
61- variant_type_name (value));
28+ std::string as_string (const ParamValue &value, const std::string &path) {
29+ return param::as_string (value, path);
6230}
6331
6432void require_finite (const double value, const std::string &path) {
0 commit comments