Added include! directive to config files allowing nesting diagram configs

This commit is contained in:
Bartek Kryza
2022-02-05 15:22:14 +01:00
parent c1825f1a1f
commit fcc42bc277
13 changed files with 184 additions and 172 deletions

View File

@@ -2,122 +2,18 @@ compilation_database_dir: debug
output_directory: docs/diagrams output_directory: docs/diagrams
diagrams: diagrams:
main_package: main_package:
type: package include!: uml/main_package_diagram.yml
glob:
- src/**/*.h
- src/**/*.cc
include:
namespaces:
- clanguml
using_namespace:
- clanguml
plantuml:
before:
- 'title clang-uml namespaces'
config_class: config_class:
type: class include!: uml/config_class_diagram.yml
include_relations_also_as_members: false
glob:
- src/config/config.h
- src/config/config.cc
include:
namespaces:
- clanguml::config
using_namespace:
- clanguml::config
plantuml:
before:
- 'title clang-uml configuration model'
decorators_class: decorators_class:
type: class include!: uml/decorators_class_diagram.yml
include_relations_also_as_members: false
glob:
- src/decorators/decorators.h
- src/decorators/decorators.cc
include:
namespaces:
- clanguml::decorators
using_namespace:
- clanguml::decorators
plantuml:
before:
- 'title clang-uml decorators model'
common_model_class: common_model_class:
type: class include!: uml/common_model_class_diagram.yml
include_relations_also_as_members: false
glob:
- src/common/model/*.h
- src/common/model/*.cc
include:
namespaces:
- clanguml::common::model
using_namespace:
- clanguml::common::model
plantuml:
before:
- 'title clang-uml common diagram model'
class_model_class: class_model_class:
type: class include!: uml/class_model_class_diagram.yml
include_relations_also_as_members: false
glob:
- src/class_diagram/model/*.h
- src/class_diagram/model/*.cc
include:
namespaces:
- clanguml::class_diagram::model
using_namespace:
- clanguml::class_diagram::model
plantuml:
before:
- 'title clang-uml class diagram model'
sequence_model_class: sequence_model_class:
type: class include!: uml/sequence_model_class_diagram.yml
include_relations_also_as_members: false
glob:
- src/sequence_diagram/model/*.h
- src/sequence_diagram/model/*.cc
include:
namespaces:
- clanguml::sequence_diagram::model
using_namespace:
- clanguml::sequence_diagram::model
plantuml:
before:
- 'title clang-uml sequence diagram model'
package_model_class: package_model_class:
type: class include!: uml/package_model_class_diagram.yml
include_relations_also_as_members: false
glob:
- src/package_diagram/model/*.h
- src/package_diagram/model/*.cc
include:
namespaces:
- clanguml::package_diagram::model
using_namespace:
- clanguml::package_diagram::model
plantuml:
before:
- 'title clang-uml package diagram model'
diagram_model_class: diagram_model_class:
type: class include!: uml/diagram_model_class_diagram.yml
include_relations_also_as_members: false
glob:
- src/common/model/*.h
- src/common/model/*.cc
- src/class_diagram/model/*.h
- src/class_diagram/model/*.cc
- src/sequence_diagram/model/*.h
- src/sequence_diagram/model/*.cc
- src/package_diagram/model/*.h
- src/package_diagram/model/*.cc
include:
namespaces:
- clanguml::common::model
- clanguml::class_diagram::model
- clanguml::sequence_diagram::model
- clanguml::package_diagram::model
using_namespace:
- clanguml
plantuml:
before:
- 'title clang-uml diagram model'

View File

@@ -1,39 +0,0 @@
compilation_database_dir: build
output_directory: puml
diagrams:
myproject_class:
type: class
glob:
- src/**.h
- src/**.cc
using_namespace:
- myproject
include:
namespaces:
- myproject
exclude:
namespaces:
- myproject::detail
plantuml:
after:
- 'note left of @A(MyProjectMain) : Main class of myproject library.'
main_sequence_diagram:
type: sequence
glob:
- src/main.cc
using_namespace:
- ""
start_from:
- function: "main()"
include:
namespaces:
- clanguml
exclude:
namespaces:
- std
- CLI
plantuml:
before:
- "' main test sequence diagram"
after:
- "' end"

View File

@@ -22,9 +22,19 @@ namespace config {
config load(const std::string &config_file) config load(const std::string &config_file)
{ {
YAML::Node doc = YAML::LoadFile(config_file); try {
YAML::Node doc = YAML::LoadFile(config_file);
return doc.as<config>(); return doc.as<config>();
}
catch (YAML::BadFile &e) {
throw std::runtime_error(fmt::format(
"Could not open config file {}: {}", config_file, e.what()));
}
catch (YAML::Exception &e) {
throw std::runtime_error(fmt::format(
"Cannot parse YAML file {}: {}", config_file, e.what()));
}
} }
std::string to_string(const diagram_type t) std::string to_string(const diagram_type t)
@@ -321,6 +331,34 @@ template <> struct convert<package_diagram> {
} }
}; };
std::shared_ptr<clanguml::config::diagram> parse_diagram_config(const Node &d)
{
const auto diagram_type = d["type"].as<std::string>();
if (diagram_type == "class") {
return std::make_shared<class_diagram>(d.as<class_diagram>());
}
else if (diagram_type == "sequence") {
return std::make_shared<sequence_diagram>(d.as<sequence_diagram>());
}
else if (diagram_type == "package") {
return std::make_shared<package_diagram>(d.as<package_diagram>());
}
LOG_WARN("Diagrams of type {} are not supported... ", diagram_type);
return {};
}
inline bool has_key(const YAML::Node &n, const std::string &key)
{
assert(n.Type() == NodeType::Map);
return std::count_if(n.begin(), n.end(), [&key](auto &&n) {
return n.first.template as<std::string>() == key;
}) > 0;
}
// //
// config Yaml decoder // config Yaml decoder
// //
@@ -342,26 +380,23 @@ template <> struct convert<config> {
assert(diagrams.Type() == NodeType::Map); assert(diagrams.Type() == NodeType::Map);
for (const auto &d : diagrams) { for (const auto &d : diagrams) {
const auto diagram_type = d.second["type"].as<std::string>();
auto name = d.first.as<std::string>(); auto name = d.first.as<std::string>();
if (diagram_type == "class") { std::shared_ptr<clanguml::config::diagram> diagram_config;
rhs.diagrams[name] = std::make_shared<class_diagram>(
d.second.as<class_diagram>()); if (has_key(d.second, "include!")) {
} YAML::Node node =
else if (diagram_type == "sequence") { YAML::LoadFile(d.second["include!"].as<std::string>());
rhs.diagrams[name] = std::make_shared<sequence_diagram>(
d.second.as<sequence_diagram>()); diagram_config = parse_diagram_config(node);
}
else if (diagram_type == "package") {
rhs.diagrams[name] = std::make_shared<package_diagram>(
d.second.as<package_diagram>());
} }
else { else {
LOG_WARN( diagram_config = parse_diagram_config(d.second);
"Diagrams of type {} are not supported at the moment... ", }
diagram_type);
if (diagram_config) {
diagram_config->name = name;
rhs.diagrams[name] = diagram_config;
} }
rhs.diagrams[name]->name = name;
} }
return true; return true;

View File

@@ -74,7 +74,14 @@ int main(int argc, const char *argv[])
LOG_INFO("Loading clang-uml config from {}", config_path); LOG_INFO("Loading clang-uml config from {}", config_path);
auto config = clanguml::config::load(config_path); clanguml::config::config config;
try {
config = clanguml::config::load(config_path);
}
catch (std::runtime_error &e) {
LOG_ERROR(e.what());
return 1;
}
if (list_diagrams) { if (list_diagrams) {
print_diagrams_list(config); print_diagrams_list(config);

View File

@@ -181,9 +181,10 @@ bool contains(const T &container, const E &element)
container.end(); container.end();
} }
else { else {
return std::find(container.cbegin(), container.cend(), element) != return std::find(container.begin(), container.end(), element) !=
container.cend(); container.end();
} }
} }
} // namespace util } // namespace util
} // namespace clanguml } // namespace clanguml

View File

@@ -0,0 +1,13 @@
type: class
include_relations_also_as_members: false
glob:
- src/class_diagram/model/*.h
- src/class_diagram/model/*.cc
include:
namespaces:
- clanguml::class_diagram::model
using_namespace:
- clanguml::class_diagram::model
plantuml:
before:
- 'title clang-uml class diagram model'

View File

@@ -0,0 +1,13 @@
type: class
include_relations_also_as_members: false
glob:
- src/common/model/*.h
- src/common/model/*.cc
include:
namespaces:
- clanguml::common::model
using_namespace:
- clanguml::common::model
plantuml:
before:
- 'title clang-uml common diagram model'

View File

@@ -0,0 +1,13 @@
type: class
include_relations_also_as_members: false
glob:
- src/config/config.h
- src/config/config.cc
include:
namespaces:
- clanguml::config
using_namespace:
- clanguml::config
plantuml:
before:
- 'title clang-uml configuration model'

View File

@@ -0,0 +1,13 @@
type: class
include_relations_also_as_members: false
glob:
- src/decorators/decorators.h
- src/decorators/decorators.cc
include:
namespaces:
- clanguml::decorators
using_namespace:
- clanguml::decorators
plantuml:
before:
- 'title clang-uml decorators model'

View File

@@ -0,0 +1,22 @@
type: class
include_relations_also_as_members: false
glob:
- src/common/model/*.h
- src/common/model/*.cc
- src/class_diagram/model/*.h
- src/class_diagram/model/*.cc
- src/sequence_diagram/model/*.h
- src/sequence_diagram/model/*.cc
- src/package_diagram/model/*.h
- src/package_diagram/model/*.cc
include:
namespaces:
- clanguml::common::model
- clanguml::class_diagram::model
- clanguml::sequence_diagram::model
- clanguml::package_diagram::model
using_namespace:
- clanguml
plantuml:
before:
- 'title clang-uml diagram model'

View File

@@ -0,0 +1,12 @@
type: package
glob:
- src/**/*.h
- src/**/*.cc
include:
namespaces:
- clanguml
using_namespace:
- clanguml
plantuml:
before:
- 'title clang-uml namespaces'

View File

@@ -0,0 +1,13 @@
type: class
include_relations_also_as_members: false
glob:
- src/package_diagram/model/*.h
- src/package_diagram/model/*.cc
include:
namespaces:
- clanguml::package_diagram::model
using_namespace:
- clanguml::package_diagram::model
plantuml:
before:
- 'title clang-uml package diagram model'

View File

@@ -0,0 +1,13 @@
type: class
include_relations_also_as_members: false
glob:
- src/sequence_diagram/model/*.h
- src/sequence_diagram/model/*.cc
include:
namespaces:
- clanguml::sequence_diagram::model
using_namespace:
- clanguml::sequence_diagram::model
plantuml:
before:
- 'title clang-uml sequence diagram model'