From 1bcb1e566635ef361c7161e11d788208cf7073a8 Mon Sep 17 00:00:00 2001 From: Bartek Kryza Date: Sun, 21 Feb 2021 19:36:20 +0100 Subject: [PATCH] Refactored config diagram decoder --- src/config/config.h | 62 +++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/src/config/config.h b/src/config/config.h index b1aecabe..de386634 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -134,21 +134,6 @@ using clanguml::config::plantuml; using clanguml::config::sequence_diagram; using clanguml::config::source_location; -// -// class_diagram Yaml decoder -// -template <> struct convert { - static bool decode(const Node &node, class_diagram &rhs) - { - rhs.using_namespace = - node["using_namespace"].as>(); - rhs.glob = node["glob"].as>(); - if (node["puml"]) - rhs.puml = node["plantuml"].as(); - return true; - } -}; - template <> struct convert> { static bool decode( const Node &node, std::vector &rhs) @@ -198,25 +183,52 @@ template <> struct convert { } }; +template bool decode_diagram(const Node &node, T &rhs) +{ + if (node["using_namespace"]) + rhs.using_namespace = + node["using_namespace"].as>(); + + if (node["glob"]) + rhs.glob = node["glob"].as>(); + + if (node["include"]) + rhs.include = node["include"].as(); + + if (node["exclude"]) + rhs.exclude = node["exclude"].as(); + + if (node["plantuml"]) + rhs.puml = node["plantuml"].as(); + + return true; +} + +// +// class_diagram Yaml decoder +// +template <> struct convert { + static bool decode(const Node &node, class_diagram &rhs) + { + if (!decode_diagram(node, rhs)) + return false; + + return true; + } +}; + // // sequence_diagram Yaml decoder // template <> struct convert { static bool decode(const Node &node, sequence_diagram &rhs) { - rhs.using_namespace = - node["using_namespace"].as>(); - rhs.glob = node["glob"].as>(); - rhs.puml = node["plantuml"].as(); - - if (node["include"]) - rhs.include = node["include"].as(); - - if (node["exclude"]) - rhs.exclude = node["exclude"].as(); + if (!decode_diagram(node, rhs)) + return false; if (node["start_from"]) rhs.start_from = node["start_from"].as(); + return true; } };