Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
JsonParamMappingAdapter.h
Go to the documentation of this file.
1#ifndef JSONPARAMMAPPINGADAPTER_H
2#define JSONPARAMMAPPINGADAPTER_H
3
4#include <variant>
5#include <iostream>
6
8#include "DBNode.h"
9
39public:
46 explicit JsonParamMappingAdapter(std::shared_ptr<IParser> parser)
47 : parser_(std::move(parser)) {}
48
58 std::unordered_map<std::string, InterpretedParam>
59 loadFromFile(const std::string& filePath) const override;
60
61private:
76 static std::string asString(const DBNode::Value& v) {
77 if (auto s = std::get_if<BlockName>(&v)) return *s;
78 if (auto i = std::get_if<int>(&v)) return std::to_string(*i);
79 if (auto d = std::get_if<double>(&v)) return std::to_string(*d);
80 if (auto b = std::get_if<bool>(&v)) return *b ? "true" : "false";
81 throw std::runtime_error("JSON mapping: non-scalar value cannot be converted to a string");
82 }
83
84private:
86 std::shared_ptr<IParser> parser_;
87};
88
89#endif // JSONPARAMMAPPINGADAPTER_H
Hierarchical key–value tree with JSON/YAML serialization.
Interface for loading parameter mappings from an external source.
std::variant< BlockName, int, double, bool, std::shared_ptr< DBNode >, std::vector< std::shared_ptr< DBNode > > > Value
Variant type used to store values in the tree.
Definition DBNode.h:45
Abstract source of InterpretedParam mappings.
IParamMappingSource implementation backed by a JSON-like file.
std::unordered_map< std::string, InterpretedParam > loadFromFile(const std::string &filePath) const override
Loads parameter mappings from a file.
JsonParamMappingAdapter(std::shared_ptr< IParser > parser)
Constructs the adapter with a given parser instance.
Hash specialization for SymbolId<Tag>.
Definition BlockName.h:353