Initial refactor of namespace handling
This commit is contained in:
@@ -24,8 +24,8 @@
|
||||
|
||||
namespace clanguml::class_diagram::model {
|
||||
|
||||
class_::class_(const std::vector<std::string> &using_namespaces)
|
||||
: element{using_namespaces}
|
||||
class_::class_(const common::model::namespace_ &using_namespace)
|
||||
: element{using_namespace}
|
||||
{
|
||||
}
|
||||
|
||||
@@ -112,10 +112,12 @@ std::string class_::full_name_no_ns() const
|
||||
std::string class_::full_name(bool relative) const
|
||||
{
|
||||
using namespace clanguml::util;
|
||||
using clanguml::common::model::namespace_;
|
||||
|
||||
std::ostringstream ostr;
|
||||
if (relative && starts_with(get_namespace(), using_namespace()))
|
||||
ostr << ns_relative(using_namespace(), name_and_ns());
|
||||
// if (relative && starts_with(get_namespace(), using_namespace()))
|
||||
if (relative)
|
||||
ostr << namespace_{name()}.relative_to(using_namespace()).to_string();
|
||||
else
|
||||
ostr << name_and_ns();
|
||||
|
||||
@@ -126,6 +128,8 @@ std::string class_::full_name(bool relative) const
|
||||
std::ostringstream &class_::render_template_params(
|
||||
std::ostringstream &ostr) const
|
||||
{
|
||||
using clanguml::common::model::namespace_;
|
||||
|
||||
if (!templates_.empty()) {
|
||||
std::vector<std::string> tnames;
|
||||
std::transform(templates_.cbegin(), templates_.cend(),
|
||||
@@ -133,12 +137,14 @@ std::ostringstream &class_::render_template_params(
|
||||
std::vector<std::string> res;
|
||||
|
||||
if (!tmplt.type().empty())
|
||||
res.push_back(
|
||||
util::ns_relative(using_namespace(), tmplt.type()));
|
||||
res.push_back(namespace_{tmplt.type()}
|
||||
.relative_to(using_namespace())
|
||||
.to_string());
|
||||
|
||||
if (!tmplt.name().empty())
|
||||
res.push_back(
|
||||
util::ns_relative(using_namespace(), tmplt.name()));
|
||||
res.push_back(namespace_{tmplt.name()}
|
||||
.relative_to(using_namespace())
|
||||
.to_string());
|
||||
|
||||
if (!tmplt.default_value().empty()) {
|
||||
res.push_back("=");
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace clanguml::class_diagram::model {
|
||||
class class_ : public common::model::element,
|
||||
public common::model::stylable_element {
|
||||
public:
|
||||
class_(const std::vector<std::string> &using_namespaces);
|
||||
class_(const common::model::namespace_ &using_namespace);
|
||||
|
||||
class_(const class_ &) = delete;
|
||||
class_(class_ &&) noexcept = delete;
|
||||
|
||||
@@ -82,7 +82,7 @@ void diagram::add_class(std::unique_ptr<class_> &&c)
|
||||
auto ns = c->get_relative_namespace();
|
||||
auto name = c->name();
|
||||
add_element(ns, std::move(c));
|
||||
ns.push_back(name);
|
||||
ns |= name;
|
||||
const auto ccc = get_element<class_>(ns);
|
||||
assert(ccc.value().name() == name);
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
namespace clanguml::class_diagram::model {
|
||||
|
||||
enum_::enum_(const std::vector<std::string> &using_namespaces)
|
||||
: element{using_namespaces}
|
||||
enum_::enum_(const common::model::namespace_ &using_namespace)
|
||||
: element{using_namespace}
|
||||
{
|
||||
}
|
||||
|
||||
@@ -37,10 +37,11 @@ bool operator==(const enum_ &l, const enum_ &r)
|
||||
std::string enum_::full_name(bool relative) const
|
||||
{
|
||||
using namespace clanguml::util;
|
||||
using clanguml::common::model::namespace_;
|
||||
|
||||
std::ostringstream ostr;
|
||||
if (relative)
|
||||
ostr << ns_relative(using_namespace(), name());
|
||||
ostr << namespace_{name()}.relative_to(using_namespace()).to_string();
|
||||
else
|
||||
ostr << name();
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace clanguml::class_diagram::model {
|
||||
class enum_ : public common::model::element,
|
||||
public common::model::stylable_element {
|
||||
public:
|
||||
enum_(const std::vector<std::string> &using_namespaces);
|
||||
enum_(const common::model::namespace_ &using_namespaces);
|
||||
|
||||
enum_(const enum_ &) = delete;
|
||||
enum_(enum_ &&) = default;
|
||||
|
||||
@@ -38,14 +38,16 @@ void method_parameter::set_default_value(const std::string &value)
|
||||
std::string method_parameter::default_value() const { return default_value_; }
|
||||
|
||||
std::string method_parameter::to_string(
|
||||
const std::vector<std::string> &using_namespaces) const
|
||||
const common::model::namespace_ &using_namespace) const
|
||||
{
|
||||
using namespace clanguml::util;
|
||||
auto t = ns_relative(using_namespaces, type());
|
||||
auto type_ns = common::model::namespace_{type()}
|
||||
.relative_to(using_namespace)
|
||||
.to_string();
|
||||
if (default_value().empty())
|
||||
return fmt::format("{} {}", t, name());
|
||||
return fmt::format("{} {}", type_ns, name());
|
||||
|
||||
return fmt::format("{} {} = {}", t, name(), default_value());
|
||||
return fmt::format("{} {} = {}", type_ns, name(), default_value());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "common/model/decorated_element.h"
|
||||
#include "common/model/namespace.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -36,7 +37,7 @@ public:
|
||||
std::string default_value() const;
|
||||
|
||||
std::string to_string(
|
||||
const std::vector<std::string> &using_namespaces) const;
|
||||
const common::model::namespace_ &using_namespaces) const;
|
||||
|
||||
private:
|
||||
std::string type_;
|
||||
|
||||
Reference in New Issue
Block a user