32#include <unordered_set>
38using common::model::diagram_element;
40using common::model::element_view;
41using common::model::path;
69 diagram_t
type()
const override;
98 opt_ref<diagram_element>
get(
const std::string &full_name)
const override;
106 opt_ref<diagram_element>
get(
eid_t id)
const override;
136 template <
typename ElementT>
bool contains(
const ElementT &e);
148 template <
typename ElementT>
149 opt_ref<ElementT>
find(
const std::string &
name)
const;
161 template <
typename ElementT>
162 std::vector<opt_ref<ElementT>>
find(
175 template <
typename ElementT> opt_ref<ElementT>
find(
eid_t id)
const;
183 template <
typename ElementT>
198 template <
typename ElementT>
199 bool add(
const path &parent_path, std::unique_ptr<ElementT> &&e)
250 inja::json
context()
const override;
262 template <
typename ElementT>
265 template <
typename ElementT>
269 template <
typename ElementT>
279 const auto &element_opt) {
return element_opt.get() == element; });
282template <
typename ElementT>
285 const auto base_name = e->name();
286 const auto full_name = e->full_name(
false);
287 const auto element_type = e->type_name();
289 LOG_DBG(
"Adding {}: {}::{}, {}", element_type,
290 e->get_namespace().to_string(), base_name, full_name);
293 throw std::runtime_error(
"Name cannot contain namespace: " + base_name);
296 throw std::runtime_error(
"Name cannot contain *: " + base_name);
298 const auto ns = e->get_relative_namespace();
299 auto name = base_name;
300 auto name_with_ns = e->name_and_ns();
301 auto name_and_ns = ns |
name;
303 auto id = e_ref.id();
310 const auto &el = get_element<ElementT>(name_and_ns).value();
312 if ((el.name() !=
name) || !(el.get_relative_namespace() == ns))
313 throw std::runtime_error(
314 "Invalid element stored in the diagram tree");
316 LOG_DBG(
"Added {} {} ({} - [{}])", element_type, base_name,
322 catch (
const std::runtime_error &e) {
323 LOG_WARN(
"Cannot add {} {} with id {} due to: {}", element_type,
name,
328 LOG_DBG(
"{} {} ({} - [{}]) already in the model", element_type, base_name,
334template <
typename ElementT>
338 const auto element_type = e->type_name();
342 for (
auto it = parent_path.
begin(); it != parent_path.
end(); it++) {
343 auto pkg = std::make_unique<common::model::package>(
344 e->using_namespace(), parent_path.
type());
349 pkg->set_namespace(ns);
352 add(ns, std::move(pkg));
355 const auto base_name = e->name();
356 const auto full_name = e->full_name(
false);
367template <
typename ElementT>
371 const auto element_type = e->type_name();
375 for (
auto it = parent_path.
begin(); it != parent_path.
end(); it++) {
376 auto pkg = std::make_unique<common::model::package>(
377 e->using_namespace(), parent_path.
type());
382 pkg->set_namespace(ns);
385 add(ns, std::move(pkg));
388 const auto base_name = e->name();
389 const auto full_name = e->full_name(
false);
400template <
typename ElementT>
404 const auto full_name = element.get().full_name(
false);
406 auto full_name_escaped = full_name;
409 if (
name == full_name ||
name == full_name_escaped) {
417template <
typename ElementT>
421 std::vector<opt_ref<ElementT>> result;
424 const auto full_name = element.get().full_name(
false);
425 auto full_name_escaped = full_name;
428 if (pattern == full_name || pattern == full_name_escaped) {
429 result.emplace_back(element);
439 if (element.get().id() == id) {
447template <
typename ElementT>
457bool diagram::add_with_namespace_path<common::model::package>(
458 std::unique_ptr<common::model::package> &&p);
461bool diagram::add_with_module_path<common::model::package>(
463 std::unique_ptr<common::model::package> &&p);
466bool diagram::add_with_filesystem_path<common::model::package>(
468 std::unique_ptr<common::model::package> &&p);
474bool check_diagram_type<clanguml::class_diagram::model::diagram>(diagram_t t);