33#include <unordered_set>
39using common::model::diagram_element;
41using common::model::eid_t;
42using common::model::element_view;
43using common::model::element_views;
44using common::model::path;
55 public element_views<class_, enum_, concept_, objc_interface>,
72 diagram_t
type()
const override;
103 opt_ref<diagram_element>
get(
const std::string &full_name)
const override;
111 opt_ref<diagram_element>
get(eid_t
id)
const override;
143 template <
typename ElementT>
bool contains(
const ElementT &e);
155 template <
typename ElementT>
156 opt_ref<ElementT>
find(
const std::string &
name)
const;
168 template <
typename ElementT>
169 std::vector<opt_ref<ElementT>>
find(
182 template <
typename ElementT> opt_ref<ElementT>
find(eid_t
id)
const;
190 template <
typename ElementT>
205 template <
typename ElementT>
206 bool add(
const path &parent_path, std::unique_ptr<ElementT> &&e)
219 template <
typename ElementT>
void move(eid_t
id,
const path &parent_path)
221 LOG_DBG(
"Moving element {} to package {}",
id.value(),
224 auto e = nested_trait_ns::get_and_remove<ElementT>(
id);
230 this->add<ElementT>(parent_path, std::move(e));
233 template <
typename ElementT>
void remove(eid_t
id)
248 std::string
to_alias(eid_t
id)
const;
284 template <
typename ElementT>
287 template <
typename ElementT>
291 template <
typename ElementT>
301 const auto &element_opt) {
return element_opt.get() == element; });
304template <
typename ElementT>
312 const auto base_name = e->name();
313 const auto full_name = e->full_name(
false);
314 const auto element_type = e->type_name();
316 LOG_DBG(
"Adding {}: {}::{}, {}", element_type,
317 e->get_namespace().to_string(), base_name, full_name);
320 throw std::runtime_error(
"Name cannot contain namespace: " + base_name);
322 const auto ns = e->get_relative_namespace();
324 auto name = base_name;
325 auto name_and_ns = ns |
name;
327 auto id = e_ref.id();
335 const auto maybe_el = get_element<ElementT>(name_and_ns);
336 const auto &el = maybe_el.value();
338 if ((el.name() !=
name) || !(el.get_relative_namespace() == ns))
339 throw std::runtime_error(
340 "Invalid element stored in the diagram tree");
342 LOG_DBG(
"Added {} {} ({} - [{}])", element_type, base_name,
349 catch (
const std::runtime_error &e) {
350 LOG_WARN(
"Cannot add {} {} with id {} due to: {}", element_type,
name,
355 LOG_DBG(
"{} {} ({} - [{}]) already in the model", element_type, base_name,
361template <
typename ElementT>
370 const auto element_type = e->type_name();
374 for (
auto it = parent_path.
begin(); it != parent_path.
end(); it++) {
375 auto pkg = std::make_unique<common::model::package>(
376 e->using_namespace(), parent_path.
type());
381 pkg->set_namespace(ns);
384 add(ns, std::move(pkg));
387 const auto base_name = e->name();
388 const auto full_name = e->full_name(
false);
399template <
typename ElementT>
406 LOG_DBG(
"Adding element {} at path {}", e->full_name(
false),
409 const auto element_type = e->type_name();
413 for (
auto it = parent_path.
begin(); it != parent_path.
end(); it++) {
414 auto pkg = std::make_unique<common::model::package>(
415 e->using_namespace(), parent_path.
type());
419 pkg->set_namespace(package_path);
420 pkg->set_id(
common::to_id(
"__directory__" + pkg->full_name(
false)));
422 LOG_DBG(
"Adding filesystem package {} at path {}", pkg->name(),
423 package_path.to_string());
425 add(package_path, std::move(pkg));
428 const auto base_name = e->name();
429 const auto full_name = e->full_name(
false);
441template <
typename ElementT>
445 const auto full_name = element.get().full_name(
false);
447 auto full_name_escaped = full_name;
450 if (
name == full_name ||
name == full_name_escaped) {
458template <
typename ElementT>
462 std::vector<opt_ref<ElementT>> result;
465 const auto full_name = element.get().full_name(
false);
466 auto full_name_escaped = full_name;
469 if (pattern == full_name || pattern == full_name_escaped) {
470 result.emplace_back(element);
480 if (element.get().id() == id) {
488template <
typename ElementT>
498bool diagram::add_with_namespace_path<common::model::package>(
499 std::unique_ptr<common::model::package> &&p);
502bool diagram::add_with_module_path<common::model::package>(
504 std::unique_ptr<common::model::package> &&p);
507bool diagram::add_with_filesystem_path<common::model::package>(
509 std::unique_ptr<common::model::package> &&p);
515bool check_diagram_type<clanguml::class_diagram::model::diagram>(diagram_t t);