0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
class.h
Go to the documentation of this file.
1/**
2 * @file src/class_diagram/model/class.h
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#pragma once
19
20#include "class_member.h"
21#include "class_method.h"
22#include "common/model/enums.h"
27#include "common/types.h"
28
29#include <string>
30#include <vector>
31
33class diagram_filter;
34}
35
37
38/**
39 * @brief Diagram element representing a class or class template.
40 */
43public:
45
46 class_(const class_ &) = delete;
47 class_(class_ &&) noexcept = delete;
48 class_ &operator=(const class_ &) = delete;
49 class_ &operator=(class_ &&) = delete;
50
51 friend bool operator==(const class_ &l, const class_ &r);
52
53 /**
54 * Get the type name of the diagram element.
55 *
56 * @return Type name of the diagram element.
57 */
58 std::string type_name() const override { return "class"; }
59
60 /**
61 * Whether or not the class was declared in the code as 'struct'.
62 *
63 * @return True, if the class was declared as 'struct'
64 */
65 bool is_struct() const;
66
67 /**
68 * Set, whether the class was declared as 'struct'.
69 *
70 * @param is_struct True, if the class was declared as 'struct'
71 */
72 void is_struct(bool is_struct);
73
74 /**
75 * Whether or not the class is a union.
76 *
77 * @return True, if the class is a union.
78 */
79 bool is_union() const;
80
81 /**
82 * Set, whether the class is a union.
83 *
84 * @param u True, if the class is a union.
85 */
86 void is_union(bool is_union);
87
88 /**
89 * Add a data member to the class.
90 *
91 * @param member Class data member.
92 */
93 void add_member(class_member &&member);
94
95 /**
96 * Add a method to the class.
97 *
98 * @param method Class method.
99 */
100 void add_method(class_method &&method);
101
102 /**
103 * Get reference to class member list.
104 *
105 * @return Reference to class members.
106 */
107 const std::vector<class_member> &members() const;
108
109 /**
110 * Get reference to class method list.
111 *
112 * @return Reference to class methods.
113 */
114 const std::vector<class_method> &methods() const;
115
116 /**
117 * @brief Get unqualified class ful name.
118 *
119 * This method returns the class full name but without any namespace
120 * qualifier.
121 *
122 * @return Full class name without namespace.
123 */
124 std::string full_name_no_ns() const override;
125
126 /**
127 * Whether the class is abstract.
128 *
129 * @return True, if at least one method is abstract (=0).
130 */
131 bool is_abstract() const;
132
133 /**
134 * @brief Generate Doxygen style HTML link for the class.
135 *
136 * This method generates a link, which can be used in SVG diagrams to
137 * create links from classes to Doxygen documentation pages.
138 *
139 * @return Doxygen-style HTML link for the class.
140 */
141 std::optional<std::string> doxygen_link() const override;
142
144 const std::set<common::model::eid_t> &removed) override;
145
146protected:
147 /**
148 * @brief Get class full name.
149 *
150 * This method renders the entire class name including all template
151 * parameters and/or arguments.
152 *
153 * @param relative Whether the class name should be relative to
154 * using_namespace
155 * @return Full class name.
156 */
157 std::string full_name_impl(bool relative = true) const override;
158
159private:
160 bool is_struct_{false};
161 bool is_union_{false};
162 std::vector<class_member> members_;
163 std::vector<class_method> methods_;
164 std::string full_name_;
165};
166
167} // namespace clanguml::class_diagram::model
168
169namespace std {
170template <>
171struct hash<std::reference_wrapper<clanguml::class_diagram::model::class_>> {
172 std::size_t operator()(
173 const std::reference_wrapper<clanguml::class_diagram::model::class_>
174 &key) const
175 {
176 return std::hash<uint64_t>{}(key.get().id().value());
177 }
178};
179} // namespace std