0.5.4
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-2024 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
61inja::json diagram::context() const
62{
63 inja::json ctx;
64 ctx["name"] = name();
65 ctx["type"] = "package";
66
67 inja::json::array_t elements{};
68
69 for (const auto &p : packages()) {
70 elements.emplace_back(p.get().context());
71 }
72
73 ctx["elements"] = elements;
74
75 return ctx;
76}
77
79{
80 // First find all element ids which should be removed
81 std::set<eid_t> to_remove;
82
83 for (const auto &c : packages())
84 if (!filter().should_include(c.get()))
85 to_remove.emplace(c.get().id());
86
87 element_view<package>::remove(to_remove);
88
89 nested_trait_ns::remove(to_remove);
90
91 for (auto &c : element_view<package>::view())
92 c.get().apply_filter(filter(), to_remove);
93}
94
95bool diagram::is_empty() const { return element_view<package>::is_empty(); }
96} // namespace clanguml::package_diagram::model
97
99template <>
100bool check_diagram_type<clanguml::package_diagram::model::diagram>(diagram_t t)
101{
102 return t == diagram_t::kPackage;
103}
104}