Added generate_method_arguments config option

This commit is contained in:
Bartek Kryza 2022-02-06 18:18:34 +01:00
parent 8f35a194e1
commit 786ecbdd1d
6 changed files with 66 additions and 35 deletions

View File

@ -3,7 +3,6 @@ BasedOnStyle: WebKit
BreakConstructorInitializersBeforeComma: true
ColumnLimit: 80
Cpp11BracedListStyle: true
IndentCaseLabels: true
NamespaceIndentation: None
PointerBindsToType: false
Standard: Cpp11

View File

@ -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<std::vector<std::string>>(
{
l.insert(l.end(), r.begin(), r.end());
}
template <> void append_value<plantuml>(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 <typename T>
void get_option(const Node &node, clanguml::config::option<T> &option)
{
if (node[option.name])
option.append(node[option.name].template as<T>());
option.set(node[option.name].template as<T>());
}
template <>
void get_option<method_arguments>(
const Node &node, clanguml::config::option<method_arguments> &option)
{
if (node[option.name]) {
const auto &val = node[option.name].as<std::string>();
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<clanguml::config::diagram> parse_diagram_config(const Node &d)
@ -367,6 +376,7 @@ template <> struct convert<class_diagram> {
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<config> {
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"];

View File

@ -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<std::string> before;
std::vector<std::string> after;
@ -61,35 +64,42 @@ struct filter {
std::vector<common::model::scope_t> scopes;
};
enum class diagram_type { class_diagram, sequence_diagram, package_diagram };
std::string to_string(const diagram_type t);
template <typename T> void append_value(T &l, const T &r) { l = r; }
enum class option_inherit_mode { override, append };
template <typename T> 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<T> &operator+=(const T &r)
void override(const option<T> &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 <typename T> 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<filter> include{"include"};
option<filter> exclude{"exclude"};
option<plantuml> puml{"plantuml"};
option<plantuml> puml{"plantuml", option_inherit_mode::append};
option<method_arguments> generate_method_arguments{
"generate_method_arguments", method_arguments::full};
void inherit(const inheritable_diagram_options &parent);
};

View File

@ -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);
}

View File

@ -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:

View File

@ -8,6 +8,7 @@ diagrams:
- src/**/*.h
using_namespace:
- clanguml
generate_method_arguments: full
include:
namespaces:
- clanguml