0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
diagram.cc
Go to the documentation of this file.
1/**
2 * @file src/package_diagram/model/diagram.cc
3 *
4 * Copyright (c) 2021-2025 Bartek Kryza <bkryza@gmail.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include "diagram.h"
20
22#include "util/error.h"
23#include "util/util.h"
24
26
28{
30}
31
34{
35 return element_view<package>::view();
36}
37
39 const std::string &full_name) const
40{
41 return find<package>(full_name);
42}
43
45 const eid_t id) const
46{
47 return find<package>(id);
48}
49
50std::string diagram::to_alias(const eid_t id) const
51{
52 LOG_DBG("Looking for alias for {}", id);
53
54 auto p = find<package>(id);
55 if (p.has_value() && p.value().id() == id)
56 return p.value().alias();
57
58 return {};
59}
60
62{
63 // Remove elements by traversing down into packages until no elements
64 // were removed. This is necessary to remove all empty packages.
65 while (true) {
66 auto previous_to_remove_size = packages().size();
67
68 // First find all element ids which should be removed
69 std::set<eid_t> to_remove;
70
71 for (const auto &c : packages()) {
72 if (!filter().should_include(c.get())) {
73 to_remove.emplace(c.get().id());
74 }
75 }
76
77 element_view<package>::remove(to_remove);
78
79 nested_trait_ns::remove(to_remove);
80
81 for (const auto &c : packages()) {
82 c.get().apply_filter(filter(), to_remove);
83 }
84
85 // If this loop didn't remove anything - stop it
86 if (previous_to_remove_size == packages().size())
87 break;
88 }
89}
90
91bool diagram::is_empty() const { return element_view<package>::is_empty(); }
92} // namespace clanguml::package_diagram::model
93
95template <>
96bool check_diagram_type<clanguml::package_diagram::model::diagram>(diagram_t t)
97{
98 return t == diagram_t::kPackage;
99}
100}