Skip to content

Commit b726f82

Browse files
committed
Implemented diagram append metod (#415)
1 parent 2faa9b5 commit b726f82

File tree

17 files changed

+424
-182
lines changed

17 files changed

+424
-182
lines changed

src/class_diagram/model/diagram.cc

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,111 @@ common::optional_ref<clanguml::common::model::diagram_element> diagram::get(
118118
return res;
119119
}
120120

121+
void diagram::add_class(std::unique_ptr<class_> &&c)
122+
{
123+
assert(c->id().value() != 0);
124+
125+
if ((config().generate_packages() &&
126+
config().package_type() == config::package_type_t::kDirectory)) {
127+
assert(!c->file().empty());
128+
129+
const auto file = config().make_path_relative(c->file());
130+
131+
common::model::path p{
132+
file.string(), common::model::path_type::kFilesystem};
133+
p.pop_back();
134+
135+
add(p, std::move(c));
136+
}
137+
else if ((config().generate_packages() &&
138+
config().package_type() == config::package_type_t::kModule)) {
139+
140+
const auto module_path = config().make_module_relative(c->module());
141+
142+
common::model::path p{module_path, common::model::path_type::kModule};
143+
144+
add(p, std::move(c));
145+
}
146+
else {
147+
add(c->path(), std::move(c));
148+
}
149+
}
150+
151+
void diagram::add_objc_interface(std::unique_ptr<objc_interface> &&c)
152+
{
153+
if ((config().generate_packages() &&
154+
config().package_type() == config::package_type_t::kDirectory)) {
155+
assert(!c->file().empty());
156+
157+
const auto file = config().make_path_relative(c->file());
158+
159+
common::model::path p{
160+
file.string(), common::model::path_type::kFilesystem};
161+
p.pop_back();
162+
163+
add(p, std::move(c));
164+
}
165+
else {
166+
add(c->path(), std::move(c));
167+
}
168+
}
169+
170+
void diagram::add_enum(std::unique_ptr<enum_> &&e)
171+
{
172+
if ((config().generate_packages() &&
173+
config().package_type() == config::package_type_t::kDirectory)) {
174+
assert(!e->file().empty());
175+
176+
const auto file = config().make_path_relative(e->file());
177+
178+
common::model::path p{
179+
file.string(), common::model::path_type::kFilesystem};
180+
p.pop_back();
181+
182+
add(p, std::move(e));
183+
}
184+
else if ((config().generate_packages() &&
185+
config().package_type() == config::package_type_t::kModule)) {
186+
187+
const auto module_path = config().make_module_relative(e->module());
188+
189+
common::model::path p{module_path, common::model::path_type::kModule};
190+
191+
add(p, std::move(e));
192+
}
193+
else {
194+
add(e->path(), std::move(e));
195+
}
196+
}
197+
198+
void diagram::add_concept(std::unique_ptr<concept_> &&c)
199+
{
200+
if ((config().generate_packages() &&
201+
config().package_type() == config::package_type_t::kDirectory)) {
202+
assert(!c->file().empty());
203+
204+
const auto file = config().make_path_relative(c->file());
205+
206+
common::model::path p{
207+
file.string(), common::model::path_type::kFilesystem};
208+
p.pop_back();
209+
210+
add(p, std::move(c));
211+
}
212+
else if ((config().generate_packages() &&
213+
config().package_type() == config::package_type_t::kModule)) {
214+
215+
const auto module_path = config().make_module_relative(c->module());
216+
217+
common::model::path p{module_path, common::model::path_type::kModule};
218+
219+
add(p, std::move(c));
220+
}
221+
else {
222+
add(c->path(), std::move(c));
223+
}
224+
}
225+
121226
template <>
122227
bool diagram::add_with_namespace_path<common::model::package>(
123228
std::unique_ptr<common::model::package> &&p)

src/class_diagram/model/diagram.h

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,17 @@ class diagram : public common::model::diagram,
5757
public:
5858
using nested_trait_t = nested_trait_ns;
5959

60-
diagram() = default;
60+
diagram(const config::class_diagram &config)
61+
: config_{config}
62+
{
63+
}
6164

6265
diagram(const diagram &) = delete;
6366
diagram(diagram &&) = default;
6467
diagram &operator=(const diagram &) = delete;
65-
diagram &operator=(diagram &&) = default;
68+
diagram &operator=(diagram &&) = delete;
69+
70+
const config::class_diagram &config() const { return config_; }
6671

6772
/**
6873
* @brief Get the diagram model type - in this case class.
@@ -216,6 +221,29 @@ class diagram : public common::model::diagram,
216221
return add_with_filesystem_path(parent_path, std::move(e));
217222
}
218223

224+
/**
225+
* @brief Add class (or template class) to the diagram.
226+
*
227+
* @param c Class model
228+
*/
229+
void add_class(std::unique_ptr<class_> &&c);
230+
231+
/**
232+
* @brief Add enum to the diagram.
233+
*
234+
* @param e Enum model
235+
*/
236+
void add_enum(std::unique_ptr<enum_> &&e);
237+
238+
/**
239+
* @brief Add concept to the diagram.
240+
*
241+
* @param c Concept model
242+
*/
243+
void add_concept(std::unique_ptr<concept_> &&c);
244+
245+
void add_objc_interface(std::unique_ptr<objc_interface> &&c);
246+
219247
template <typename ElementT> void move(eid_t id, const path &parent_path)
220248
{
221249
LOG_DBG("Moving element {} to package {}", id.value(),
@@ -278,7 +306,26 @@ class diagram : public common::model::diagram,
278306

279307
void apply_filter() override;
280308

309+
void append(diagram &&other)
310+
{
311+
clanguml::common::model::diagram::append(
312+
dynamic_cast<clanguml::common::model::diagram &&>(other));
313+
314+
element_views<class_, enum_, concept_, objc_interface>::append(
315+
dynamic_cast<
316+
element_views<class_, enum_, concept_, objc_interface> &&>(
317+
other));
318+
319+
nested_trait_t::append(dynamic_cast<nested_trait_t &&>(other));
320+
321+
for (auto &&ae : other.added_elements_) {
322+
added_elements_.emplace(std::move(ae));
323+
}
324+
}
325+
281326
private:
327+
const config::class_diagram &config_;
328+
282329
std::set<eid_t> added_elements_;
283330

284331
template <typename ElementT>

0 commit comments

Comments
 (0)