diff --git a/src/config/config.cc b/src/config/config.cc index 778aba9d..548e2290 100644 --- a/src/config/config.cc +++ b/src/config/config.cc @@ -91,6 +91,7 @@ void inheritable_diagram_options::inherit( exclude.override(parent.exclude); puml.override(parent.puml); generate_method_arguments.override(parent.generate_method_arguments); + generate_links.override(parent.generate_links); } bool diagram::should_include_entities(const std::string &ent) @@ -268,6 +269,7 @@ using clanguml::common::model::scope_t; using clanguml::config::class_diagram; using clanguml::config::config; using clanguml::config::filter; +using clanguml::config::generate_links_config; using clanguml::config::hint_t; using clanguml::config::layout_hint; using clanguml::config::method_arguments; @@ -439,6 +441,19 @@ template <> struct convert { } }; +// +// generate_links_config Yaml decoder +// +template <> struct convert { + static bool decode(const Node &node, generate_links_config &rhs) + { + if (node["prefix"]) + rhs.prefix = node["prefix"].as(); + + return true; + } +}; + template bool decode_diagram(const Node &node, T &rhs) { get_option(node, rhs.glob); @@ -464,6 +479,7 @@ template <> struct convert { get_option(node, rhs.include_relations_also_as_members); get_option(node, rhs.generate_method_arguments); get_option(node, rhs.generate_packages); + get_option(node, rhs.generate_links); return true; } @@ -479,6 +495,7 @@ template <> struct convert { return false; get_option(node, rhs.start_from); + get_option(node, rhs.generate_links); return true; } @@ -494,6 +511,7 @@ template <> struct convert { return false; get_option(node, rhs.layout); + get_option(node, rhs.generate_links); return true; } @@ -545,6 +563,7 @@ template <> struct convert { get_option(node, rhs.puml); get_option(node, rhs.generate_method_arguments); get_option(node, rhs.generate_packages); + get_option(node, rhs.generate_links); auto diagrams = node["diagrams"]; diff --git a/src/config/config.h b/src/config/config.h index 632b53a3..97493f3b 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -74,6 +74,10 @@ struct layout_hint { using layout_hints = std::map>; +struct generate_links_config { + std::string prefix; +}; + std::string to_string(const diagram_type t); std::string to_string(const hint_t t); @@ -88,6 +92,7 @@ struct inheritable_diagram_options { option generate_method_arguments{ "generate_method_arguments", method_arguments::full}; option generate_packages{"generate_packages", false}; + option generate_links{"generate_links"}; void inherit(const inheritable_diagram_options &parent); }; @@ -97,8 +102,6 @@ struct diagram : public inheritable_diagram_options { virtual diagram_type type() const = 0; - std::string name; - bool should_include_entities(const std::string &ent); bool should_include_relationship(const std::string &rel); @@ -119,6 +122,7 @@ struct diagram : public inheritable_diagram_options { bool should_include(const common::model::namespace_ &path) const; + std::string name; private: }; diff --git a/src/config/option.h b/src/config/option.h index 7d27efe1..e106cdae 100644 --- a/src/config/option.h +++ b/src/config/option.h @@ -35,6 +35,7 @@ template struct option { option_inherit_mode im = option_inherit_mode::override) : name{name_} , value{initial_value} + , has_value{true} { } @@ -42,6 +43,7 @@ template struct option { { value = v; is_declared = true; + has_value = true; } void override(const option &o) @@ -53,6 +55,7 @@ template struct option { value = o.value; is_declared = true; + has_value = true; } } @@ -62,9 +65,12 @@ template struct option { const T &operator()() const { return value; } + operator bool() const { return has_value; } + std::string name; T value; bool is_declared{false}; + bool has_value{false}; option_inherit_mode inheritance_mode; }; } diff --git a/tests/test_config.cc b/tests/test_config.cc index cc11a991..7ccc53d4 100644 --- a/tests/test_config.cc +++ b/tests/test_config.cc @@ -34,6 +34,9 @@ TEST_CASE("Test config simple", "[unit-test]") CHECK(diagram.generate_method_arguments() == clanguml::config::method_arguments::full); CHECK(diagram.generate_packages() == true); + CHECK(diagram.generate_links == true); + CHECK(diagram.generate_links().prefix == + "https://github.com/bkryza/clang-uml/blob/master/"); } TEST_CASE("Test config inherited", "[unit-test]") @@ -48,6 +51,7 @@ TEST_CASE("Test config inherited", "[unit-test]") CHECK(def.glob()[1] == "src/**/*.h"); CHECK(clanguml::util::contains(def.using_namespace(), "clanguml")); CHECK(def.generate_packages() == false); + CHECK(def.generate_links == false); auto &cus = *cfg.diagrams["class_custom"]; CHECK(cus.type() == clanguml::config::diagram_type::class_diagram); @@ -55,7 +59,8 @@ TEST_CASE("Test config inherited", "[unit-test]") CHECK(cus.glob()[0] == "src/main.cc"); CHECK(cus.using_namespace().starts_with({"clanguml::ns1"})); CHECK(cus.include_relations_also_as_members()); - CHECK(def.generate_packages() == false); + CHECK(cus.generate_packages() == false); + CHECK(cus.generate_links == false); } TEST_CASE("Test config includes", "[unit-test]") diff --git a/tests/test_config_data/simple.yml b/tests/test_config_data/simple.yml index 698cd3e8..43d4c5e6 100644 --- a/tests/test_config_data/simple.yml +++ b/tests/test_config_data/simple.yml @@ -9,6 +9,8 @@ diagrams: using_namespace: clanguml generate_method_arguments: full generate_packages: true + generate_links: + prefix: https://github.com/bkryza/clang-uml/blob/master/ include: namespaces: - clanguml