Added regex support to parents filter
This commit is contained in:
@@ -24,8 +24,6 @@
|
||||
|
||||
namespace clanguml::config {
|
||||
|
||||
std::string to_string(const std::string &s) { return s; }
|
||||
|
||||
std::string to_string(const hint_t t)
|
||||
{
|
||||
switch (t) {
|
||||
@@ -87,8 +85,6 @@ std::string to_string(method_type mt)
|
||||
}
|
||||
}
|
||||
|
||||
std::string to_string(string_or_regex sr) { return sr.to_string(); }
|
||||
|
||||
std::string to_string(const comment_parser_t cp)
|
||||
{
|
||||
switch (cp) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include "diagram_templates.h"
|
||||
|
||||
namespace YAML {
|
||||
using clanguml::common::namespace_or_regex;
|
||||
using clanguml::common::string_or_regex;
|
||||
using clanguml::common::model::access_t;
|
||||
using clanguml::common::model::relationship_t;
|
||||
using clanguml::config::class_diagram;
|
||||
@@ -35,14 +37,12 @@ using clanguml::config::location_t;
|
||||
using clanguml::config::member_order_t;
|
||||
using clanguml::config::method_arguments;
|
||||
using clanguml::config::method_type;
|
||||
using clanguml::config::namespace_or_regex;
|
||||
using clanguml::config::package_diagram;
|
||||
using clanguml::config::package_type_t;
|
||||
using clanguml::config::plantuml;
|
||||
using clanguml::config::relationship_hint_t;
|
||||
using clanguml::config::sequence_diagram;
|
||||
using clanguml::config::source_location;
|
||||
using clanguml::config::string_or_regex;
|
||||
|
||||
inline bool has_key(const YAML::Node &n, const std::string &key)
|
||||
{
|
||||
|
||||
@@ -18,39 +18,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
namespace clanguml::common::model {
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const namespace_ &n)
|
||||
{
|
||||
out << n.to_string();
|
||||
return out;
|
||||
}
|
||||
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const relationship_t &r)
|
||||
{
|
||||
out << to_string(r);
|
||||
return out;
|
||||
}
|
||||
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const access_t &a)
|
||||
{
|
||||
out << to_string(a);
|
||||
return out;
|
||||
}
|
||||
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const diagram_t &d)
|
||||
{
|
||||
out << to_string(d);
|
||||
return out;
|
||||
}
|
||||
} // namespace clanguml::common::model
|
||||
|
||||
namespace clanguml::config {
|
||||
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const method_type &m)
|
||||
{
|
||||
out << to_string(m);
|
||||
return out;
|
||||
}
|
||||
namespace clanguml::common {
|
||||
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const string_or_regex &m)
|
||||
{
|
||||
@@ -78,6 +46,42 @@ YAML::Emitter &operator<<(YAML::Emitter &out, const namespace_or_regex &m)
|
||||
return out;
|
||||
}
|
||||
|
||||
namespace model {
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const namespace_ &n)
|
||||
{
|
||||
out << n.to_string();
|
||||
return out;
|
||||
}
|
||||
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const relationship_t &r)
|
||||
{
|
||||
out << to_string(r);
|
||||
return out;
|
||||
}
|
||||
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const access_t &a)
|
||||
{
|
||||
out << to_string(a);
|
||||
return out;
|
||||
}
|
||||
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const diagram_t &d)
|
||||
{
|
||||
out << to_string(d);
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace model
|
||||
} // namespace clanguml::common
|
||||
|
||||
namespace clanguml::config {
|
||||
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const method_type &m)
|
||||
{
|
||||
out << to_string(m);
|
||||
return out;
|
||||
}
|
||||
|
||||
YAML::Emitter &operator<<(YAML::Emitter &out, const filter &f)
|
||||
{
|
||||
out << YAML::BeginMap;
|
||||
|
||||
Reference in New Issue
Block a user