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