Fixed root namespace handling
This commit is contained in:
@@ -184,6 +184,11 @@ void generator::generate(const class_ &c, std::ostream &ostr) const
|
|||||||
try {
|
try {
|
||||||
destination = r.destination();
|
destination = r.destination();
|
||||||
|
|
||||||
|
// TODO: Refactor destination to a namespace qualified entity
|
||||||
|
// name
|
||||||
|
if (util::starts_with(destination, std::string{"::"}))
|
||||||
|
destination = destination.substr(2, destination.size());
|
||||||
|
|
||||||
LOG_DBG("=== Destination is: {}", destination);
|
LOG_DBG("=== Destination is: {}", destination);
|
||||||
|
|
||||||
std::string puml_relation;
|
std::string puml_relation;
|
||||||
@@ -263,6 +268,11 @@ void generator::generate_relationships(
|
|||||||
try {
|
try {
|
||||||
destination = r.destination();
|
destination = r.destination();
|
||||||
|
|
||||||
|
// TODO: Refactor destination to a namespace qualified entity
|
||||||
|
// name
|
||||||
|
if (util::starts_with(destination, std::string{"::"}))
|
||||||
|
destination = destination.substr(2, destination.size());
|
||||||
|
|
||||||
LOG_DBG("=== Destination is: {}", destination);
|
LOG_DBG("=== Destination is: {}", destination);
|
||||||
|
|
||||||
std::string puml_relation;
|
std::string puml_relation;
|
||||||
@@ -402,7 +412,7 @@ void generator::generate(const package &p, std::ostream &ostr) const
|
|||||||
|
|
||||||
// Don't generate packages from namespaces filtered out by
|
// Don't generate packages from namespaces filtered out by
|
||||||
// using_namespace
|
// using_namespace
|
||||||
if (!uns.starts_with(p.full_name(false))) {
|
if (!uns.starts_with({p.full_name(false)})) {
|
||||||
ostr << "package [" << p.name() << "] ";
|
ostr << "package [" << p.name() << "] ";
|
||||||
ostr << "as " << p.alias();
|
ostr << "as " << p.alias();
|
||||||
|
|
||||||
@@ -440,7 +450,7 @@ void generator::generate(const package &p, std::ostream &ostr) const
|
|||||||
if (m_config.generate_packages()) {
|
if (m_config.generate_packages()) {
|
||||||
// Don't generate packages from namespaces filtered out by
|
// Don't generate packages from namespaces filtered out by
|
||||||
// using_namespace
|
// using_namespace
|
||||||
if (!uns.starts_with(p.full_name(false))) {
|
if (!uns.starts_with({p.full_name(false)})) {
|
||||||
ostr << "}" << '\n';
|
ostr << "}" << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -594,12 +594,12 @@ void translation_unit_visitor::process_class_bases(
|
|||||||
{
|
{
|
||||||
for (auto &base : cls.bases()) {
|
for (auto &base : cls.bases()) {
|
||||||
class_parent cp;
|
class_parent cp;
|
||||||
auto base_ns = common::model::namespace_{
|
auto ns = cx::util::ns(base.type(), ctx.entity_index());
|
||||||
cx::util::ns(base.type(), ctx.entity_index())};
|
common::model::namespace_ base_ns;
|
||||||
|
if(!ns.empty())
|
||||||
|
base_ns = common::model::namespace_{ns};
|
||||||
base_ns = base_ns | common::model::namespace_{base.name()}.name();
|
base_ns = base_ns | common::model::namespace_{base.name()}.name();
|
||||||
cp.set_name(
|
cp.set_name(base_ns.to_string());
|
||||||
// base_ns.relative_to(ctx.config().using_namespace()).to_string());
|
|
||||||
base_ns.to_string());
|
|
||||||
cp.is_virtual(base.is_virtual());
|
cp.is_virtual(base.is_virtual());
|
||||||
|
|
||||||
switch (base.access_specifier()) {
|
switch (base.access_specifier()) {
|
||||||
@@ -758,7 +758,7 @@ bool translation_unit_visitor::process_field_with_template_instantiation(
|
|||||||
auto [decorator_rtype, decorator_rmult] = member.get_relationship();
|
auto [decorator_rtype, decorator_rmult] = member.get_relationship();
|
||||||
if (decorator_rtype != relationship_t::kNone) {
|
if (decorator_rtype != relationship_t::kNone) {
|
||||||
rr.set_type(decorator_rtype);
|
rr.set_type(decorator_rtype);
|
||||||
auto mult = util::split(decorator_rmult, ":");
|
auto mult = util::split(decorator_rmult, ":", false);
|
||||||
if (mult.size() == 2) {
|
if (mult.size() == 2) {
|
||||||
rr.set_multiplicity_source(mult[0]);
|
rr.set_multiplicity_source(mult[0]);
|
||||||
rr.set_multiplicity_destination(mult[1]);
|
rr.set_multiplicity_destination(mult[1]);
|
||||||
@@ -811,6 +811,8 @@ bool translation_unit_visitor::add_nested_template_relationships(
|
|||||||
template_argument.find_nested_relationships(nested_relationships,
|
template_argument.find_nested_relationships(nested_relationships,
|
||||||
relationship_type,
|
relationship_type,
|
||||||
[&d = ctx.diagram()](const std::string &full_name) {
|
[&d = ctx.diagram()](const std::string &full_name) {
|
||||||
|
if(full_name.empty())
|
||||||
|
return false;
|
||||||
auto [ns, name] = cx::util::split_ns(full_name);
|
auto [ns, name] = cx::util::split_ns(full_name);
|
||||||
return d.should_include(ns, name);
|
return d.should_include(ns, name);
|
||||||
});
|
});
|
||||||
@@ -823,7 +825,7 @@ bool translation_unit_visitor::add_nested_template_relationships(
|
|||||||
nested_relationship.set_style(m.style_spec());
|
nested_relationship.set_style(m.style_spec());
|
||||||
if (decorator_rtype != relationship_t::kNone) {
|
if (decorator_rtype != relationship_t::kNone) {
|
||||||
nested_relationship.set_type(decorator_rtype);
|
nested_relationship.set_type(decorator_rtype);
|
||||||
auto mult = util::split(decorator_rmult, ":");
|
auto mult = util::split(decorator_rmult, ":", false);
|
||||||
if (mult.size() == 2) {
|
if (mult.size() == 2) {
|
||||||
nested_relationship.set_multiplicity_source(mult[0]);
|
nested_relationship.set_multiplicity_source(mult[0]);
|
||||||
nested_relationship.set_multiplicity_destination(mult[1]);
|
nested_relationship.set_multiplicity_destination(mult[1]);
|
||||||
@@ -914,7 +916,7 @@ void translation_unit_visitor::process_field(
|
|||||||
auto [decorator_rtype, decorator_rmult] = m.get_relationship();
|
auto [decorator_rtype, decorator_rmult] = m.get_relationship();
|
||||||
if (decorator_rtype != relationship_t::kNone) {
|
if (decorator_rtype != relationship_t::kNone) {
|
||||||
r.set_type(decorator_rtype);
|
r.set_type(decorator_rtype);
|
||||||
auto mult = util::split(decorator_rmult, ":");
|
auto mult = util::split(decorator_rmult, ":", false);
|
||||||
if (mult.size() == 2) {
|
if (mult.size() == 2) {
|
||||||
r.set_multiplicity_source(mult[0]);
|
r.set_multiplicity_source(mult[0]);
|
||||||
r.set_multiplicity_destination(mult[1]);
|
r.set_multiplicity_destination(mult[1]);
|
||||||
|
|||||||
@@ -31,7 +31,13 @@ public:
|
|||||||
|
|
||||||
path() = default;
|
path() = default;
|
||||||
|
|
||||||
path(const std::string &ns) { path_ = util::split(ns, Sep::value); }
|
explicit path(const std::string &ns)
|
||||||
|
{
|
||||||
|
if (ns.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
path_ = util::split(ns, Sep::value);
|
||||||
|
}
|
||||||
|
|
||||||
path(container_type::const_iterator begin,
|
path(container_type::const_iterator begin,
|
||||||
container_type::const_iterator end)
|
container_type::const_iterator end)
|
||||||
@@ -49,16 +55,22 @@ public:
|
|||||||
|
|
||||||
path(std::initializer_list<std::string> ns)
|
path(std::initializer_list<std::string> ns)
|
||||||
{
|
{
|
||||||
if ((ns.size() == 1) && util::contains(*ns.begin(), Sep::value))
|
if ((ns.size() == 1) && util::contains(*ns.begin(), Sep::value)) {
|
||||||
path_ = util::split(*ns.begin(), Sep::value);
|
path_ = util::split(*ns.begin(), Sep::value);
|
||||||
|
}
|
||||||
|
else if ((ns.size() == 1) && ns.begin()->empty()) {
|
||||||
|
}
|
||||||
else
|
else
|
||||||
path_ = ns;
|
path_ = ns;
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit path(const std::vector<std::string> &ns)
|
explicit path(const std::vector<std::string> &ns)
|
||||||
{
|
{
|
||||||
if ((ns.size() == 1) && util::contains(*ns.begin(), Sep::value))
|
if ((ns.size() == 1) && util::contains(*ns.begin(), Sep::value)) {
|
||||||
path_ = util::split(*ns.begin(), Sep::value);
|
path_ = util::split(*ns.begin(), Sep::value);
|
||||||
|
}
|
||||||
|
else if ((ns.size() == 1) && ns.begin()->empty()) {
|
||||||
|
}
|
||||||
else
|
else
|
||||||
path_ = ns;
|
path_ = ns;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
|
|
||||||
source_file(const std::filesystem::path &p)
|
source_file(const std::filesystem::path &p)
|
||||||
{
|
{
|
||||||
set_path(p.parent_path().string());
|
set_path({p.parent_path().string()});
|
||||||
set_name(p.filename());
|
set_name(p.filename());
|
||||||
is_absolute_ = p.is_absolute();
|
is_absolute_ = p.is_absolute();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,10 +215,10 @@ void get_option<clanguml::common::model::namespace_>(const Node &node,
|
|||||||
{
|
{
|
||||||
if (node[option.name]) {
|
if (node[option.name]) {
|
||||||
if (node[option.name].Type() == NodeType::Scalar)
|
if (node[option.name].Type() == NodeType::Scalar)
|
||||||
option.set(node[option.name].template as<std::string>());
|
option.set({node[option.name].template as<std::string>()});
|
||||||
else if (node[option.name].Type() == NodeType::Sequence)
|
else if (node[option.name].Type() == NodeType::Sequence)
|
||||||
option.set(
|
option.set({
|
||||||
node[option.name].template as<std::vector<std::string>>()[0]);
|
node[option.name].template as<std::vector<std::string>>()[0]});
|
||||||
else
|
else
|
||||||
throw std::runtime_error("Invalid using_namespace value");
|
throw std::runtime_error("Invalid using_namespace value");
|
||||||
}
|
}
|
||||||
@@ -406,7 +406,7 @@ template <> struct convert<filter> {
|
|||||||
auto namespace_list =
|
auto namespace_list =
|
||||||
node["namespaces"].as<std::vector<std::string>>();
|
node["namespaces"].as<std::vector<std::string>>();
|
||||||
for (const auto &ns : namespace_list)
|
for (const auto &ns : namespace_list)
|
||||||
rhs.namespaces.push_back(ns);
|
rhs.namespaces.push_back({ns});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node["relationships"])
|
if (node["relationships"])
|
||||||
|
|||||||
@@ -129,6 +129,8 @@ bool is_inside_class(const cppast::cpp_entity &e)
|
|||||||
std::pair<common::model::namespace_, std::string> split_ns(
|
std::pair<common::model::namespace_, std::string> split_ns(
|
||||||
const std::string &full_name)
|
const std::string &full_name)
|
||||||
{
|
{
|
||||||
|
assert(!full_name.empty());
|
||||||
|
|
||||||
auto name_before_template = ::clanguml::util::split(full_name, "<")[0];
|
auto name_before_template = ::clanguml::util::split(full_name, "<")[0];
|
||||||
auto ns = common::model::namespace_{
|
auto ns = common::model::namespace_{
|
||||||
::clanguml::util::split(name_before_template, "::")};
|
::clanguml::util::split(name_before_template, "::")};
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ void generator::generate(const package &p, std::ostream &ostr) const
|
|||||||
|
|
||||||
// Don't generate packages from namespaces filtered out by
|
// Don't generate packages from namespaces filtered out by
|
||||||
// using_namespace
|
// using_namespace
|
||||||
if (!uns.starts_with(p.full_name(false))) {
|
if (!uns.starts_with({p.full_name(false)})) {
|
||||||
ostr << "package [" << p.name() << "] ";
|
ostr << "package [" << p.name() << "] ";
|
||||||
ostr << "as " << p.alias();
|
ostr << "as " << p.alias();
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ void generator::generate(const package &p, std::ostream &ostr) const
|
|||||||
generate(dynamic_cast<const package &>(*subpackage), ostr);
|
generate(dynamic_cast<const package &>(*subpackage), ostr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!uns.starts_with(p.full_name(false))) {
|
if (!uns.starts_with({p.full_name(false)})) {
|
||||||
ostr << "}" << '\n';
|
ostr << "}" << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,8 @@ std::string rtrim(const std::string &s)
|
|||||||
|
|
||||||
std::string trim(const std::string &s) { return rtrim(ltrim(s)); }
|
std::string trim(const std::string &s) { return rtrim(ltrim(s)); }
|
||||||
|
|
||||||
std::vector<std::string> split(std::string str, std::string_view delimiter)
|
std::vector<std::string> split(
|
||||||
|
std::string str, std::string_view delimiter, bool skip_empty)
|
||||||
{
|
{
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
|
|
||||||
@@ -146,11 +147,13 @@ std::vector<std::string> split(std::string str, std::string_view delimiter)
|
|||||||
while (str.size()) {
|
while (str.size()) {
|
||||||
auto index = str.find(delimiter);
|
auto index = str.find(delimiter);
|
||||||
if (index != std::string::npos) {
|
if (index != std::string::npos) {
|
||||||
result.push_back(str.substr(0, index));
|
auto tok = str.substr(0, index);
|
||||||
|
if (!tok.empty() || !skip_empty)
|
||||||
|
result.push_back(std::move(tok));
|
||||||
str = str.substr(index + delimiter.size());
|
str = str.substr(index + delimiter.size());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!str.empty())
|
if (!str.empty() || !skip_empty)
|
||||||
result.push_back(str);
|
result.push_back(str);
|
||||||
str = "";
|
str = "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,10 +83,12 @@ std::string get_git_toplevel_dir();
|
|||||||
*
|
*
|
||||||
* @param str String to split
|
* @param str String to split
|
||||||
* @param delimiter Delimiter string
|
* @param delimiter Delimiter string
|
||||||
|
* @param skip_empty Skip empty toks between delimiters if true
|
||||||
*
|
*
|
||||||
* @return Vector of string tokens.
|
* @return Vector of string tokens.
|
||||||
*/
|
*/
|
||||||
std::vector<std::string> split(std::string str, std::string_view delimiter);
|
std::vector<std::string> split(
|
||||||
|
std::string str, std::string_view delimiter, bool skip_empty = true);
|
||||||
|
|
||||||
std::string join(
|
std::string join(
|
||||||
const std::vector<std::string> &toks, std::string_view delimiter);
|
const std::vector<std::string> &toks, std::string_view delimiter);
|
||||||
|
|||||||
Reference in New Issue
Block a user