Added storing list of using namespace directives for each namespace

This commit is contained in:
Bartek Kryza
2022-03-14 23:23:48 +01:00
parent 1d0bef2085
commit c0a759c2c4
5 changed files with 52 additions and 1 deletions

View File

@@ -185,6 +185,11 @@ bool operator==(const namespace_ &left, const namespace_ &right)
return left.namespace_path_ == right.namespace_path_;
}
bool operator<(const namespace_ &left, const namespace_ &right)
{
return std::hash<namespace_>{}(left) < std::hash<namespace_>{}(right);
}
std::string namespace_::name() const
{
assert(size() > 0);

View File

@@ -23,9 +23,9 @@
namespace clanguml::common::model {
class namespace_ {
public:
using container_type = std::vector<std::string>;
public:
namespace_() = default;
namespace_(const std::string &ns);
@@ -42,6 +42,7 @@ public:
namespace_ &operator=(namespace_ &&right) noexcept = default;
friend bool operator==(const namespace_ &left, const namespace_ &right);
friend bool operator<(const namespace_ &left, const namespace_ &right);
namespace_(std::initializer_list<std::string> ns);
@@ -85,4 +86,23 @@ private:
container_type namespace_path_;
};
}
namespace std {
template <> struct hash<clanguml::common::model::namespace_> {
std::size_t operator()(const clanguml::common::model::namespace_ &key) const
{
using clanguml::common::model::namespace_;
std::size_t seed = key.size();
for (const auto &ns : key) {
seed ^= std::hash<std::string>{}(ns) + 0x6a3712b5 + (seed << 6) +
(seed >> 2);
}
return seed;
}
};
}