Generate enums as aliases
This commit is contained in:
@@ -124,7 +124,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void generate_aliases(const class_ &c, std::ostream &ostr) const
|
||||
void generate_alias(const class_ &c, std::ostream &ostr) const
|
||||
{
|
||||
std::string class_type{"class"};
|
||||
if (c.is_abstract())
|
||||
@@ -135,6 +135,13 @@ public:
|
||||
ostr << "\" as " << c.alias() << std::endl;
|
||||
}
|
||||
|
||||
void generate_alias(const enum_ &e, std::ostream &ostr) const
|
||||
{
|
||||
ostr << "enum" << " \"" << e.full_name(m_config.using_namespace);
|
||||
|
||||
ostr << "\" as " << e.alias() << std::endl;
|
||||
}
|
||||
|
||||
void generate(const class_ &c, std::ostream &ostr) const
|
||||
{
|
||||
std::string class_type{"class"};
|
||||
@@ -266,7 +273,7 @@ public:
|
||||
|
||||
void generate(const enum_ &e, std::ostream &ostr) const
|
||||
{
|
||||
ostr << "enum " << ns_relative(m_config.using_namespace, e.name) << " {"
|
||||
ostr << "enum " << e.alias() << " {"
|
||||
<< std::endl;
|
||||
|
||||
for (const auto &enum_constant : e.constants) {
|
||||
@@ -325,7 +332,12 @@ public:
|
||||
|
||||
if (m_config.should_include_entities("classes")) {
|
||||
for (const auto &c : m_model.classes) {
|
||||
generate_aliases(c, ostr);
|
||||
generate_alias(c, ostr);
|
||||
ostr << std::endl;
|
||||
}
|
||||
|
||||
for (const auto &e : m_model.enums) {
|
||||
generate_alias(e, ostr);
|
||||
ostr << std::endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -175,9 +175,9 @@ public:
|
||||
|
||||
void add_relationship(class_relationship &&cr)
|
||||
{
|
||||
if (cr.destination.empty() || type_aliases.count(cr.destination) == 0) {
|
||||
if (cr.destination.empty()) {
|
||||
LOG_WARN(
|
||||
"Skipping relationship '{}' - {} - '{}' due to missing alias",
|
||||
"Skipping relationship '{}' - {} - '{}' due empty destination",
|
||||
cr.destination, to_string(cr.type), usr);
|
||||
return;
|
||||
}
|
||||
@@ -240,6 +240,18 @@ struct enum_ : public element {
|
||||
{
|
||||
return l.name == r.name;
|
||||
}
|
||||
|
||||
std::string full_name(
|
||||
const std::vector<std::string> &using_namespaces) const
|
||||
{
|
||||
using namespace clanguml::util;
|
||||
|
||||
std::ostringstream ostr;
|
||||
ostr << ns_relative(using_namespaces, name);
|
||||
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct diagram {
|
||||
@@ -289,6 +301,12 @@ struct diagram {
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &e : enums) {
|
||||
if (e.full_name(using_namespaces) == full_name) {
|
||||
return e.alias();
|
||||
}
|
||||
}
|
||||
|
||||
throw error::uml_alias_missing(
|
||||
fmt::format("Missing alias for {}", full_name));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user