Refactored standard template aliases to configuration file
This commit is contained in:
@@ -64,8 +64,6 @@ void generator::generate_alias(const class_ &c, std::ostream &ostr) const
|
||||
else
|
||||
full_name = c.full_name();
|
||||
|
||||
// util::replace_all(full_name, "std::basic_string<char>", "std::string");
|
||||
|
||||
if (full_name.empty())
|
||||
full_name = "<<anonymous>>";
|
||||
|
||||
|
||||
@@ -36,14 +36,7 @@ void template_parameter::set_type(const std::string &type) { type_ = type; }
|
||||
|
||||
std::string template_parameter::type() const { return type_; }
|
||||
|
||||
void template_parameter::set_name(const std::string &name)
|
||||
{
|
||||
name_ = name;
|
||||
// TODO: Add a configurable mapping for simplifying non-interesting
|
||||
// std templates
|
||||
util::replace_all(name_, "std::basic_string<char>", "std::string");
|
||||
util::replace_all(name_, "std::basic_string<wchar_t>", "std::wstring");
|
||||
}
|
||||
void template_parameter::set_name(const std::string &name) { name_ = name; }
|
||||
|
||||
std::string template_parameter::name() const
|
||||
{
|
||||
@@ -157,10 +150,6 @@ std::string template_parameter::to_string(
|
||||
res += default_value();
|
||||
}
|
||||
|
||||
// TODO: Refactor this to external configurable class
|
||||
util::replace_all(res, "std::basic_string<char>", "std::string");
|
||||
util::replace_all(res, "std::basic_string<wchar_t>", "std::wstring");
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -2077,20 +2077,8 @@ const cppast::cpp_type &translation_unit_visitor::resolve_alias_template(
|
||||
bool translation_unit_visitor::simplify_system_template(
|
||||
template_parameter &ct, const std::string &full_name)
|
||||
{
|
||||
if (full_name == "std::basic_string<char>") {
|
||||
ct.set_name("std::string");
|
||||
return true;
|
||||
}
|
||||
else if (full_name == "std::basic_string<wchar_t>") {
|
||||
ct.set_name("std::wstring");
|
||||
return true;
|
||||
}
|
||||
else if (full_name == "std::basic_string<char16_t>") {
|
||||
ct.set_name("std::u16string");
|
||||
return true;
|
||||
}
|
||||
else if (full_name == "std::basic_string<char32_t>") {
|
||||
ct.set_name("std::u32string");
|
||||
if (ctx.config().template_aliases().count(full_name) > 0) {
|
||||
ct.set_name(ctx.config().template_aliases().at(full_name));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -148,6 +148,25 @@ void class_diagram::initialize_relationship_hints()
|
||||
}
|
||||
}
|
||||
|
||||
void class_diagram::initialize_template_aliases()
|
||||
{
|
||||
if (!template_aliases().count("std::basic_string<char>")) {
|
||||
template_aliases().insert({"std::basic_string<char>", "std::string"});
|
||||
}
|
||||
if (!template_aliases().count("std::basic_string<wchar_t>")) {
|
||||
template_aliases().insert(
|
||||
{"std::basic_string<wchar_t>", "std::wstring"});
|
||||
}
|
||||
if (!template_aliases().count("std::basic_string<char16_t>")) {
|
||||
template_aliases().insert(
|
||||
{"std::basic_string<char16_t>", "std::u16string"});
|
||||
}
|
||||
if (!template_aliases().count("std::basic_string<char32_t>")) {
|
||||
template_aliases().insert(
|
||||
{"std::basic_string<char32_t>", "std::u32string"});
|
||||
}
|
||||
}
|
||||
|
||||
template <> void append_value<plantuml>(plantuml &l, const plantuml &r)
|
||||
{
|
||||
l.append(r);
|
||||
@@ -489,8 +508,10 @@ template <> struct convert<class_diagram> {
|
||||
get_option(node, rhs.generate_method_arguments);
|
||||
get_option(node, rhs.generate_packages);
|
||||
get_option(node, rhs.relationship_hints);
|
||||
get_option(node, rhs.template_aliases);
|
||||
|
||||
rhs.initialize_relationship_hints();
|
||||
rhs.initialize_template_aliases();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -116,6 +116,8 @@ struct relationship_hint_t {
|
||||
|
||||
using relationship_hints_t = std::map<std::string, relationship_hint_t>;
|
||||
|
||||
using template_aliases_t = std::map<std::string, std::string>;
|
||||
|
||||
std::string to_string(const hint_t t);
|
||||
|
||||
struct inheritable_diagram_options {
|
||||
@@ -135,6 +137,7 @@ struct inheritable_diagram_options {
|
||||
option<std::filesystem::path> relative_to{"relative_to"};
|
||||
option<bool> generate_system_headers{"generate_system_headers", false};
|
||||
option<relationship_hints_t> relationship_hints{"relationship_hints"};
|
||||
option<template_aliases_t> template_aliases{"template_aliases"};
|
||||
|
||||
void inherit(const inheritable_diagram_options &parent);
|
||||
};
|
||||
@@ -162,6 +165,8 @@ struct class_diagram : public diagram {
|
||||
option<layout_hints> layout{"layout"};
|
||||
|
||||
void initialize_relationship_hints();
|
||||
|
||||
void initialize_template_aliases();
|
||||
};
|
||||
|
||||
struct sequence_diagram : public diagram {
|
||||
|
||||
Reference in New Issue
Block a user