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

Show on the map →

Called by extract_scalar_fields

Calls to_string

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
lines 307–307bool matched = false;lines 308–308◇ if (node.is_map() && node.has_child(key))lines 309–309auto child = node[key];lines 310–310◇ if (child.is_map() && child.has_child("content"))lines 311–311auto content = child["content"];lines 312–312◇ if (content.has_val())lines 313–313out = to_string(content.val());lines 314–314matched = true;lines 318–318return matched;

Requirements

REQ-TYPE-005

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

Show on the map →

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
lines 359–359◇ if (!node.is_map() || !node.has_child(key))lines 360–360return false;lines 362–362auto child = node[key];lines 363–363◇ if (!child.is_seq())lines 364–364bool is_null = !child.has_val() || child.val_is_null();lines 365–365out = is_null ? std::nullopt : out;lines 366–366return is_null;lines 368–368std::vector<std::string> vec;lines 369–369◇ for (auto item : child)lines 370–370vec.push_back(to_string(item.val()));lines 372–372out = std::move(vec);lines 373–373return true;

Requirements

REQ-TYPE-005

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

Show on the map →

Called by extract_scalar_fields, parse_tier_config

Calls expand_home, to_string

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;
}
Activity · 9 steps
lines 274–274◇ if (!node.is_map() || !node.has_child(key))lines 275–275return false;lines 277–277auto child = node[key];lines 278–278bool is_null = !child.has_val() || child.val_is_null();lines 279–279auto val = is_null ? std::string{} : to_string(child.val());lines 280–280bool is_false = (val == "false" || val == "False" || val == "FALSE");lines 282–282disabled = is_false;lines 283–285out = (is_null || is_false) ? std::nullopt : std::optional{expand_home(std::filesystem::path(val))};lines 286–286return true;

Requirements

REQ-TYPE-005