Skip to content

Commit 2c25263

Browse files
committed
Fixed test cases (#415)
1 parent b726f82 commit 2c25263

33 files changed

+409
-152
lines changed

src/class_diagram/model/class.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "common/model/filters/diagram_filter.h"
2222
#include "util/util.h"
2323

24+
#include <algorithm>
2425
#include <sstream>
2526

2627
namespace clanguml::class_diagram::model {
@@ -118,4 +119,23 @@ std::optional<std::string> class_::doxygen_link() const
118119
util::replace_all(name, "##", "_1_1"); // nested classes
119120
return fmt::format("{}{}.html", type, name);
120121
}
122+
123+
void class_::append(const class_ &other)
124+
{
125+
// Add members from other only if they don't already exist in this
126+
for (const auto &member : other.members()) {
127+
auto it = std::find(members_.begin(), members_.end(), member);
128+
if (it == members_.end()) {
129+
members_.push_back(member);
130+
}
131+
}
132+
133+
// Add methods from other only if they don't already exist in this
134+
for (const auto &method : other.methods()) {
135+
auto it = std::find(methods_.begin(), methods_.end(), method);
136+
if (it == methods_.end()) {
137+
methods_.push_back(method);
138+
}
139+
}
140+
}
121141
} // namespace clanguml::class_diagram::model

src/class_diagram/model/class.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ class class_ : public common::model::template_element,
143143
void apply_filter(const common::model::diagram_filter &filter,
144144
const std::set<common::model::eid_t> &removed) override;
145145

146+
void append(const class_ &other);
147+
146148
protected:
147149
/**
148150
* @brief Get class full name.

src/class_diagram/model/class_element.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,10 @@ void class_element::set_qualified_name(const std::string &qn)
4747

4848
std::string class_element::qualified_name() const { return qualified_name_; }
4949

50+
bool class_element::operator==(const class_element &other) const
51+
{
52+
return access_ == other.access_ && name_ == other.name_ &&
53+
qualified_name_ == other.qualified_name_ && type_ == other.type_;
54+
}
55+
5056
} // namespace clanguml::class_diagram::model

src/class_diagram/model/class_element.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class class_element : public common::model::decorated_element,
8585
*/
8686
std::string qualified_name() const;
8787

88+
bool operator==(const class_element &other) const;
89+
8890
private:
8991
common::model::access_t access_;
9092
std::string name_;

src/class_diagram/model/class_member.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @file src/class_diagram/model/class_member_base.cc
2+
* @file src/class_diagram/model/class_member.cc
33
*
44
* Copyright (c) 2021-2025 Bartek Kryza <[email protected]>
55
*
@@ -16,4 +16,13 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "class_member_base.h"
19+
#include "class_member.h"
20+
21+
namespace clanguml::class_diagram::model {
22+
23+
bool class_member::operator==(const class_member &other) const
24+
{
25+
return class_member_base::operator==(other);
26+
}
27+
28+
} // namespace clanguml::class_diagram::model

src/class_diagram/model/class_member.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ namespace clanguml::class_diagram::model {
2929
class class_member : public class_member_base {
3030
public:
3131
using class_member_base::class_member_base;
32+
33+
bool operator==(const class_member &other) const;
3234
};
3335

3436
} // namespace clanguml::class_diagram::model

src/class_diagram/model/class_member_base.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,10 @@ std::optional<size_t> class_member_base::destination_multiplicity() const
4040
return destination_multiplicity_;
4141
}
4242

43+
bool class_member_base::operator==(const class_member_base &other) const
44+
{
45+
return class_element::operator==(other) && is_static_ == other.is_static_ &&
46+
destination_multiplicity_ == other.destination_multiplicity_;
47+
}
48+
4349
} // namespace clanguml::class_diagram::model

src/class_diagram/model/class_member_base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class class_member_base : public class_element {
6868
*/
6969
std::optional<size_t> destination_multiplicity() const;
7070

71+
bool operator==(const class_member_base &other) const;
72+
7173
private:
7274
bool is_static_{false};
7375
std::optional<size_t> destination_multiplicity_{};

src/class_diagram/model/class_method.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,23 @@ bool class_method::is_operator() const { return is_operator_; }
122122

123123
void class_method::is_operator(bool is_operator) { is_operator_ = is_operator; }
124124

125+
bool class_method::operator==(const class_method &other) const
126+
{
127+
return class_method_base::operator==(other) &&
128+
template_params() == other.template_params() &&
129+
is_pure_virtual_ == other.is_pure_virtual_ &&
130+
is_virtual_ == other.is_virtual_ && is_const_ == other.is_const_ &&
131+
is_defaulted_ == other.is_defaulted_ &&
132+
is_deleted_ == other.is_deleted_ &&
133+
is_noexcept_ == other.is_noexcept_ &&
134+
is_constexpr_ == other.is_constexpr_ &&
135+
is_consteval_ == other.is_consteval_ &&
136+
is_coroutine_ == other.is_coroutine_ &&
137+
is_constructor_ == other.is_constructor_ &&
138+
is_destructor_ == other.is_destructor_ &&
139+
is_move_assignment_ == other.is_move_assignment_ &&
140+
is_copy_assignment_ == other.is_copy_assignment_ &&
141+
is_operator_ == other.is_operator_;
142+
}
143+
125144
} // namespace clanguml::class_diagram::model

src/class_diagram/model/class_method.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ class class_method : public class_method_base, public template_trait {
238238
*/
239239
void is_operator(bool is_operator);
240240

241+
bool operator==(const class_method &other) const;
242+
241243
private:
242244
bool is_pure_virtual_{false};
243245
bool is_virtual_{false};

0 commit comments

Comments
 (0)