0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
diagram_element.cc
Go to the documentation of this file.
1/**
2 * @file src/common/model/diagram_element.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 "diagram_element.h"
20
22#include "util/util.h"
23
24#include <ostream>
25
27
29
30const eid_t &diagram_element::id() const { return id_; }
31
33
34std::optional<eid_t> diagram_element::parent_element_id() const
35{
36 return parent_element_id_;
37}
38
40{
42}
43
44std::string diagram_element::alias() const
45{
46 // Only generate alias for global id's
47 assert(id_.is_global());
48
49 return fmt::format("C_{:022}", id_.value());
50}
51
53{
54 if ((cr.type() == relationship_t::kInstantiation) &&
55 (cr.destination() == id())) {
56 LOG_DBG("Skipping self instantiation relationship for {}",
57 cr.destination());
58 return;
59 }
60
62 LOG_DBG("Adding relationship from: '{}' ({}) - {} - '{}'", id(),
63 full_name(true), to_string(cr.type()), cr.destination());
64
65 relationships_.emplace_back(std::move(cr));
66 }
67}
68
69std::vector<relationship> &diagram_element::relationships()
70{
71 return relationships_;
72}
73
74const std::vector<relationship> &diagram_element::relationships() const
75{
76 return relationships_;
77}
78
80{
82}
83
84bool diagram_element::is_nested() const { return nested_; }
85
86void diagram_element::nested(bool nested) { nested_ = nested; }
87
88bool diagram_element::complete() const { return complete_; }
89
90void diagram_element::complete(bool completed) { complete_ = completed; }
91
93{
94 std::vector<relationship> unique_relationships;
95
96 for (auto &r : relationships_) {
97 if (!util::contains(unique_relationships, r)) {
98 unique_relationships.emplace_back(r);
99 }
100 }
101
102 std::swap(relationships_, unique_relationships);
103}
104
106 const diagram_filter &filter, const std::set<eid_t> &removed)
107{
109
110 auto &rels = relationships();
111 rels.erase(std::remove_if(std::begin(rels), std::end(rels),
112 [&removed](auto &&r) {
113 return removed.count(r.destination()) > 0;
114 }),
115 std::end(rels));
116}
117
119{
120 return l.id() == r.id();
121}
122
123std::ostream &operator<<(std::ostream &out, const diagram_element &rhs)
124{
125 out << "(" << rhs.name() << ", full_name=[" << rhs.full_name(false) << "])";
126
127 return out;
128}
129
130} // namespace clanguml::common::model