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/common/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 "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 if (!complete()) {
78 return filter_->should_include(
79 dynamic_cast<const source_location &>(e));
80 }
81
82 return filter_->should_include(e) &&
83 filter_->should_include(dynamic_cast<const source_location &>(e));
84}
85
87{
88 if (filtered_)
89 return true;
90
91 if (filter_.get() == nullptr)
92 return true;
93
94 return filter_->should_include(ns);
95}
96
98{
99 return should_include(r.type());
100}
101
103{
104 if (filter_.get() == nullptr)
105 return true;
106
107 return filter_->should_include(r);
108}
109
111{
112 if (filter_.get() == nullptr)
113 return true;
114
115 return filter_->should_include(s);
116}
117
119 const namespace_ &ns, const std::string &name) const
120{
121 if (filter_.get() == nullptr)
122 return true;
123
124 return filter_->should_include(ns, name);
125}
126
128{
129 if (filter_.get() == nullptr)
130 return true;
131
132 return filter_->should_include(f);
133}
134
135} // namespace clanguml::common::model