2020#include " class.h"
2121#include " common/model/diagram.h"
2222#include " common/model/element_view.h"
23+ #include " common/model/filters/diagram_filter.h"
2324#include " common/model/nested_trait.h"
2425#include " common/model/package.h"
2526#include " common/types.h"
@@ -44,21 +45,16 @@ using common::model::element_views;
4445using common::model::path;
4546using common::model::path_type;
4647
47- using nested_trait_ns =
48- clanguml::common::model::nested_trait<clanguml::common::model::element,
49- clanguml::common::model::namespace_>;
50-
5148/* *
5249 * @brief Class representing a class diagram.
5350 */
54- class diagram : public common ::model::diagram,
55- public element_views<class_, enum_, concept_, objc_interface>,
56- public nested_trait_ns {
51+ class diagram : public common ::model::hierarchical_diagram<class_, enum_,
52+ concept_, objc_interface> {
5753public:
58- using nested_trait_t = nested_trait_ns;
59-
6054 diagram (const config::class_diagram &config)
61- : clanguml::common::model::diagram{config}, config_{config}
55+ : common::model::hierarchical_diagram<class_, enum_, concept_,
56+ objc_interface>(config)
57+ , config_{config}
6258 {
6359 }
6460
@@ -76,11 +72,6 @@ class diagram : public common::model::diagram,
7672 */
7773 diagram_t type () const override ;
7874
79- /* *
80- * Inherit the should_include methods from the common diagram model.
81- */
82- using common::model::diagram::should_include;
83-
8475 /* *
8576 * @brief Whether a class_member should be included in the diagram.
8677 *
@@ -243,37 +234,21 @@ class diagram : public common::model::diagram,
243234 void add_concept (std::unique_ptr<concept_> &&c);
244235
245236 void add_objc_interface (std::unique_ptr<objc_interface> &&c);
246-
247- template <typename ElementT> void move (eid_t id, const path &parent_path)
248- {
249- LOG_DBG (" Moving element {} to package {}" , id.value (),
250- parent_path.to_string ());
251-
252- auto e = nested_trait_ns::get_and_remove<ElementT>(id);
253- assert (e);
254-
255- element_view<ElementT>::remove ({id});
256- added_elements_.erase (id);
257-
258- this ->add <ElementT>(parent_path, std::move (e));
259- }
260-
261- template <typename ElementT> void remove (eid_t id)
262- {
263- nested_trait_ns::remove ({id});
264- element_view<ElementT>::remove ({id});
265- }
266-
267- /* *
268- * @brief Convert element id to PlantUML alias.
269- *
270- * @todo This method does not belong here - refactor to PlantUML specific
271- * code.
272- *
273- * @param id Id of the diagram element.
274- * @return PlantUML alias.
275- */
276- std::string to_alias (eid_t id) const ;
237+ //
238+ // template <typename ElementT> void move(eid_t id, const path
239+ // &parent_path)
240+ // {
241+ // LOG_DBG("Moving element {} to package {}", id.value(),
242+ // parent_path.to_string());
243+ //
244+ // auto e = nested_trait_ns::get_and_remove<ElementT>(id);
245+ // assert(e);
246+ //
247+ // element_view<ElementT>::remove({id});
248+ // added_elements_.erase(id);
249+ //
250+ // this->add<ElementT>(parent_path, std::move(e));
251+ // }
277252
278253 /* *
279254 * @brief Given an initial set of classes, add all their parents to the
@@ -312,17 +287,6 @@ class diagram : public common::model::diagram,
312287 const config::class_diagram &config_;
313288
314289 std::set<eid_t > added_elements_;
315-
316- template <typename ElementT>
317- bool add_with_namespace_path (std::unique_ptr<ElementT> &&e);
318-
319- template <typename ElementT>
320- bool add_with_module_path (
321- const common::model::path &parent_path, std::unique_ptr<ElementT> &&e);
322-
323- template <typename ElementT>
324- bool add_with_filesystem_path (
325- const common::model::path &parent_path, std::unique_ptr<ElementT> &&e);
326290};
327291
328292template <typename ElementT> bool diagram::contains (const ElementT &element)
@@ -333,143 +297,6 @@ template <typename ElementT> bool diagram::contains(const ElementT &element)
333297 const auto &element_opt) { return element_opt.get () == element; });
334298}
335299
336- template <typename ElementT>
337- bool diagram::add_with_namespace_path (std::unique_ptr<ElementT> &&e)
338- {
339- if (added_elements_.count (e->id ()) > 0 )
340- return true ;
341-
342- added_elements_.emplace (e->id ());
343-
344- const auto base_name = e->name ();
345- const auto full_name = e->full_name (false );
346- const auto element_type = e->type_name ();
347-
348- LOG_DBG (" Adding {}: {}::{}, {} [{}]" , element_type,
349- e->get_namespace ().to_string (), base_name, full_name, e->id ().usr ());
350-
351- if (util::contains (base_name, " ::" ))
352- throw std::runtime_error (" Name cannot contain namespace: " + base_name);
353-
354- const auto ns = e->get_relative_namespace ();
355-
356- auto name = base_name;
357- auto name_and_ns = ns | name;
358- auto &e_ref = *e;
359- auto id = e_ref.id ();
360-
361- try {
362- if (!contains (e_ref)) {
363- if (add_element (ns, std::move (e)))
364- element_view<ElementT>::add (std::ref (e_ref));
365-
366- #if !defined(NDEBUG)
367- const auto maybe_el = get_element<ElementT>(name_and_ns);
368- const auto &el = maybe_el.value ();
369-
370- if ((el.name () != name) || !(el.get_relative_namespace () == ns))
371- throw std::runtime_error (
372- " Invalid element stored in the diagram tree" );
373-
374- LOG_DBG (" Added {} {} ({} - [{}])" , element_type, base_name,
375- full_name, id);
376- #endif
377-
378- return true ;
379- }
380- }
381- catch (const std::runtime_error &e) {
382- LOG_WARN (" Cannot add {} {} with id {} due to: {}" , element_type, name,
383- id, e.what ());
384- return false ;
385- }
386-
387- LOG_DBG (" {} {} ({} - [{}]) already in the model" , element_type, base_name,
388- full_name, id);
389-
390- return false ;
391- }
392-
393- template <typename ElementT>
394- bool diagram::add_with_module_path (
395- const common::model::path &parent_path, std::unique_ptr<ElementT> &&e)
396- {
397- if (added_elements_.count (e->id ()) > 0 )
398- return true ;
399-
400- added_elements_.emplace (e->id ());
401-
402- const auto element_type = e->type_name ();
403-
404- // Make sure all parent modules are already packages in the
405- // model
406- for (auto it = parent_path.begin (); it != parent_path.end (); it++) {
407- auto pkg = std::make_unique<common::model::package>(
408- e->using_namespace (), parent_path.type ());
409- pkg->set_name (*it);
410- auto ns =
411- common::model::path (parent_path.begin (), it, parent_path.type ());
412- // ns.pop_back();
413- pkg->set_namespace (ns);
414- pkg->set_id (common::to_id (*pkg));
415-
416- add (ns, std::move (pkg));
417- }
418-
419- const auto base_name = e->name ();
420- const auto full_name = e->full_name (false );
421- auto &e_ref = *e;
422-
423- if (add_element (parent_path, std::move (e))) {
424- element_view<ElementT>::add (std::ref (e_ref));
425- return true ;
426- }
427-
428- return false ;
429- }
430-
431- template <typename ElementT>
432- bool diagram::add_with_filesystem_path (
433- const common::model::path &parent_path, std::unique_ptr<ElementT> &&e)
434- {
435- if (added_elements_.count (e->id ()) > 0 )
436- return false ;
437-
438- LOG_DBG (" Adding element {} at path {}" , e->full_name (false ),
439- parent_path.to_string ());
440-
441- const auto element_type = e->type_name ();
442-
443- // Make sure all parent modules are already packages in the
444- // model
445- for (auto it = parent_path.begin (); it != parent_path.end (); it++) {
446- auto pkg = std::make_unique<common::model::package>(
447- e->using_namespace (), parent_path.type ());
448- pkg->set_name (*it);
449- auto package_path =
450- common::model::path (parent_path.begin (), it, parent_path.type ());
451- pkg->set_namespace (package_path);
452- pkg->set_id (common::to_id (*pkg));
453-
454- LOG_DBG (" Adding filesystem package {} at path {}" , pkg->name (),
455- package_path.to_string ());
456-
457- add (package_path, std::move (pkg));
458- }
459-
460- const auto base_name = e->name ();
461- const auto full_name = e->full_name (false );
462- auto &e_ref = *e;
463-
464- if (add_element (parent_path, std::move (e))) {
465- added_elements_.emplace (e_ref.id ());
466- element_view<ElementT>::add (std::ref (e_ref));
467- return true ;
468- }
469-
470- return false ;
471- }
472-
473300template <typename ElementT>
474301opt_ref<ElementT> diagram::find (const std::string &name) const
475302{
@@ -523,23 +350,6 @@ const common::reference_vector<ElementT> &diagram::elements() const
523350 return element_view<ElementT>::view ();
524351}
525352
526- //
527- // Template method specialization pre-declarations...
528- //
529- template <>
530- bool diagram::add_with_namespace_path<common::model::package>(
531- std::unique_ptr<common::model::package> &&p);
532-
533- template <>
534- bool diagram::add_with_module_path<common::model::package>(
535- const common::model::path &parent_path,
536- std::unique_ptr<common::model::package> &&p);
537-
538- template <>
539- bool diagram::add_with_filesystem_path<common::model::package>(
540- const common::model::path &parent_path,
541- std::unique_ptr<common::model::package> &&p);
542-
543353} // namespace clanguml::class_diagram::model
544354
545355namespace clanguml ::common::model {
0 commit comments