Added handling of start_from directive for USR

This commit is contained in:
Bartek Kryza
2021-02-20 15:02:41 +01:00
parent 6e3cc2e03b
commit 501a1f0466
5 changed files with 69 additions and 19 deletions

View File

@@ -4,13 +4,19 @@ diagrams:
main_sequence_diagram: main_sequence_diagram:
type: sequence type: sequence
glob: glob:
- t00001/t00001.cc - src/main.cc
using_namespace: clanguml::t00001 using_namespace:
- ""
start_from: start_from:
file: t00001/t00001.cc - usr: "c:@F@main#I#**1C#"
line: 20 include:
classes: namespace:
- A - clanguml
- B exclude:
puml: namespace:
- 'note top of diagram: Aggregate template' - std
plantuml:
before:
- "' main test sequence diagram"
after:
- "' end"

View File

@@ -31,6 +31,9 @@ struct source_location {
using usr = std::string; using usr = std::string;
using marker = std::string; using marker = std::string;
using file = std::pair<std::string, int>; using file = std::pair<std::string, int>;
// std::variant requires unique types, so we cannot add
// marker here, we need sth like boost::mp_unique
// type function
using variant = std::variant<usr, file>; using variant = std::variant<usr, file>;
}; };
@@ -100,11 +103,27 @@ template <> struct convert<class_diagram> {
} }
}; };
template <> struct convert<source_location::variant> { template <> struct convert<std::vector<source_location::variant>> {
static bool decode(const Node &node, source_location::variant &rhs) static bool decode(
const Node &node, std::vector<source_location::variant> &rhs)
{ {
if(node["usr"]) for (auto it = node.begin(); it != node.end(); ++it) {
rhs = node["usr"].as<source_location::usr>(); const YAML::Node &n = *it;
if (n["usr"]) {
rhs.emplace_back(n["usr"].as<source_location::usr>());
}
else if (n["marker"]) {
rhs.emplace_back(n["marker"].as<source_location::marker>());
}
else if (n["file"] && n["line"]) {
rhs.emplace_back(std::make_pair(
n["file"].as<std::string>(), n["line"].as<int>()));
}
else {
return false;
}
}
return true; return true;
} }
}; };

View File

@@ -19,6 +19,7 @@ namespace puml {
using diagram_model = clanguml::model::sequence_diagram::diagram; using diagram_model = clanguml::model::sequence_diagram::diagram;
using diagram_config = clanguml::config::sequence_diagram::diagram; using diagram_config = clanguml::config::sequence_diagram::diagram;
using clanguml::config::source_location;
using clanguml::model::sequence_diagram::activity; using clanguml::model::sequence_diagram::activity;
using clanguml::model::sequence_diagram::message; using clanguml::model::sequence_diagram::message;
using clanguml::model::sequence_diagram::message_t; using clanguml::model::sequence_diagram::message_t;
@@ -83,14 +84,22 @@ public:
void generate(std::ostream &ostr) const void generate(std::ostream &ostr) const
{ {
auto start_from = "c:@N@clanguml@N@t00001@F@tmain#";
ostr << "@startuml" << std::endl; ostr << "@startuml" << std::endl;
for (const auto &b : m_config.puml.before) for (const auto &b : m_config.puml.before)
ostr << b << std::endl; ostr << b << std::endl;
generate_activity(m_model.sequences[start_from], ostr); for (const auto &sf : m_config.start_from) {
std::string start_from;
if (std::holds_alternative<source_location::usr>(sf)) {
start_from = std::get<source_location::usr>(sf);
}
else {
// TODO: Add support for other sequence start location types
continue;
}
generate_activity(m_model.sequences[start_from], ostr);
}
for (const auto &a : m_config.puml.after) for (const auto &a : m_config.puml.after)
ostr << a << std::endl; ostr << a << std::endl;

View File

@@ -10,7 +10,7 @@ diagrams:
- clanguml::t00001 - clanguml::t00001
exclude: exclude:
namespace: namespace:
- std - clanguml::t00001::detail
using_namespace: using_namespace:
- clanguml::t00001 - clanguml::t00001
start_from: start_from:

View File

@@ -1,13 +1,26 @@
#include <vector>
#include <algorithm> #include <algorithm>
#include <numeric> #include <numeric>
#include <vector>
namespace clanguml { namespace clanguml {
namespace t00001 { namespace t00001 {
namespace detail {
struct C {
auto add(int x, int y)
{
return x + y;
}
};
}
class A { class A {
public: public:
int add(int x, int y) { return x + y; } A()
{
}
int add(int x, int y) { return m_c.add(x, y); }
int add3(int x, int y, int z) int add3(int x, int y, int z)
{ {
@@ -21,6 +34,9 @@ public:
} }
void log_result(int r) {} void log_result(int r) {}
private:
detail::C m_c{};
}; };
class B { class B {