diff --git a/.clang-format b/.clang-format index 7ac8aac9..f992c954 100644 --- a/.clang-format +++ b/.clang-format @@ -3,7 +3,6 @@ BasedOnStyle: WebKit BreakConstructorInitializersBeforeComma: true ColumnLimit: 80 Cpp11BracedListStyle: true -IndentCaseLabels: true NamespaceIndentation: None PointerBindsToType: false Standard: Cpp11 diff --git a/src/config/config.cc b/src/config/config.cc index e331e08c..72a8b2f9 100644 --- a/src/config/config.cc +++ b/src/config/config.cc @@ -67,25 +67,14 @@ void plantuml::append(const plantuml &r) void inheritable_diagram_options::inherit( const inheritable_diagram_options &parent) { - if (!glob.has_value && parent.glob.has_value) - glob.append(parent.glob()); - - if (!using_namespace.has_value && parent.using_namespace.has_value) - using_namespace.append(parent.using_namespace()); - - if (!include_relations_also_as_members.has_value && - parent.include_relations_also_as_members.has_value) - include_relations_also_as_members.append( - parent.include_relations_also_as_members()); - - if (!include.has_value && parent.include.has_value) - include.append(parent.include()); - - if (!exclude.has_value && parent.exclude.has_value) - exclude.append(parent.exclude()); - - if (!puml.has_value && parent.puml.has_value) - puml.append(parent.puml()); + glob.override(parent.glob); + using_namespace.override(parent.using_namespace); + include_relations_also_as_members.override( + parent.include_relations_also_as_members); + include.override(parent.include); + exclude.override(parent.exclude); + puml.override(parent.puml); + generate_method_arguments.override(parent.generate_method_arguments); } bool diagram::should_include_entities(const std::string &ent) @@ -202,6 +191,7 @@ void append_value>( { l.insert(l.end(), r.begin(), r.end()); } + template <> void append_value(plantuml &l, const plantuml &r) { l.append(r); @@ -214,6 +204,7 @@ using clanguml::common::model::scope_t; using clanguml::config::class_diagram; using clanguml::config::config; using clanguml::config::filter; +using clanguml::config::method_arguments; using clanguml::config::package_diagram; using clanguml::config::plantuml; using clanguml::config::sequence_diagram; @@ -232,7 +223,25 @@ template void get_option(const Node &node, clanguml::config::option &option) { if (node[option.name]) - option.append(node[option.name].template as()); + option.set(node[option.name].template as()); +} + +template <> +void get_option( + const Node &node, clanguml::config::option &option) +{ + if (node[option.name]) { + const auto &val = node[option.name].as(); + if (val == "full") + option.set(method_arguments::full); + else if (val == "abbreviated") + option.set(method_arguments::abbreviated); + else if (val == "none") + option.set(method_arguments::none); + else + throw std::runtime_error( + "Invalid generate_method_arguments value: " + val); + } } std::shared_ptr parse_diagram_config(const Node &d) @@ -367,6 +376,7 @@ template <> struct convert { get_option(node, rhs.classes); get_option(node, rhs.include_relations_also_as_members); + get_option(node, rhs.generate_method_arguments); return true; } @@ -413,6 +423,7 @@ template <> struct convert { get_option(node, rhs.compilation_database_dir); get_option(node, rhs.include_relations_also_as_members); get_option(node, rhs.puml); + get_option(node, rhs.generate_method_arguments); auto diagrams = node["diagrams"]; diff --git a/src/config/config.h b/src/config/config.h index 42acb1d5..b4358b3a 100644 --- a/src/config/config.h +++ b/src/config/config.h @@ -34,6 +34,9 @@ namespace clanguml { namespace config { +enum class diagram_type { class_diagram, sequence_diagram, package_diagram }; +enum class method_arguments { full, abbreviated, none }; + struct plantuml { std::vector before; std::vector after; @@ -61,35 +64,42 @@ struct filter { std::vector scopes; }; -enum class diagram_type { class_diagram, sequence_diagram, package_diagram }; - std::string to_string(const diagram_type t); template void append_value(T &l, const T &r) { l = r; } +enum class option_inherit_mode { override, append }; + template struct option { - option(const std::string &name_) + option(const std::string &name_, + option_inherit_mode im = option_inherit_mode::override) : name{name_} + , value{{}} { } - option(const std::string &name_, const T &initial_value) + option(const std::string &name_, const T &initial_value, + option_inherit_mode im = option_inherit_mode::override) : name{name_} , value{initial_value} - , has_value{true} { } - void append(const T &r) + void set(const T &v) { - append_value(value, r); - has_value = true; + value = v; + is_declared = true; } - option &operator+=(const T &r) + void override(const option &o) { - append_value(value, r); - has_value = true; - return *this; + if (!is_declared && o.is_declared) { + if (inheritance_mode == option_inherit_mode::append) + append_value(value, o.value); + else + value = o.value; + + is_declared = true; + } } T &operator()() { return value; } @@ -98,7 +108,8 @@ template struct option { std::string name; T value; - bool has_value{false}; + bool is_declared{false}; + option_inherit_mode inheritance_mode; }; struct inheritable_diagram_options { @@ -108,7 +119,9 @@ struct inheritable_diagram_options { "include_relations_also_as_members", true}; option include{"include"}; option exclude{"exclude"}; - option puml{"plantuml"}; + option puml{"plantuml", option_inherit_mode::append}; + option generate_method_arguments{ + "generate_method_arguments", method_arguments::full}; void inherit(const inheritable_diagram_options &parent); }; diff --git a/tests/test_config.cc b/tests/test_config.cc index 159ca2be..1a5aa603 100644 --- a/tests/test_config.cc +++ b/tests/test_config.cc @@ -31,6 +31,8 @@ TEST_CASE("Test config simple", "[unit-test]") CHECK(diagram.type() == clanguml::config::diagram_type::class_diagram); CHECK(diagram.glob().size() == 2); CHECK(clanguml::util::contains(diagram.using_namespace(), "clanguml")); + CHECK(diagram.generate_method_arguments() == + clanguml::config::method_arguments::full); } TEST_CASE("Test config inherited", "[unit-test]") @@ -64,6 +66,8 @@ TEST_CASE("Test config includes", "[unit-test]") CHECK(def.glob()[0] == "src/**/*.cc"); CHECK(def.glob()[1] == "src/**/*.h"); CHECK(clanguml::util::contains(def.using_namespace(), "clanguml")); + CHECK(def.generate_method_arguments() == + clanguml::config::method_arguments::none); auto &cus = *cfg.diagrams["class_2"]; CHECK(cus.type() == clanguml::config::diagram_type::class_diagram); @@ -71,4 +75,6 @@ TEST_CASE("Test config includes", "[unit-test]") CHECK(cus.glob()[0] == "src/main.cc"); CHECK(clanguml::util::contains(cus.using_namespace(), "clanguml::ns1")); CHECK(cus.include_relations_also_as_members()); + CHECK(cus.generate_method_arguments() == + clanguml::config::method_arguments::none); } \ No newline at end of file diff --git a/tests/test_config_data/includes.yml b/tests/test_config_data/includes.yml index edbf64e4..edcb0174 100644 --- a/tests/test_config_data/includes.yml +++ b/tests/test_config_data/includes.yml @@ -1,6 +1,7 @@ compilation_database_dir: debug output_directory: output include_relations_also_as_members: false +generate_method_arguments: none using_namespace: - clanguml include: diff --git a/tests/test_config_data/simple.yml b/tests/test_config_data/simple.yml index 251cb43b..22e6d4f7 100644 --- a/tests/test_config_data/simple.yml +++ b/tests/test_config_data/simple.yml @@ -8,6 +8,7 @@ diagrams: - src/**/*.h using_namespace: - clanguml + generate_method_arguments: full include: namespaces: - clanguml