Added regex support to parents filter
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "class_diagram/model/diagram.h"
|
||||
#include "common/model/enums.h"
|
||||
#include "common/types.h"
|
||||
#include "option.h"
|
||||
#include "util/util.h"
|
||||
|
||||
@@ -36,80 +37,6 @@
|
||||
namespace clanguml {
|
||||
namespace config {
|
||||
|
||||
std::string to_string(const std::string &s);
|
||||
|
||||
/**
|
||||
* @brief Wrapper around std::regex, which contains original pattern
|
||||
*/
|
||||
struct regex {
|
||||
regex(std::regex r, std::string p)
|
||||
: regexp{std::move(r)}
|
||||
, pattern{std::move(p)}
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] bool operator==(const std::string &v) const
|
||||
{
|
||||
return std::regex_match(v, regexp);
|
||||
}
|
||||
|
||||
std::regex regexp;
|
||||
std::string pattern;
|
||||
};
|
||||
|
||||
template <typename T> struct or_regex {
|
||||
or_regex() = default;
|
||||
|
||||
or_regex(T v)
|
||||
: value_{std::move(v)}
|
||||
{
|
||||
}
|
||||
|
||||
or_regex(std::regex r, std::string p)
|
||||
: value_{regex{std::move(r), std::move(p)}}
|
||||
{
|
||||
}
|
||||
|
||||
or_regex &operator=(const T &v)
|
||||
{
|
||||
value_ = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
or_regex &operator=(const regex &v)
|
||||
{
|
||||
value_ = v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool operator==(const T &v) const
|
||||
{
|
||||
if (std::holds_alternative<regex>(value_))
|
||||
return std::regex_match(v, std::get<regex>(value_).regexp);
|
||||
|
||||
return std::get<T>(value_) == v;
|
||||
}
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
if (std::holds_alternative<regex>(value_))
|
||||
return std::get<regex>(value_).pattern;
|
||||
|
||||
return clanguml::config::to_string(std::get<T>(value_));
|
||||
}
|
||||
|
||||
const std::variant<T, regex> &value() const { return value_; }
|
||||
|
||||
private:
|
||||
std::variant<T, regex> value_;
|
||||
};
|
||||
|
||||
using string_or_regex = or_regex<std::string>;
|
||||
|
||||
std::string to_string(string_or_regex sr);
|
||||
|
||||
using namespace_or_regex = or_regex<common::model::namespace_>;
|
||||
|
||||
enum class method_arguments { full, abbreviated, none };
|
||||
|
||||
enum class method_type {
|
||||
@@ -148,9 +75,9 @@ struct diagram_template {
|
||||
};
|
||||
|
||||
struct filter {
|
||||
std::vector<namespace_or_regex> namespaces;
|
||||
std::vector<common::namespace_or_regex> namespaces;
|
||||
|
||||
std::vector<string_or_regex> elements;
|
||||
std::vector<common::string_or_regex> elements;
|
||||
|
||||
// E.g.:
|
||||
// - class
|
||||
@@ -170,9 +97,9 @@ struct filter {
|
||||
// - private
|
||||
std::vector<common::model::access_t> access;
|
||||
|
||||
std::vector<string_or_regex> subclasses;
|
||||
std::vector<common::string_or_regex> subclasses;
|
||||
|
||||
std::vector<std::string> parents;
|
||||
std::vector<common::string_or_regex> parents;
|
||||
|
||||
std::vector<std::string> specializations;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user