0.5.4
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-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
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
84inja::json diagram_element::context() const
85{
86 inja::json ctx;
87 ctx["name"] = name();
88 ctx["type"] = type_name();
89 ctx["alias"] = alias();
90 ctx["full_name"] = full_name(false);
91 auto maybe_doxygen_link = doxygen_link();
92 if (maybe_doxygen_link)
93 ctx["doxygen_link"] = maybe_doxygen_link.value();
94
95 return ctx;
96}
97
98bool diagram_element::is_nested() const { return nested_; }
99
100void diagram_element::nested(bool nested) { nested_ = nested; }
101
102bool diagram_element::complete() const { return complete_; }
103
104void diagram_element::complete(bool completed) { complete_ = completed; }
105
107 const diagram_filter &filter, const std::set<eid_t> &removed)
108{
110
111 auto &rels = relationships();
112 rels.erase(std::remove_if(std::begin(rels), std::end(rels),
113 [&removed](auto &&r) {
114 return removed.count(r.destination()) > 0;
115 }),
116 std::end(rels));
117}
118
120{
121 return l.id() == r.id();
122}
123
124std::ostream &operator<<(std::ostream &out, const diagram_element &rhs)
125{
126 out << "(" << rhs.name() << ", full_name=[" << rhs.full_name(false) << "])";
127
128 return out;
129}
130
131} // namespace clanguml::common::model