0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
class.cc
Go to the documentation of this file.
1/**
2 * @file src/class_diagram/model/class.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 "class.h"
20
22#include "util/util.h"
23
24#include <sstream>
25
27
29 : template_element{using_namespace}
30{
31}
32
33bool class_::is_struct() const { return is_struct_; }
34
35void class_::is_struct(bool is_struct) { is_struct_ = is_struct; }
36
37bool class_::is_union() const { return is_union_; }
38
39void class_::is_union(bool is_union) { is_union_ = is_union; }
40
42{
43 members_.emplace_back(std::move(member));
44}
45
47{
48 methods_.emplace_back(std::move(method));
49}
50
51const std::vector<class_member> &class_::members() const { return members_; }
52
53const std::vector<class_method> &class_::methods() const { return methods_; }
54
55bool operator==(const class_ &l, const class_ &r) { return l.id() == r.id(); }
56
57std::string class_::full_name_no_ns() const
58{
59 using namespace clanguml::util;
60
61 std::ostringstream ostr;
62
63 ostr << name();
64
66
67 return ostr.str();
68}
69
70std::string class_::full_name_impl(bool relative) const
71{
72 using namespace clanguml::util;
74
75 std::ostringstream ostr;
76
77 ostr << name_and_ns();
78
79 render_template_params(ostr, using_namespace(), relative);
80
81 std::string res;
82
83 if (relative)
84 res = using_namespace().relative(ostr.str());
85 else
86 res = ostr.str();
87
88 if (res.empty())
89 return "<<anonymous>>";
90
91 return res;
92}
93
95{
96 // TODO check if all base abstract methods are overriden
97 // with non-abstract methods
98 return std::any_of(methods_.begin(), methods_.end(),
99 [](const auto &method) { return method.is_pure_virtual(); });
100}
101
103 const common::model::diagram_filter &filter, const std::set<eid_t> &removed)
104{
105 diagram_element::apply_filter(filter, removed);
106
109}
110
111std::optional<std::string> class_::doxygen_link() const
112{
113 const auto *type = is_struct() ? "struct" : "class";
114
115 auto name = name_and_ns();
116 util::replace_all(name, "_", "__");
117 util::replace_all(name, "::", "_1_1");
118 util::replace_all(name, "##", "_1_1"); // nested classes
119 return fmt::format("{}{}.html", type, name);
120}
121} // namespace clanguml::class_diagram::model