From f440fac550f9dcfea6644c81ad35e65b5401d0b1 Mon Sep 17 00:00:00 2001 From: Vincent Payet Date: Wed, 11 Dec 2024 11:49:59 +0100 Subject: [PATCH] encoder ok --- src/solver/systemParser/encoders.hxx | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) 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