yaml_util.cpp¶
src/config/yaml_util.cpp
@file yaml_util.cpp @brief ryml extraction helper implementations.
Owners: @tvanfossen
extract_inline_content
bool entropic::config::extract_inline_content(ryml::ConstNodeRef node, c4::csubstr key, std::optional< std::string > &out)
Extract inline text from an object-form value (gh#141).
src/config/yaml_util.cpp:304
Source · 16 lines
bool extract_inline_content(
ryml::ConstNodeRef node, c4::csubstr key, std::optional<std::string>& out)
{
bool matched = false;
if (node.is_map() && node.has_child(key)) {
auto child = node[key];
if (child.is_map() && child.has_child("content")) {
auto content = child["content"];
if (content.has_val()) {
out = to_string(content.val());
matched = true;
}
}
}
return matched;
}Activity · 9 steps
Requirements
extract_string_list_opt
bool entropic::config::extract_string_list_opt(ryml::ConstNodeRef node, c4::csubstr key, std::optional< std::vector< std::string > > &out)
Extract an optional vector of strings.
src/config/yaml_util.cpp:356
Called by extract_identity_fields, extract_phases, parse_model_config
Calls to_string
Source · 19 lines
bool extract_string_list_opt(ryml::ConstNodeRef node, c4::csubstr key,
std::optional<std::vector<std::string>>& out)
{
if (!node.is_map() || !node.has_child(key)) {
return false;
}
auto child = node[key];
if (!child.is_seq()) {
bool is_null = !child.has_val() || child.val_is_null();
out = is_null ? std::nullopt : out;
return is_null;
}
std::vector<std::string> vec;
for (auto item : child) {
vec.push_back(to_string(item.val()));
}
out = std::move(vec);
return true;
}Activity · 12 steps
Requirements
extract_tri_state_path
bool entropic::config::extract_tri_state_path(ryml::ConstNodeRef node, c4::csubstr key, std::optional< std::filesystem::path > &out, bool &disabled)
Extract a tri-state path (null = default, false = disabled, string = path).
src/config/yaml_util.cpp:270
Source · 18 lines
bool extract_tri_state_path(
ryml::ConstNodeRef node, c4::csubstr key,
std::optional<std::filesystem::path>& out, bool& disabled)
{
if (!node.is_map() || !node.has_child(key)) {
return false;
}
auto child = node[key];
bool is_null = !child.has_val() || child.val_is_null();
auto val = is_null ? std::string{} : to_string(child.val());
bool is_false = (val == "false" || val == "False" || val == "FALSE");
disabled = is_false;
out = (is_null || is_false)
? std::nullopt
: std::optional{expand_home(std::filesystem::path(val))};
return true;
}