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>,
70 diagram_t
type()
const override;
101 opt_ref<diagram_element>
get(
const std::string &full_name)
const override;
109 opt_ref<diagram_element>
get(eid_t
id)
const override;
141 template <
typename ElementT>
bool contains(
const ElementT &e);
153 template <
typename ElementT>
154 opt_ref<ElementT>
find(
const std::string &
name)
const;
166 template <
typename ElementT>
167 std::vector<opt_ref<ElementT>>
find(
180 template <
typename ElementT> opt_ref<ElementT>
find(eid_t
id)
const;
188 template <
typename ElementT>
203 template <
typename ElementT>
204 bool add(
const path &parent_path, std::unique_ptr<ElementT> &&e)
226 std::string
to_alias(eid_t
id)
const;
260 template <
typename ElementT>
263 template <
typename ElementT>
267 template <
typename ElementT>
277 const auto &element_opt) {
return element_opt.get() == element; });
280template <
typename ElementT>
283 const auto base_name = e->name();
284 const auto full_name = e->full_name(
false);
285 const auto element_type = e->type_name();
287 LOG_DBG(
"Adding {}: {}::{}, {}", element_type,
288 e->get_namespace().to_string(), base_name, full_name);
291 throw std::runtime_error(
"Name cannot contain namespace: " + base_name);
294 throw std::runtime_error(
"Name cannot contain *: " + base_name);
296 const auto ns = e->get_relative_namespace();
297 auto name = base_name;
298 auto name_and_ns = ns |
name;
300 auto id = e_ref.id();
307 const auto &el = get_element<ElementT>(name_and_ns).value();
309 if ((el.name() !=
name) || !(el.get_relative_namespace() == ns))
310 throw std::runtime_error(
311 "Invalid element stored in the diagram tree");
313 LOG_DBG(
"Added {} {} ({} - [{}])", element_type, base_name,
319 catch (
const std::runtime_error &e) {
320 LOG_WARN(
"Cannot add {} {} with id {} due to: {}", element_type,
name,
325 LOG_DBG(
"{} {} ({} - [{}]) already in the model", element_type, base_name,
331template <
typename ElementT>
335 const auto element_type = e->type_name();
339 for (
auto it = parent_path.
begin(); it != parent_path.
end(); it++) {
340 auto pkg = std::make_unique<common::model::package>(
341 e->using_namespace(), parent_path.
type());
346 pkg->set_namespace(ns);
349 add(ns, std::move(pkg));
352 const auto base_name = e->name();
353 const auto full_name = e->full_name(
false);
364template <
typename ElementT>
368 const auto element_type = e->type_name();
372 for (
auto it = parent_path.
begin(); it != parent_path.
end(); it++) {
373 auto pkg = std::make_unique<common::model::package>(
374 e->using_namespace(), parent_path.
type());
379 pkg->set_namespace(ns);
382 add(ns, std::move(pkg));
385 const auto base_name = e->name();
386 const auto full_name = e->full_name(
false);
397template <
typename ElementT>
401 const auto full_name = element.get().full_name(
false);
403 auto full_name_escaped = full_name;
406 if (
name == full_name ||
name == full_name_escaped) {
414template <
typename ElementT>
418 std::vector<opt_ref<ElementT>> result;
421 const auto full_name = element.get().full_name(
false);
422 auto full_name_escaped = full_name;
425 if (pattern == full_name || pattern == full_name_escaped) {
426 result.emplace_back(element);
436 if (element.get().id() == id) {
444template <
typename ElementT>
454bool diagram::add_with_namespace_path<common::model::package>(
455 std::unique_ptr<common::model::package> &&p);
458bool diagram::add_with_module_path<common::model::package>(
460 std::unique_ptr<common::model::package> &&p);
463bool diagram::add_with_filesystem_path<common::model::package>(
465 std::unique_ptr<common::model::package> &&p);
471bool check_diagram_type<clanguml::class_diagram::model::diagram>(diagram_t t);