Refactored generator inheritance hierarchy
This commit is contained in:
@@ -33,11 +33,11 @@ void generator::generate_relationships(
|
||||
LOG_DBG("Generating relationships for package {}", p.full_name(true));
|
||||
|
||||
// Generate this packages relationship
|
||||
if (m_model.should_include(relationship_t::kDependency)) {
|
||||
if (model().should_include(relationship_t::kDependency)) {
|
||||
for (const auto &r : p.relationships()) {
|
||||
nlohmann::json rel = r;
|
||||
rel["source"] = std::to_string(p.id());
|
||||
json_["relationships"].push_back(std::move(rel));
|
||||
parent["relationships"].push_back(std::move(rel));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ void generator::generate(const package &p, nlohmann::json &parent) const
|
||||
|
||||
for (const auto &subpackage : p) {
|
||||
auto &pkg = dynamic_cast<package &>(*subpackage);
|
||||
if (m_model.should_include(pkg)) {
|
||||
if (model().should_include(pkg)) {
|
||||
generate(pkg, j);
|
||||
}
|
||||
}
|
||||
@@ -74,33 +74,29 @@ void generator::generate(const package &p, nlohmann::json &parent) const
|
||||
parent["elements"].push_back(std::move(j));
|
||||
}
|
||||
|
||||
void generator::generate(std::ostream &ostr) const
|
||||
void generator::generate_diagram(nlohmann::json &parent) const
|
||||
{
|
||||
if (m_config.using_namespace)
|
||||
json_["using_namespace"] = m_config.using_namespace().to_string();
|
||||
if (config().using_namespace)
|
||||
parent["using_namespace"] = config().using_namespace().to_string();
|
||||
|
||||
json_["name"] = m_model.name();
|
||||
json_["diagram_type"] = "package";
|
||||
parent["name"] = model().name();
|
||||
parent["diagram_type"] = "package";
|
||||
|
||||
json_["elements"] = std::vector<nlohmann::json>{};
|
||||
json_["relationships"] = std::vector<nlohmann::json>{};
|
||||
parent["elements"] = std::vector<nlohmann::json>{};
|
||||
parent["relationships"] = std::vector<nlohmann::json>{};
|
||||
|
||||
for (const auto &p : m_model) {
|
||||
for (const auto &p : model()) {
|
||||
auto &pkg = dynamic_cast<package &>(*p);
|
||||
if (m_model.should_include(pkg)) {
|
||||
generate(pkg, json_);
|
||||
if (model().should_include(pkg)) {
|
||||
generate(pkg, parent);
|
||||
}
|
||||
}
|
||||
|
||||
// Process package relationships
|
||||
for (const auto &p : m_model) {
|
||||
if (m_model.should_include(dynamic_cast<package &>(*p)))
|
||||
generate_relationships(dynamic_cast<package &>(*p), json_);
|
||||
for (const auto &p : model()) {
|
||||
if (model().should_include(dynamic_cast<package &>(*p)))
|
||||
generate_relationships(dynamic_cast<package &>(*p), parent);
|
||||
}
|
||||
|
||||
generate_metadata(json_);
|
||||
|
||||
ostr << json_;
|
||||
}
|
||||
|
||||
} // namespace clanguml::package_diagram::generators::json
|
||||
|
||||
@@ -51,6 +51,8 @@ class generator : public common_generator<diagram_config, diagram_model> {
|
||||
public:
|
||||
generator(diagram_config &config, diagram_model &model);
|
||||
|
||||
using common_generator<diagram_config, diagram_model>::generate;
|
||||
|
||||
/**
|
||||
* @brief Main generator method.
|
||||
*
|
||||
@@ -59,7 +61,7 @@ public:
|
||||
*
|
||||
* @param ostr Output stream.
|
||||
*/
|
||||
void generate(std::ostream &ostr) const override;
|
||||
void generate_diagram(nlohmann::json &parent) const override;
|
||||
|
||||
/**
|
||||
* @brief Generate relationships originating from package `p`
|
||||
@@ -76,9 +78,6 @@ public:
|
||||
* @param parent Parent JSON node
|
||||
*/
|
||||
void generate(const package &p, nlohmann::json &parent) const;
|
||||
|
||||
private:
|
||||
mutable nlohmann::json json_;
|
||||
};
|
||||
|
||||
} // namespace clanguml::package_diagram::generators::json
|
||||
|
||||
@@ -34,11 +34,11 @@ void generator::generate_relationships(
|
||||
LOG_DBG("Generating relationships for package {}", p.full_name(true));
|
||||
|
||||
// Generate this packages relationship
|
||||
if (m_model.should_include(relationship_t::kDependency)) {
|
||||
if (model().should_include(relationship_t::kDependency)) {
|
||||
for (const auto &r : p.relationships()) {
|
||||
std::stringstream relstr;
|
||||
try {
|
||||
auto destination = m_model.to_alias(r.destination());
|
||||
auto destination = model().to_alias(r.destination());
|
||||
if (!destination.empty()) {
|
||||
relstr << p.alias() << " ..> " << destination << '\n';
|
||||
ostr << relstr.str();
|
||||
@@ -65,7 +65,7 @@ void generator::generate(const package &p, std::ostream &ostr) const
|
||||
|
||||
together_group_stack_.enter();
|
||||
|
||||
const auto &uns = m_config.using_namespace();
|
||||
const auto &uns = config().using_namespace();
|
||||
|
||||
// Don't generate packages from namespaces filtered out by
|
||||
// using_namespace
|
||||
@@ -76,7 +76,7 @@ void generator::generate(const package &p, std::ostream &ostr) const
|
||||
if (p.is_deprecated())
|
||||
ostr << " <<deprecated>>";
|
||||
|
||||
if (m_config.generate_links) {
|
||||
if (config().generate_links) {
|
||||
generate_link(ostr, p);
|
||||
}
|
||||
|
||||
@@ -88,9 +88,9 @@ void generator::generate(const package &p, std::ostream &ostr) const
|
||||
|
||||
for (const auto &subpackage : p) {
|
||||
auto &pkg = dynamic_cast<package &>(*subpackage);
|
||||
if (m_model.should_include(pkg)) {
|
||||
if (model().should_include(pkg)) {
|
||||
auto together_group =
|
||||
m_config.get_together_group(pkg.full_name(false));
|
||||
config().get_together_group(pkg.full_name(false));
|
||||
if (together_group) {
|
||||
together_group_stack_.group_together(
|
||||
together_group.value(), &pkg);
|
||||
@@ -112,46 +112,6 @@ void generator::generate(const package &p, std::ostream &ostr) const
|
||||
together_group_stack_.leave();
|
||||
}
|
||||
|
||||
void generator::generate(std::ostream &ostr) const
|
||||
{
|
||||
update_context();
|
||||
|
||||
ostr << "@startuml" << '\n';
|
||||
|
||||
generate_plantuml_directives(ostr, m_config.puml().before);
|
||||
|
||||
for (const auto &p : m_model) {
|
||||
auto &pkg = dynamic_cast<package &>(*p);
|
||||
if (m_model.should_include(pkg)) {
|
||||
auto together_group =
|
||||
m_config.get_together_group(pkg.full_name(false));
|
||||
if (together_group) {
|
||||
together_group_stack_.group_together(
|
||||
together_group.value(), &pkg);
|
||||
}
|
||||
else {
|
||||
generate(pkg, ostr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
generate_groups(ostr);
|
||||
|
||||
// Process package relationships
|
||||
for (const auto &p : m_model) {
|
||||
if (m_model.should_include(dynamic_cast<package &>(*p)))
|
||||
generate_relationships(dynamic_cast<package &>(*p), ostr);
|
||||
}
|
||||
|
||||
generate_config_layout_hints(ostr);
|
||||
|
||||
generate_plantuml_directives(ostr, m_config.puml().after);
|
||||
|
||||
generate_metadata(ostr);
|
||||
|
||||
ostr << "@enduml" << '\n';
|
||||
}
|
||||
|
||||
void generator::generate_groups(std::ostream &ostr) const
|
||||
{
|
||||
for (const auto &[group_name, group_elements] :
|
||||
@@ -166,4 +126,32 @@ void generator::generate_groups(std::ostream &ostr) const
|
||||
}
|
||||
}
|
||||
|
||||
void generator::generate_diagram(std::ostream &ostr) const
|
||||
{
|
||||
for (const auto &p : model()) {
|
||||
auto &pkg = dynamic_cast<package &>(*p);
|
||||
if (model().should_include(pkg)) {
|
||||
auto together_group =
|
||||
config().get_together_group(pkg.full_name(false));
|
||||
if (together_group) {
|
||||
together_group_stack_.group_together(
|
||||
together_group.value(), &pkg);
|
||||
}
|
||||
else {
|
||||
generate(pkg, ostr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
generate_groups(ostr);
|
||||
|
||||
// Process package relationships
|
||||
for (const auto &p : model()) {
|
||||
if (model().should_include(dynamic_cast<package &>(*p)))
|
||||
generate_relationships(dynamic_cast<package &>(*p), ostr);
|
||||
}
|
||||
|
||||
generate_config_layout_hints(ostr);
|
||||
}
|
||||
|
||||
} // namespace clanguml::package_diagram::generators::plantuml
|
||||
|
||||
@@ -55,6 +55,8 @@ class generator : public common_generator<diagram_config, diagram_model> {
|
||||
public:
|
||||
generator(diagram_config &config, diagram_model &model);
|
||||
|
||||
using common_generator<diagram_config, diagram_model>::generate;
|
||||
|
||||
/**
|
||||
* @brief Main generator method.
|
||||
*
|
||||
@@ -63,7 +65,7 @@ public:
|
||||
*
|
||||
* @param ostr Output stream.
|
||||
*/
|
||||
void generate(std::ostream &ostr) const override;
|
||||
void generate_diagram(std::ostream &ostr) const override;
|
||||
|
||||
/**
|
||||
* @brief Generate relationships originating from package `p`
|
||||
|
||||
Reference in New Issue
Block a user