16 #include <yaml-cpp/yaml.h> 17 #include <boost/filesystem.hpp> 18 #include <boost/filesystem/fstream.hpp> 37 std::initializer_list<const char *> keys) {
38 assert(keys.size() > 0);
39 for (
auto key : keys) {
41 node.reset(node[key]);
54 std::vector<std::string> to_remove(root.size());
57 if ((
n.second.IsMap() ||
n.second.IsSequence()) &&
n.second.size() == 0) {
58 to_remove.emplace_back(
n.first.Scalar());
61 for (
const auto &key : to_remove) {
75 YAML::Node
operator|=(YAML::Node a,
const YAML::Node &b) {
78 a[n0.first.Scalar()] |= n0.second;
87 namespace particles_txt {
88 #include <particles.txt.h> 90 namespace decaymodes_txt {
91 #include <decaymodes.txt.h> 103 const auto file_path = path / filename;
104 if (!bf::exists(file_path)) {
107 "', but the file does not exist.");
110 throw std::runtime_error(
111 "The configuration file has CR LF line endings. Please use LF " 115 root_node_ = YAML::LoadFile(file_path.native());
116 }
catch (YAML::ParserException &e) {
117 if (e.msg ==
"illegal map value" || e.msg ==
"end of map not found") {
118 const auto line = std::to_string(e.mark.line + 1);
119 throw ParseError(
"YAML parse error at\n" + file_path.native() +
':' +
120 line +
": " + e.msg +
121 " (check that the indentation of map keys matches)");
127 root_node_[
"decaymodes"] = decaymodes_txt::data;
130 root_node_[
"particles"] = particles_txt::data;
137 }
catch (YAML::ParserException &e) {
138 if (e.msg ==
"illegal map value" || e.msg ==
"end of map not found") {
139 const auto line = std::to_string(e.mark.line + 1);
140 throw ParseError(
"YAML parse error in:\n" + yaml +
"\nat line " + line +
142 " (check that the indentation of map keys matches)");
149 std::vector<std::string> r;
151 r.emplace_back(i.first.Scalar());
157 std::initializer_list<const char *> keys) {
158 assert(keys.size() > 0);
160 auto keyIt = begin(keys);
162 for (; i < keys.size() - 1; ++i, ++keyIt) {
167 node.reset(node[*keyIt]);
169 const auto r = node[*keyIt];
171 return {r, keys.begin()[keys.size() - 1]};
175 std::initializer_list<const char *> keys)
const {
180 std::vector<std::string> to_remove;
182 if (i.first.Scalar() != key) {
183 to_remove.push_back(i.first.Scalar());
186 for (
auto i : to_remove) {
192 std::initializer_list<const char *> keys)
const {
194 return n.IsDefined();
199 return n.IsDefined() && (!
n.IsNull());
Value read(std::initializer_list< const char *> keys) const
Additional interface for SMASH to read configuration values without removing them.
std::string unused_values_report() const
Returns a string listing the key/value pairs that have not been taken yet.
Thrown if the file does not exist.
Return type of Configuration::take that automatically determines the target type. ...
YAML::Node operator|=(YAML::Node a, const YAML::Node &b)
Merge two YAML::Nodes.
Configuration(const bf::path &path)
Reads config.yaml from the specified path.
Interface to the SMASH configuration files.
YAML::Node remove_empty_maps(YAML::Node root)
Removes all empty maps of a YAML::Node.
Thrown for YAML parse errors.
std::vector< std::string > list_upmost_nodes()
Lists all YAML::Nodes from the configuration setup.
bool has_value(std::initializer_list< const char *> keys) const
Returns whether there is a non-empty value behind the requested keys.
void merge_yaml(const std::string &yaml)
Merge the configuration in yaml into the existing tree.
void remove_all_but(const std::string &key)
Removes all entries in the map except for key.
bool has_crlf_line_ending(const std::string in)
Check if a line in the string ends with \r\n.
bool has_value_including_empty(std::initializer_list< const char *> keys) const
Returns if there is a (maybe empty) value behind the requested keys.
YAML::Node find_node_at(YAML::Node node, std::initializer_list< const char *> keys)
Finds a node, copies its structure and replaces the previous keys by the newly provided keys...
Value take(std::initializer_list< const char *> keys)
The default interface for SMASH to read configuration values.
YAML::Node root_node_
the general_config.yaml contents - fully parsed
std::string to_string() const
Returns a YAML string of the current tree.
std::string read_all(std::istream &&input)
Utility function to read a complete input stream (e.g.