diff --git a/src/solver/systemParser/encoders.hxx b/src/solver/systemParser/encoders.hxx index e53c4ff237..afcdd40421 100644 --- a/src/solver/systemParser/encoders.hxx +++ b/src/solver/systemParser/encoders.hxx @@ -29,6 +29,22 @@ namespace YAML { +/** + * @brief shortend to default construct a value when node is null + * @tparam T Type to convert the node to + * @param n node + * @return Object of type T + * It's just to simplify repertitve and verbose lines + * as_fallback_default>( +node["parameters"]) is equivalent to + node["parameters"].as>(std::vector()) + */ +template +inline T as_fallback_default(const Node& n) +{ + return n.as(T()); +} + template<> struct convert { @@ -45,4 +61,39 @@ struct convert } }; +template<> +struct convert +{ + static bool decode(const Node& node, Antares::Solver::SystemParser::Component& rhs) + { + if (!node.IsMap()) + { + return false; + } + rhs.id = node["id"].as(); + rhs.model = node["model"].as(); + rhs.scenarioGroup = node["scenario-group"].as(); + rhs.parameters = as_fallback_default>( + node["parameters"]); + return true; + } +}; + +template<> +struct convert +{ + static bool decode(const Node& node, Antares::Solver::SystemParser::System& rhs) + { + if (!node.IsMap()) + { + return false; + } + rhs.id = node["id"].as(); + rhs.libraries = as_fallback_default>(node["model-libaries"]); + rhs.components = as_fallback_default>( + node["components"]); + return true; + } +}; + } // namespace YAML