Added initial support for directory based packages in class diagrams
This commit is contained in:
@@ -39,7 +39,7 @@ public:
|
||||
|
||||
virtual diagram_t type() const = 0;
|
||||
|
||||
virtual common::optional_ref<clanguml::common::model::diagram_element> get(
|
||||
virtual opt_ref<clanguml::common::model::diagram_element> get(
|
||||
const std::string &full_name) const = 0;
|
||||
|
||||
virtual common::optional_ref<clanguml::common::model::diagram_element> get(
|
||||
|
||||
@@ -430,8 +430,8 @@ paths_filter::paths_filter(filter_t type, const std::filesystem::path &root,
|
||||
absolute_path = path;
|
||||
|
||||
try {
|
||||
absolute_path =
|
||||
std::filesystem::canonical(absolute_path.lexically_normal());
|
||||
absolute_path = absolute(absolute_path);
|
||||
absolute_path = canonical(absolute_path.lexically_normal());
|
||||
}
|
||||
catch (std::filesystem::filesystem_error &e) {
|
||||
LOG_WARN("Cannot add non-existent path {} to paths filter",
|
||||
@@ -539,7 +539,7 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
filter_t::kInclusive, c.include().access));
|
||||
|
||||
add_inclusive_filter(std::make_unique<paths_filter>(
|
||||
filter_t::kInclusive, c.relative_to(), c.include().paths));
|
||||
filter_t::kInclusive, c.root_directory(), c.include().paths));
|
||||
|
||||
// Include any of these matches even if one them does not match
|
||||
std::vector<std::unique_ptr<filter_visitor>> element_filters;
|
||||
@@ -623,7 +623,7 @@ void diagram_filter::init_filters(const config::diagram &c)
|
||||
filter_t::kExclusive, c.exclude().namespaces));
|
||||
|
||||
add_exclusive_filter(std::make_unique<paths_filter>(
|
||||
filter_t::kExclusive, c.relative_to(), c.exclude().paths));
|
||||
filter_t::kExclusive, c.root_directory(), c.exclude().paths));
|
||||
|
||||
add_exclusive_filter(std::make_unique<element_filter>(
|
||||
filter_t::kExclusive, c.exclude().elements));
|
||||
|
||||
@@ -29,7 +29,7 @@ struct ns_path_separator {
|
||||
static constexpr std::string_view value = "::";
|
||||
};
|
||||
|
||||
using namespace_ = path<ns_path_separator>;
|
||||
using namespace_ = path;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "common/model/element.h"
|
||||
#include "common/model/nested_trait.h"
|
||||
#include "common/model/path.h"
|
||||
#include "common/model/stylable_element.h"
|
||||
#include "common/types.h"
|
||||
#include "util/util.h"
|
||||
@@ -33,9 +34,9 @@ namespace clanguml::common::model {
|
||||
|
||||
class package : public element,
|
||||
public stylable_element,
|
||||
public nested_trait<element, namespace_> {
|
||||
public nested_trait<element, path> {
|
||||
public:
|
||||
package(const common::model::namespace_ &using_namespace);
|
||||
package(const common::model::path &using_namespace);
|
||||
|
||||
package(const package &) = delete;
|
||||
package(package &&) = default;
|
||||
|
||||
@@ -25,41 +25,84 @@
|
||||
|
||||
namespace clanguml::common::model {
|
||||
|
||||
template <typename Sep> class path {
|
||||
enum class path_type { kNamespace, kFilesystem };
|
||||
|
||||
class path {
|
||||
|
||||
const char *separator() const
|
||||
{
|
||||
switch (path_type_) {
|
||||
case path_type::kNamespace:
|
||||
return "::";
|
||||
case path_type::kFilesystem:
|
||||
#ifdef _WIN32
|
||||
return "\\";
|
||||
#else
|
||||
return "/";
|
||||
#endif
|
||||
}
|
||||
|
||||
return "::";
|
||||
}
|
||||
|
||||
public:
|
||||
using container_type = std::vector<std::string>;
|
||||
|
||||
path() = default;
|
||||
path(path_type pt = path_type::kNamespace)
|
||||
: path_type_{pt}
|
||||
{
|
||||
}
|
||||
|
||||
explicit path(const std::string &ns)
|
||||
path(const std::string &ns, path_type pt = path_type::kNamespace)
|
||||
: path_type_{pt}
|
||||
{
|
||||
if (ns.empty())
|
||||
return;
|
||||
|
||||
path_ = util::split(ns, Sep::value);
|
||||
path_ = util::split(ns, separator());
|
||||
}
|
||||
|
||||
virtual ~path() = default;
|
||||
|
||||
path(container_type::const_iterator begin,
|
||||
container_type::const_iterator end)
|
||||
container_type::const_iterator end,
|
||||
path_type pt = path_type::kNamespace)
|
||||
: path(pt)
|
||||
{
|
||||
if (begin == end)
|
||||
return;
|
||||
|
||||
std::copy(begin, end, std::back_inserter(path_));
|
||||
}
|
||||
|
||||
path(const path &right)
|
||||
: path_{right.path_}
|
||||
: path_type_{right.path_type_}
|
||||
, path_{right.path_}
|
||||
{
|
||||
}
|
||||
|
||||
path &operator=(const path &right) = default;
|
||||
path &operator=(const path &right)
|
||||
{
|
||||
if (path_type_ != right.path_type_)
|
||||
throw std::runtime_error("");
|
||||
|
||||
path_type_ = right.path_type_;
|
||||
path_ = right.path_;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
path(path &&right) noexcept = default;
|
||||
|
||||
path &operator=(path &&right) noexcept = default;
|
||||
|
||||
path(std::initializer_list<std::string> ns)
|
||||
path(std::initializer_list<std::string> ns,
|
||||
path_type pt = path_type::kNamespace)
|
||||
: path(pt)
|
||||
{
|
||||
if ((ns.size() == 1) && util::contains(*ns.begin(), Sep::value)) {
|
||||
path_ = util::split(*ns.begin(), Sep::value);
|
||||
if ((ns.size() == 1) &&
|
||||
util::contains(*ns.begin(), std::string{separator()})) {
|
||||
path_ = util::split(*ns.begin(), separator());
|
||||
}
|
||||
else if ((ns.size() == 1) && ns.begin()->empty()) {
|
||||
}
|
||||
@@ -67,10 +110,13 @@ public:
|
||||
path_ = ns;
|
||||
}
|
||||
|
||||
explicit path(const std::vector<std::string> &ns)
|
||||
explicit path(const std::vector<std::string> &ns,
|
||||
path_type pt = path_type::kNamespace)
|
||||
: path(pt)
|
||||
{
|
||||
if ((ns.size() == 1) && util::contains(*ns.begin(), Sep::value)) {
|
||||
path_ = util::split(*ns.begin(), Sep::value);
|
||||
if ((ns.size() == 1) &&
|
||||
util::contains(*ns.begin(), std::string{separator()})) {
|
||||
path_ = util::split(*ns.begin(), separator());
|
||||
}
|
||||
else if ((ns.size() == 1) && ns.begin()->empty()) {
|
||||
}
|
||||
@@ -78,19 +124,19 @@ public:
|
||||
path_ = ns;
|
||||
}
|
||||
|
||||
friend bool operator==(const path<Sep> &left, const path<Sep> &right)
|
||||
friend bool operator==(const path &left, const path &right)
|
||||
{
|
||||
return left.path_ == right.path_;
|
||||
}
|
||||
|
||||
friend bool operator<(const path<Sep> &left, const path<Sep> &right)
|
||||
friend bool operator<(const path &left, const path &right)
|
||||
{
|
||||
return std::hash<path<Sep>>{}(left) < std::hash<path<Sep>>{}(right);
|
||||
return left.to_string() < right.to_string();
|
||||
}
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
return fmt::format("{}", fmt::join(path_, Sep::value));
|
||||
return fmt::format("{}", fmt::join(path_, std::string{separator()}));
|
||||
}
|
||||
|
||||
bool is_empty() const { return path_.empty(); }
|
||||
@@ -190,7 +236,7 @@ public:
|
||||
return name;
|
||||
|
||||
auto res = name;
|
||||
auto ns_prefix = to_string() + std::string{Sep::value};
|
||||
auto ns_prefix = to_string() + std::string{separator()};
|
||||
|
||||
auto it = res.find(ns_prefix);
|
||||
while (it != std::string::npos) {
|
||||
@@ -220,7 +266,10 @@ public:
|
||||
path::container_type::const_iterator begin() const { return path_.begin(); }
|
||||
path::container_type::const_iterator end() const { return path_.end(); }
|
||||
|
||||
path_type type() const { return path_type_; }
|
||||
|
||||
private:
|
||||
path_type path_type_;
|
||||
container_type path_;
|
||||
};
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ struct fs_path_sep {
|
||||
#endif
|
||||
};
|
||||
|
||||
using filesystem_path = common::model::path<fs_path_sep>;
|
||||
using filesystem_path = common::model::path;
|
||||
|
||||
class source_file
|
||||
: public common::model::diagram_element,
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
{
|
||||
auto preferred = p;
|
||||
preferred.make_preferred();
|
||||
set_path({preferred.parent_path().string()});
|
||||
set_path({preferred.parent_path().string(), path_type::kFilesystem});
|
||||
set_name(preferred.filename().string());
|
||||
is_absolute_ = preferred.is_absolute();
|
||||
set_id(common::to_id(preferred));
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
filesystem_path path_;
|
||||
filesystem_path path_{path_type::kFilesystem};
|
||||
source_file_t type_{source_file_t::kDirectory};
|
||||
bool is_absolute_{false};
|
||||
};
|
||||
@@ -134,21 +134,24 @@ private:
|
||||
|
||||
namespace std {
|
||||
|
||||
template <> struct hash<clanguml::common::model::filesystem_path> {
|
||||
std::size_t operator()(
|
||||
const clanguml::common::model::filesystem_path &key) const
|
||||
{
|
||||
using clanguml::common::model::path;
|
||||
/*
|
||||
template <> struct hash<clanguml::common::model::filesystem_path> {
|
||||
std::size_t operator()(
|
||||
const clanguml::common::model::filesystem_path &key) const
|
||||
{
|
||||
using clanguml::common::model::path;
|
||||
|
||||
std::size_t seed = key.size();
|
||||
for (const auto &ns : key) {
|
||||
seed ^=
|
||||
std::hash<std::string>{}(ns) + clanguml::util::hash_seed(seed);
|
||||
}
|
||||
std::size_t seed = key.size();
|
||||
for (const auto &ns : key) {
|
||||
seed ^=
|
||||
std::hash<std::string>{}(ns) +
|
||||
clanguml::util::hash_seed(seed);
|
||||
}
|
||||
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
} // namespace std
|
||||
|
||||
|
||||
@@ -129,6 +129,8 @@ private:
|
||||
T *value_{nullptr};
|
||||
};
|
||||
|
||||
template <typename T> using opt_ref = optional_ref<T>;
|
||||
|
||||
template <typename T>
|
||||
using reference_vector = std::vector<std::reference_wrapper<T>>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user