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:
type: sequence
glob:
- t00001/t00001.cc
using_namespace: clanguml::t00001
- src/main.cc
using_namespace:
- ""
start_from:
file: t00001/t00001.cc
line: 20
classes:
- A
- B
puml:
- 'note top of diagram: Aggregate template'
- usr: "c:@F@main#I#**1C#"
include:
namespace:
- clanguml
exclude:
namespace:
- std
plantuml:
before:
- "' main test sequence diagram"
after:
- "' end"

View File

@@ -31,6 +31,9 @@ struct source_location {
using usr = std::string;
using marker = std::string;
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>;
};
@@ -100,11 +103,27 @@ template <> struct convert<class_diagram> {
}
};
template <> struct convert<source_location::variant> {
static bool decode(const Node &node, source_location::variant &rhs)
template <> struct convert<std::vector<source_location::variant>> {
static bool decode(
const Node &node, std::vector<source_location::variant> &rhs)
{
if(node["usr"])
rhs = node["usr"].as<source_location::usr>();
for (auto it = node.begin(); it != node.end(); ++it) {
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;
}
};

View File

@@ -19,6 +19,7 @@ namespace puml {
using diagram_model = clanguml::model::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::message;
using clanguml::model::sequence_diagram::message_t;
@@ -83,14 +84,22 @@ public:
void generate(std::ostream &ostr) const
{
auto start_from = "c:@N@clanguml@N@t00001@F@tmain#";
ostr << "@startuml" << std::endl;
for (const auto &b : m_config.puml.before)
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)
ostr << a << std::endl;

View File

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

View File

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