First working version of JSON sequence diagram generator

This commit is contained in:
Bartek Kryza
2023-03-19 18:29:45 +01:00
parent e620c86f31
commit f0497e934d
42 changed files with 1165 additions and 56 deletions

View File

@@ -20,59 +20,6 @@
#include "util/error.h"
namespace clanguml::common::model {
using nlohmann::json;
void to_json(nlohmann::json &j, const source_location &sl)
{
j = json{{"file", sl.file_relative()}, {"line", sl.line()}};
}
void to_json(nlohmann::json &j, const element &c)
{
j = json{{"id", std::to_string(c.id())}, {"name", c.name()},
{"namespace", c.get_namespace().to_string()}, {"type", c.type_name()},
{"display_name", c.full_name(false)}};
if (const auto &comment = c.comment(); comment)
j["comment"] = comment.value();
if (!c.file().empty()) {
j["source_location"] =
dynamic_cast<const common::model::source_location &>(c);
}
}
void to_json(nlohmann::json &j, const template_parameter &c)
{
j["kind"] = to_string(c.kind());
if (c.type())
j["type"] = c.type().value();
if (c.name())
j["name"] = c.name().value();
if (c.default_value())
j["default"] = c.default_value().value();
j["is_variadic"] = c.is_variadic();
}
void to_json(nlohmann::json &j, const relationship &c)
{
j["type"] = to_string(c.type());
j["destination"] = std::to_string(c.destination());
if (!c.multiplicity_source().empty())
j["multiplicity_source"] = c.multiplicity_source();
if (!c.multiplicity_destination().empty())
j["multiplicity_destination"] = c.multiplicity_destination();
if (c.access() != access_t::kNone)
j["access"] = to_string(c.access());
if (!c.label().empty())
j["label"] = c.label();
if (const auto &comment = c.comment(); comment)
j["comment"] = comment.value();
}
} // namespace clanguml::common::model
namespace clanguml::class_diagram::model {
using nlohmann::json;
void to_json(nlohmann::json &j, const class_element &c)
@@ -170,6 +117,9 @@ void generator::generate(std::ostream &ostr) const
generate_relationships(json_);
json_["name"] = m_model.name();
json_["diagram_type"] = "class";
ostr << json_;
}

View File

@@ -60,6 +60,8 @@ class generator : public common_generator<diagram_config, diagram_model> {
public:
generator(diagram_config &config, diagram_model &model);
void generate(std::ostream &ostr) const override;
void generate(const class_ &c, nlohmann::json &parent) const;
void generate(const enum_ &c, nlohmann::json &parent) const;
@@ -70,8 +72,6 @@ public:
void generate_top_level_elements(nlohmann::json &parent) const;
void generate(std::ostream &ostr) const override;
void generate_relationships(nlohmann::json &parent) const;
void generate_relationships(const class_ &c, nlohmann::json &parent) const;