Fixed package diagram unique packages generation

This commit is contained in:
Bartek Kryza
2022-01-29 20:50:03 +01:00
parent a1b4a96851
commit 8aec4a4d19
3 changed files with 19 additions and 1 deletions

View File

@@ -21,6 +21,8 @@
#include <map>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
namespace clanguml {
namespace decorators {

View File

@@ -37,7 +37,8 @@ class package_trait {
public:
void add_package(std::unique_ptr<T> p)
{
packages_.emplace_back(std::move(p));
if (!contains(packages_, p.get()))
packages_.emplace_back(std::move(p));
}
void add_package(std::vector<std::string> path, std::unique_ptr<T> p)

View File

@@ -156,4 +156,19 @@ void remove_prefix(std::vector<T> &col, const std::vector<T> &prefix)
col = std::vector<T>(col.begin() + prefix.size(), col.end());
}
template <typename T, typename E>
bool contains(const T &container, const E &element)
{
if constexpr (std::is_pointer_v<E>) {
return std::find_if(container.begin(), container.end(),
[&element](const auto &e) {
return *e == *element;
}) != container.end();
}
else {
return std::find(container.cbegin(), container.cend(), element) !=
container.cend();
}
}
}