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/common/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 "namespace.h"
23
25
26diagram::diagram() = default;
27
28diagram::~diagram() = default;
29
30diagram::diagram(diagram &&) noexcept = default;
31
32diagram &diagram::operator=(diagram &&) noexcept = default;
33
34common::optional_ref<clanguml::common::model::diagram_element>
35diagram::get_with_namespace(const std::string &name, const namespace_ &ns) const
36{
37 auto element_opt = get(name);
38
39 if (!element_opt) {
40 // If no element matches, try to prepend the 'using_namespace'
41 // value to the element and search again
42 auto fully_qualified_name = ns | name;
43 element_opt = get(fully_qualified_name.to_string());
44 }
45
46 return element_opt;
47}
48
49std::string diagram::name() const { return name_; }
50
51void diagram::set_name(const std::string &name) { name_ = name; }
52
53void diagram::set_filter(std::unique_ptr<diagram_filter> filter)
54{
55 filter_ = std::move(filter);
56}
57
58void diagram::set_complete(bool complete) { complete_ = complete; }
59
60bool diagram::complete() const { return complete_; }
61
63{
64 // Remove elements that do not match the filter
66 filtered_ = true;
67}
68
69bool diagram::should_include(const element &e) const
70{
71 if (filtered_)
72 return true;
73
74 if (filter_.get() == nullptr)
75 return true;
76
77 // In the basic mode, apply the paths filter as soon as possible
78 // to limit processing unnecessary files
79 if (filter_->mode() == filter_mode_t::basic) {
80 return filter_->should_include(e);
81 }
82
83 // In advanced mode, we have to wait until the diagram model is complete
84 // before we can filter anything out
85 if (filter_->mode() == filter_mode_t::advanced && !complete()) {
86 return true;
87 }
88
89 return filter_->should_include(e);
90}
91
93{
94 if (filtered_)
95 return true;
96
97 if (filter_.get() == nullptr)
98 return true;
99
100 return filter_->should_include(ns);
101}
102
104{
105 return should_include(r.type());
106}
107
109{
110 if (filter_.get() == nullptr)
111 return true;
112
113 return filter_->should_include(r);
114}
115
117{
118 if (filter_.get() == nullptr)
119 return true;
120
121 return filter_->should_include(s);
122}
123
125 const namespace_ &ns, const std::string &name) const
126{
127 if (filter_.get() == nullptr)
128 return true;
129
130 return filter_->should_include(ns, name);
131}
132
134{
135 if (filter_.get() == nullptr)
136 return true;
137
138 return filter_->should_include(f);
139}
140
141} // namespace clanguml::common::model