Refactored class diagram class_ model
This commit is contained in:
@@ -138,7 +138,7 @@ void generator::generate(const class_ &c, std::ostream &ostr) const
|
||||
//
|
||||
// Process methods
|
||||
//
|
||||
for (const auto &m : c.methods) {
|
||||
for (const auto &m : c.methods()) {
|
||||
if (!m_config.should_include(m.scope))
|
||||
continue;
|
||||
|
||||
@@ -237,7 +237,7 @@ void generator::generate(const class_ &c, std::ostream &ostr) const
|
||||
//
|
||||
// Process members
|
||||
//
|
||||
for (const auto &m : c.members) {
|
||||
for (const auto &m : c.members()) {
|
||||
if (!m_config.should_include(m.scope))
|
||||
continue;
|
||||
|
||||
@@ -255,7 +255,7 @@ void generator::generate(const class_ &c, std::ostream &ostr) const
|
||||
ostr << "}" << '\n';
|
||||
|
||||
if (m_config.should_include_relationship("inheritance"))
|
||||
for (const auto &b : c.bases) {
|
||||
for (const auto &b : c.parents()) {
|
||||
std::stringstream relstr;
|
||||
try {
|
||||
relstr << m_model.to_alias(ns_relative(uns, b.name)) << " <|-- "
|
||||
@@ -362,7 +362,7 @@ void generator::generate(std::ostream &ostr) const
|
||||
|
||||
if (m_config.should_include_entities("classes")) {
|
||||
for (const auto &c : m_model.classes()) {
|
||||
if (!c.is_template_instantiation &&
|
||||
if (!c.is_template_instantiation() &&
|
||||
!m_config.should_include(c.name()))
|
||||
continue;
|
||||
generate_alias(c, ostr);
|
||||
@@ -377,7 +377,7 @@ void generator::generate(std::ostream &ostr) const
|
||||
}
|
||||
|
||||
for (const auto &c : m_model.classes()) {
|
||||
if (!c.is_template_instantiation &&
|
||||
if (!c.is_template_instantiation() &&
|
||||
!m_config.should_include(c.name()))
|
||||
continue;
|
||||
generate(c, ostr);
|
||||
|
||||
@@ -184,6 +184,66 @@ bool operator==(const class_template &l, const class_template &r)
|
||||
//
|
||||
// class_
|
||||
//
|
||||
class_::class_(const std::vector<std::string> &using_namespaces)
|
||||
: element{using_namespaces}
|
||||
{
|
||||
}
|
||||
|
||||
bool class_::is_struct() const { return is_struct_; }
|
||||
|
||||
void class_::set_is_struct(bool is_struct) { is_struct_ = is_struct; }
|
||||
|
||||
bool class_::is_template() const { return is_template_; }
|
||||
|
||||
void class_::set_is_template(bool is_template) { is_template_ = is_template; }
|
||||
|
||||
bool class_::is_template_instantiation() const
|
||||
{
|
||||
return is_template_instantiation_;
|
||||
}
|
||||
|
||||
void class_::set_is_template_instantiation(bool is_template_instantiation)
|
||||
{
|
||||
is_template_instantiation_ = is_template_instantiation;
|
||||
}
|
||||
|
||||
void class_::add_member(class_member &&member)
|
||||
{
|
||||
members_.emplace_back(std::move(member));
|
||||
}
|
||||
|
||||
void class_::add_method(class_method &&method)
|
||||
{
|
||||
methods_.emplace_back(std::move(method));
|
||||
}
|
||||
|
||||
void class_::add_parent(class_parent &&parent)
|
||||
{
|
||||
bases_.emplace_back(std::move(parent));
|
||||
}
|
||||
|
||||
void class_::add_template(class_template &&tmplt)
|
||||
{
|
||||
templates_.emplace_back(std::move(tmplt));
|
||||
}
|
||||
|
||||
const std::vector<class_member> &class_::members() const { return members_; }
|
||||
|
||||
const std::vector<class_method> &class_::methods() const { return methods_; }
|
||||
|
||||
const std::vector<class_parent> &class_::parents() const { return bases_; }
|
||||
|
||||
const std::vector<class_template> &class_::templates() const
|
||||
{
|
||||
return templates_;
|
||||
}
|
||||
|
||||
void class_::set_base_template(const std::string &full_name)
|
||||
{
|
||||
base_template_full_name_ = full_name;
|
||||
}
|
||||
|
||||
std::string class_::base_template() const { return base_template_full_name_; }
|
||||
|
||||
bool operator==(const class_ &l, const class_ &r)
|
||||
{
|
||||
@@ -193,7 +253,7 @@ bool operator==(const class_ &l, const class_ &r)
|
||||
void class_::add_type_alias(type_alias &&ta)
|
||||
{
|
||||
LOG_DBG("Adding class alias: {} -> {}", ta.alias, ta.underlying_type);
|
||||
type_aliases[ta.alias] = std::move(ta);
|
||||
type_aliases_[ta.alias] = std::move(ta);
|
||||
}
|
||||
|
||||
std::string class_::full_name(bool relative) const
|
||||
@@ -206,9 +266,9 @@ std::string class_::full_name(bool relative) const
|
||||
else
|
||||
ostr << name();
|
||||
|
||||
if (!templates.empty()) {
|
||||
if (!templates_.empty()) {
|
||||
std::vector<std::string> tnames;
|
||||
std::transform(templates.cbegin(), templates.cend(),
|
||||
std::transform(templates_.cbegin(), templates_.cend(),
|
||||
std::back_inserter(tnames), [this](const auto &tmplt) {
|
||||
std::vector<std::string> res;
|
||||
|
||||
@@ -235,13 +295,17 @@ bool class_::is_abstract() const
|
||||
{
|
||||
// TODO check if all base abstract methods are overriden
|
||||
// with non-abstract methods
|
||||
return std::any_of(methods.begin(), methods.end(),
|
||||
return std::any_of(methods_.begin(), methods_.end(),
|
||||
[](const auto &method) { return method.is_pure_virtual; });
|
||||
}
|
||||
|
||||
//
|
||||
// enum_
|
||||
//
|
||||
enum_::enum_(const std::vector<std::string> &using_namespaces)
|
||||
: element{using_namespaces}
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==(const enum_ &l, const enum_ &r) { return l.name() == r.name(); }
|
||||
|
||||
@@ -258,6 +322,10 @@ std::string enum_::full_name(bool relative) const
|
||||
return ostr.str();
|
||||
}
|
||||
|
||||
std::vector<std::string> &enum_::constants() { return constants_; }
|
||||
|
||||
const std::vector<std::string> &enum_::constants() const { return constants_; }
|
||||
|
||||
//
|
||||
// diagram
|
||||
//
|
||||
|
||||
@@ -172,21 +172,29 @@ struct type_alias {
|
||||
|
||||
class class_ : public element, public stylable_element {
|
||||
public:
|
||||
class_(const std::vector<std::string> &using_namespaces)
|
||||
: element{using_namespaces}
|
||||
{
|
||||
}
|
||||
class_(const std::vector<std::string> &using_namespaces);
|
||||
|
||||
bool is_struct{false};
|
||||
bool is_template{false};
|
||||
bool is_template_instantiation{false};
|
||||
std::vector<class_member> members;
|
||||
std::vector<class_method> methods;
|
||||
std::vector<class_parent> bases;
|
||||
std::vector<std::string> inner_classes;
|
||||
std::vector<class_template> templates;
|
||||
std::string base_template_full_name;
|
||||
std::map<std::string, type_alias> type_aliases;
|
||||
bool is_struct() const;
|
||||
void set_is_struct(bool is_struct);
|
||||
|
||||
bool is_template() const;
|
||||
void set_is_template(bool is_template);
|
||||
|
||||
bool is_template_instantiation() const;
|
||||
void set_is_template_instantiation(bool is_template_instantiation);
|
||||
|
||||
void add_member(class_member &&member);
|
||||
void add_method(class_method &&method);
|
||||
void add_parent(class_parent &&parent);
|
||||
void add_template(class_template &&tmplt);
|
||||
|
||||
const std::vector<class_member> &members() const;
|
||||
const std::vector<class_method> &methods() const;
|
||||
const std::vector<class_parent> &parents() const;
|
||||
const std::vector<class_template> &templates() const;
|
||||
|
||||
void set_base_template(const std::string &full_name);
|
||||
std::string base_template() const;
|
||||
|
||||
friend bool operator==(const class_ &l, const class_ &r);
|
||||
|
||||
@@ -197,23 +205,30 @@ public:
|
||||
bool is_abstract() const;
|
||||
|
||||
private:
|
||||
bool is_struct_{false};
|
||||
bool is_template_{false};
|
||||
bool is_template_instantiation_{false};
|
||||
std::vector<class_member> members_;
|
||||
std::vector<class_method> methods_;
|
||||
std::vector<class_parent> bases_;
|
||||
std::vector<class_template> templates_;
|
||||
std::string base_template_full_name_;
|
||||
std::map<std::string, type_alias> type_aliases_;
|
||||
|
||||
std::string full_name_;
|
||||
};
|
||||
|
||||
struct enum_ : public element, public stylable_element {
|
||||
public:
|
||||
enum_(const std::vector<std::string> &using_namespaces)
|
||||
: element{using_namespaces}
|
||||
{
|
||||
}
|
||||
enum_(const std::vector<std::string> &using_namespaces);
|
||||
|
||||
friend bool operator==(const enum_ &l, const enum_ &r);
|
||||
|
||||
std::string full_name(bool relative = true) const override;
|
||||
|
||||
std::vector<std::string> &constants() { return constants_; }
|
||||
std::vector<std::string> &constants();
|
||||
|
||||
const std::vector<std::string> &constants() const { return constants_; }
|
||||
const std::vector<std::string> &constants() const;
|
||||
|
||||
private:
|
||||
std::vector<std::string> constants_;
|
||||
@@ -223,7 +238,7 @@ class diagram {
|
||||
public:
|
||||
std::string name() const;
|
||||
|
||||
void set_name(const std::string& name);
|
||||
void set_name(const std::string &name);
|
||||
|
||||
const std::vector<class_> classes() const;
|
||||
|
||||
|
||||
@@ -324,7 +324,7 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls,
|
||||
type_safe::optional_ref<const cppast::cpp_template_specialization> tspec)
|
||||
{
|
||||
class_ c{ctx.config.using_namespace};
|
||||
c.is_struct = cls.class_kind() == cppast::cpp_class_kind::struct_t;
|
||||
c.set_is_struct(cls.class_kind() == cppast::cpp_class_kind::struct_t);
|
||||
c.set_name(cx::util::full_name(ctx.namespace_, cls));
|
||||
|
||||
if (cls.comment().has_value())
|
||||
@@ -350,7 +350,7 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls,
|
||||
c.style = c.style_spec();
|
||||
|
||||
// Process class child entities
|
||||
if (c.is_struct)
|
||||
if (c.is_struct())
|
||||
last_access_specifier = cppast::cpp_access_specifier_kind::cpp_public;
|
||||
|
||||
for (auto &child : cls) {
|
||||
@@ -440,7 +440,7 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls,
|
||||
|
||||
LOG_DBG("Found base class {} for class {}", cp.name, c.name());
|
||||
|
||||
c.bases.emplace_back(std::move(cp));
|
||||
c.add_parent(std::move(cp));
|
||||
}
|
||||
|
||||
// Process class template arguments
|
||||
@@ -500,7 +500,7 @@ void tu_visitor::process_class_declaration(const cppast::cpp_class &cls,
|
||||
ct.default_value = "";
|
||||
ct.is_variadic = false;
|
||||
ct.name = "";
|
||||
c.templates.emplace_back(std::move(ct));
|
||||
c.add_template(std::move(ct));
|
||||
|
||||
const auto &primary_template_ref =
|
||||
static_cast<const cppast::cpp_class_template &>(
|
||||
@@ -739,7 +739,7 @@ void tu_visitor::process_field(const cppast::cpp_member_variable &mv, class_ &c,
|
||||
}
|
||||
}
|
||||
|
||||
c.members.emplace_back(std::move(m));
|
||||
c.add_member(std::move(m));
|
||||
}
|
||||
|
||||
void tu_visitor::process_anonymous_enum(
|
||||
@@ -752,7 +752,7 @@ void tu_visitor::process_anonymous_enum(
|
||||
m.type = "enum"; // TODO: Try to figure out real enum type
|
||||
m.scope = detail::cpp_access_specifier_to_scope(as);
|
||||
m.is_static = false;
|
||||
c.members.emplace_back(std::move(m));
|
||||
c.add_member(std::move(m));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -772,7 +772,7 @@ void tu_visitor::process_static_field(const cppast::cpp_variable &mv, class_ &c,
|
||||
if (m.skip())
|
||||
return;
|
||||
|
||||
c.members.emplace_back(std::move(m));
|
||||
c.add_member(std::move(m));
|
||||
}
|
||||
|
||||
void tu_visitor::process_method(const cppast::cpp_member_function &mf,
|
||||
@@ -799,7 +799,7 @@ void tu_visitor::process_method(const cppast::cpp_member_function &mf,
|
||||
|
||||
LOG_DBG("Adding method: {}", m.name);
|
||||
|
||||
c.methods.emplace_back(std::move(m));
|
||||
c.add_method(std::move(m));
|
||||
}
|
||||
|
||||
void tu_visitor::process_template_method(
|
||||
@@ -839,7 +839,7 @@ void tu_visitor::process_template_method(
|
||||
|
||||
LOG_DBG("Adding template method: {}", m.name);
|
||||
|
||||
c.methods.emplace_back(std::move(m));
|
||||
c.add_method(std::move(m));
|
||||
}
|
||||
|
||||
void tu_visitor::process_static_method(const cppast::cpp_function &mf,
|
||||
@@ -866,7 +866,7 @@ void tu_visitor::process_static_method(const cppast::cpp_function &mf,
|
||||
|
||||
LOG_DBG("Adding static method: {}", m.name);
|
||||
|
||||
c.methods.emplace_back(std::move(m));
|
||||
c.add_method(std::move(m));
|
||||
}
|
||||
|
||||
void tu_visitor::process_constructor(const cppast::cpp_constructor &mf,
|
||||
@@ -891,7 +891,7 @@ void tu_visitor::process_constructor(const cppast::cpp_constructor &mf,
|
||||
for (auto ¶m : mf.parameters())
|
||||
process_function_parameter(param, m, c);
|
||||
|
||||
c.methods.emplace_back(std::move(m));
|
||||
c.add_method(std::move(m));
|
||||
}
|
||||
|
||||
void tu_visitor::process_destructor(const cppast::cpp_destructor &mf, class_ &c,
|
||||
@@ -907,7 +907,7 @@ void tu_visitor::process_destructor(const cppast::cpp_destructor &mf, class_ &c,
|
||||
m.is_static = false;
|
||||
m.scope = detail::cpp_access_specifier_to_scope(as);
|
||||
|
||||
c.methods.emplace_back(std::move(m));
|
||||
c.add_method(std::move(m));
|
||||
}
|
||||
|
||||
void tu_visitor::process_function_parameter(
|
||||
@@ -1069,7 +1069,7 @@ void tu_visitor::process_template_type_parameter(
|
||||
ct.name = t.name();
|
||||
if (ct.is_variadic)
|
||||
ct.name += "...";
|
||||
parent.templates.emplace_back(std::move(ct));
|
||||
parent.add_template(std::move(ct));
|
||||
}
|
||||
|
||||
void tu_visitor::process_template_nontype_parameter(
|
||||
@@ -1082,7 +1082,7 @@ void tu_visitor::process_template_nontype_parameter(
|
||||
ct.is_variadic = t.is_variadic();
|
||||
if (ct.is_variadic)
|
||||
ct.name += "...";
|
||||
parent.templates.emplace_back(std::move(ct));
|
||||
parent.add_template(std::move(ct));
|
||||
}
|
||||
|
||||
void tu_visitor::process_template_template_parameter(
|
||||
@@ -1092,7 +1092,7 @@ void tu_visitor::process_template_template_parameter(
|
||||
ct.type = "";
|
||||
ct.name = t.name() + "<>";
|
||||
ct.default_value = "";
|
||||
parent.templates.emplace_back(std::move(ct));
|
||||
parent.add_template(std::move(ct));
|
||||
}
|
||||
|
||||
void tu_visitor::process_friend(const cppast::cpp_friend &f, class_ &parent)
|
||||
@@ -1381,10 +1381,9 @@ class_ tu_visitor::build_template_instantiation(
|
||||
}
|
||||
|
||||
if (primary_template_ref.user_data()) {
|
||||
tinst.base_template_full_name =
|
||||
static_cast<const char *>(primary_template_ref.user_data());
|
||||
LOG_DBG("Primary template ref set to: {}",
|
||||
tinst.base_template_full_name);
|
||||
tinst.set_base_template(
|
||||
static_cast<const char *>(primary_template_ref.user_data()));
|
||||
LOG_DBG("Primary template ref set to: {}", tinst.base_template());
|
||||
}
|
||||
else
|
||||
LOG_WARN("No user data for base template {}",
|
||||
@@ -1414,7 +1413,7 @@ class_ tu_visitor::build_template_instantiation(
|
||||
|
||||
tinst.set_name(ns + util::split(cppast::to_string(t), "<")[0]);
|
||||
|
||||
tinst.is_template_instantiation = true;
|
||||
tinst.set_is_template_instantiation(true);
|
||||
|
||||
if (tinst.full_name().substr(0, tinst.full_name().find('<')).find("::") ==
|
||||
std::string::npos) {
|
||||
@@ -1545,13 +1544,13 @@ class_ tu_visitor::build_template_instantiation(
|
||||
cp.access = class_parent::access_t::kPublic;
|
||||
cp.name = ct.type;
|
||||
|
||||
tinst.bases.emplace_back(std::move(cp));
|
||||
tinst.add_parent(std::move(cp));
|
||||
}
|
||||
}
|
||||
|
||||
LOG_DBG("Adding template argument '{}'", ct.type);
|
||||
|
||||
tinst.templates.emplace_back(std::move(ct));
|
||||
tinst.add_template(std::move(ct));
|
||||
}
|
||||
|
||||
// Add instantiation relationship to primary template of this
|
||||
@@ -1568,7 +1567,7 @@ class_ tu_visitor::build_template_instantiation(
|
||||
}
|
||||
else {
|
||||
// Otherwise point to the base template
|
||||
r.destination = tinst.base_template_full_name;
|
||||
r.destination = tinst.base_template();
|
||||
}
|
||||
r.type = relationship_t::kInstantiation;
|
||||
r.label = "";
|
||||
|
||||
Reference in New Issue
Block a user