0.6.1
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | List of all members
clanguml::package_diagram::model::diagram Class Reference

Package diagram model. More...

Detailed Description

Package diagram model.

Definition at line 42 of file diagram.h.

#include <diagram.h>

Public Types

using nested_trait_t = nested_trait_ns
 

Public Member Functions

 diagram ()=default
 
 diagram (const diagram &)=delete
 
 diagram (diagram &&)=default
 
diagramoperator= (const diagram &)=delete
 
diagramoperator= (diagram &&)=default
 
common::model::diagram_t type () const override
 Get the diagram model type - in this case package.
 
const common::reference_vector< package > & packages () const
 Get list of references to packages in the diagram model.
 
opt_ref< diagram_elementget (const std::string &full_name) const override
 Search for element in the diagram by fully qualified name.
 
opt_ref< diagram_elementget (eid_t id) const override
 Search for element in the diagram by id.
 
template<typename ElementT >
opt_ref< ElementT > find (const std::string &name) const
 Find an element in the diagram by name.
 
template<typename ElementT >
opt_ref< ElementT > find (eid_t id) const
 Find an element in the diagram by id.
 
template<typename ElementT >
std::vector< opt_ref< ElementT > > find (const clanguml::common::string_or_regex &pattern) const
 Find elements in the diagram by regex pattern.
 
template<typename ElementT >
bool add (const path &parent_path, std::unique_ptr< ElementT > &&e)
 Add diagram element at nested path.
 
std::string to_alias (eid_t id) const
 Get alias of existing diagram element.
 
bool is_empty () const override
 Check whether the diagram is empty.
 
void apply_filter () override
 
template<typename ElementT >
const common::reference_vector< ElementT > & elements () const
 Get reference to vector of elements of specific type.
 
- Public Member Functions inherited from clanguml::common::model::diagram
 diagram ()
 
 diagram (const diagram &)=delete
 
 diagram (diagram &&) noexcept
 
diagramoperator= (const diagram &)=delete
 
diagramoperator= (diagram &&) noexcept
 
virtual ~diagram ()
 
virtual diagram_t type () const =0
 Return type of the diagram.
 
virtual opt_ref< clanguml::common::model::diagram_elementget (const std::string &full_name) const =0
 
virtual common::optional_ref< clanguml::common::model::diagram_elementget (eid_t id) const =0
 
virtual common::optional_ref< clanguml::common::model::diagram_elementget_with_namespace (const std::string &name, const namespace_ &ns) const
 
void set_name (const std::string &name)
 
std::string name () const
 
void set_filter (std::unique_ptr< diagram_filter > filter)
 
const diagram_filterfilter () const
 
void set_complete (bool complete)
 Set diagram in a complete state.
 
bool complete () const
 Whether the diagram is complete.
 
virtual void finalize ()
 Once the diagram is complete, run any final processing.
 
bool should_include (const element &e) const
 
bool should_include (const namespace_ &ns) const
 
bool should_include (const source_file &path) const
 
bool should_include (relationship r) const
 
bool should_include (relationship_t r) const
 
bool should_include (access_t s) const
 
bool should_include (const std::string &s) const =delete
 
virtual bool has_element (const eid_t) const
 
virtual bool should_include (const namespace_ &ns, const std::string &name) const
 
virtual bool is_empty () const =0
 Check whether the diagram is empty.
 
virtual void apply_filter ()
 
- Public Member Functions inherited from clanguml::common::model::element_views< package >
void for_all_elements (F &&f)
 
void for_all_elements (F &&f) const
 
const element_view< T > & view () const
 
void dynamic_apply (T *e, F &&f) const
 Calls f function on e if it can be dynamically casted to any type in the element_views.
 
- Public Member Functions inherited from clanguml::common::model::element_view< Ts >
void add (std::reference_wrapper< Ts > element)
 Add reference to diagram element.
 
const reference_vector< Ts > & view () const
 Get collection of reference to diagram elements.
 
reference_vector< Ts > & view ()
 Get collection of reference to diagram elements.
 
common::optional_ref< Ts > get (eid_t id) const
 Get typed diagram element by id.
 
bool is_empty () const
 Check whether the element view is empty.
 
void remove (const std::set< eid_t > &element_ids)
 
void for_each (F &&f) const
 
- Public Member Functions inherited from clanguml::common::model::nested_trait< T, Path >
 nested_trait ()=default
 
 nested_trait (const nested_trait &)=delete
 
 nested_trait (nested_trait &&) noexcept=default
 
nested_traitoperator= (const nested_trait &)=delete
 
nested_traitoperator= (nested_trait &&) noexcept=default
 
virtual ~nested_trait ()=default
 
bool is_root () const
 
void is_root (bool a)
 
template<typename V = T>
bool add_element (std::unique_ptr< V > element)
 
template<typename V = T>
bool add_element (const Path &path, std::unique_ptr< V > p)
 
template<typename V = T>
auto get_element (const Path &path) const
 
template<typename V = T>
auto get_element (const std::string &name, bool is_root=false) const
 
template<typename F >
bool all_of (F &&f) const
 
bool is_empty (bool include_inner_packages=false) const
 
auto cbegin () const
 
auto cend () const
 
auto begin () const
 
auto end () const
 
void print_tree (const int level) const
 
template<typename V = T>
std::unique_ptr< V > get_and_remove (eid_t id)
 
void remove (const std::set< eid_t > &element_ids)
 

Private Member Functions

template<typename ElementT >
bool add_with_module_path (const common::model::path &parent_path, std::unique_ptr< ElementT > &&e)
 Add element using module as diagram path.
 
template<typename ElementT >
bool add_with_namespace_path (std::unique_ptr< ElementT > &&e)
 Add element using namespace as diagram path.
 
template<typename ElementT >
bool add_with_filesystem_path (const common::model::path &parent_path, std::unique_ptr< ElementT > &&e)
 Add element using relative filesystem path as diagram path.
 

Additional Inherited Members

- Protected Member Functions inherited from clanguml::common::model::diagram
diagram_filterfilter ()
 

Member Typedef Documentation

◆ nested_trait_t

Definition at line 46 of file diagram.h.

Constructor & Destructor Documentation

◆ diagram() [1/3]

clanguml::package_diagram::model::diagram::diagram ( )
default

◆ diagram() [2/3]

clanguml::package_diagram::model::diagram::diagram ( const diagram )
delete

◆ diagram() [3/3]

clanguml::package_diagram::model::diagram::diagram ( diagram &&  )
default

Member Function Documentation

◆ add()

template<typename ElementT >
bool clanguml::package_diagram::model::diagram::add ( const path parent_path,
std::unique_ptr< ElementT > &&  e 
)
inline

Add diagram element at nested path.

This method handled both diagrams where packages are created from namespaces, as well as those were packages are created from project subdirectories.

Template Parameters
ElementTType of diagram element to add
Parameters
parent_pathPackage nested path where the element should be added
eDiagram element to add
Returns
True, if the element was added.

Definition at line 137 of file diagram.h.

138 {
139 if (parent_path.type() == common::model::path_type::kNamespace) {
140 return add_with_namespace_path(std::move(e));
141 }
142
143 if (parent_path.type() == common::model::path_type::kModule) {
144 return add_with_module_path(parent_path, std::move(e));
145 }
146
147 return add_with_filesystem_path(parent_path, std::move(e));
148 }

◆ add_with_filesystem_path()

template<typename ElementT >
bool clanguml::package_diagram::model::diagram::add_with_filesystem_path ( const common::model::path parent_path,
std::unique_ptr< ElementT > &&  e 
)
private

Add element using relative filesystem path as diagram path.

Template Parameters
ElementTElement type
Parameters
parent_pathPath to diagram elements parent package
eElement to add
Returns
True, if the element was added

Definition at line 313 of file diagram.h.

315{
316 LOG_TRACE("Adding package: {}, {}", p->name(), p->full_name(true));
317
318 // Make sure all parent directories are already packages in the
319 // model
320 for (auto it = parent_path.begin(); it != parent_path.end(); it++) {
321 auto pkg = std::make_unique<common::model::package>(
322 p->using_namespace(), common::model::path_type::kFilesystem);
323 pkg->set_name(*it);
324 auto ns = common::model::path(
325 parent_path.begin(), it, common::model::path_type::kFilesystem);
326 pkg->set_namespace(ns);
327 pkg->set_id(common::to_id(pkg->full_name(false)));
328
329 add_with_filesystem_path(ns, std::move(pkg));
330 }
331
332 auto pp = std::ref(*p);
333 auto res = add_element(parent_path, std::move(p));
334 if (res)
335 element_view<ElementT>::add(pp);
336
337 return res;
338}

◆ add_with_module_path()

template<typename ElementT >
bool clanguml::package_diagram::model::diagram::add_with_module_path ( const common::model::path parent_path,
std::unique_ptr< ElementT > &&  e 
)
private

Add element using module as diagram path.

Template Parameters
ElementTElement type
Parameters
eElement to add
Returns
True, if the element was added

Definition at line 270 of file diagram.h.

272{
273 LOG_DBG("Adding package: {}, {}, {}, [{}]", p->name(), p->full_name(false),
274 parent_path.to_string(), p->id());
275
276 // Make sure all parent modules are already packages in the
277 // model
278 auto module_relative_to = path{p->using_namespace()};
279
280 for (auto it = parent_path.begin(); it != parent_path.end(); it++) {
281 auto pkg = std::make_unique<common::model::package>(
282 p->using_namespace(), common::model::path_type::kModule);
283 pkg->set_name(*it);
284
285 auto module_relative_part = common::model::path(
286 parent_path.begin(), it, common::model::path_type::kModule);
287
288 auto module_absolute_path = module_relative_to | module_relative_part;
289 pkg->set_module(module_absolute_path.to_string());
290 pkg->set_namespace(module_absolute_path);
291
292 auto package_absolute_path = module_absolute_path | pkg->name();
293
294 pkg->set_id(common::to_id(package_absolute_path.to_string()));
295
296 auto p_ref = std::ref(*pkg);
297
298 auto res = add_element(module_relative_part, std::move(pkg));
299 if (res)
300 element_view<ElementT>::add(p_ref);
301 }
302
303 auto p_ref = std::ref(*p);
304
305 auto res = add_element(parent_path, std::move(p));
306 if (res)
307 element_view<ElementT>::add(p_ref);
308
309 return res;
310}

◆ add_with_namespace_path()

template<typename ElementT >
bool clanguml::package_diagram::model::diagram::add_with_namespace_path ( std::unique_ptr< ElementT > &&  e)
private

Add element using namespace as diagram path.

Template Parameters
ElementTElement type
Parameters
eElement to add
Returns
True, if the element was added

Definition at line 254 of file diagram.h.

255{
256 LOG_DBG(
257 "Adding package: {}, {}, [{}]", p->name(), p->full_name(true), p->id());
258
259 auto ns = p->get_relative_namespace();
260 auto p_ref = std::ref(*p);
261
262 auto res = add_element(ns, std::move(p));
263 if (res)
264 element_view<ElementT>::add(p_ref);
265
266 return res;
267}

◆ apply_filter()

void clanguml::package_diagram::model::diagram::apply_filter ( )
overridevirtual

Reimplemented from clanguml::common::model::diagram.

Definition at line 61 of file diagram.cc.

62{
63 // Remove elements by traversing down into packages until no elements
64 // were removed. This is necessary to remove all empty packages.
65 while (true) {
66 auto previous_to_remove_size = packages().size();
67
68 // First find all element ids which should be removed
69 std::set<eid_t> to_remove;
70
71 for (const auto &c : packages()) {
72 if (!filter().should_include(c.get())) {
73 to_remove.emplace(c.get().id());
74 }
75 }
76
77 element_view<package>::remove(to_remove);
78
79 nested_trait_ns::remove(to_remove);
80
81 for (const auto &c : packages()) {
82 c.get().apply_filter(filter(), to_remove);
83 }
84
85 // If this loop didn't remove anything - stop it
86 if (previous_to_remove_size == packages().size())
87 break;
88 }
89}

◆ elements()

template<typename ElementT >
const common::reference_vector< ElementT > & clanguml::package_diagram::model::diagram::elements

Get reference to vector of elements of specific type.

Template Parameters
ElementTType of elements view
Returns
Reference to elements vector

Definition at line 341 of file diagram.h.

342{
343 return element_view<ElementT>::view();
344}

◆ find() [1/3]

template<typename ElementT >
std::vector< opt_ref< ElementT > > clanguml::package_diagram::model::diagram::find ( const clanguml::common::string_or_regex pattern) const

Find elements in the diagram by regex pattern.

This method allows for typed search, where the type of searched for element is determined from template specialization.

Template Parameters
ElementTType of element (e.g. class_)
Parameters
nameString or regex pattern
Returns
List of optional references to matched elements.

Definition at line 237 of file diagram.h.

239{
240 std::vector<opt_ref<ElementT>> result;
241
242 for (const auto &element : element_view<ElementT>::view()) {
243 const auto full_name = element.get().full_name(false);
244
245 if (pattern == full_name) {
246 result.emplace_back(element);
247 }
248 }
249
250 return result;
251}

◆ find() [2/3]

template<typename ElementT >
opt_ref< ElementT > clanguml::package_diagram::model::diagram::find ( const std::string &  name) const

Find an element in the diagram by name.

This method allows for typed search, where the type of searched for element is determined from template specialization.

Template Parameters
ElementTType of element (e.g. package)
Parameters
nameFully qualified name of the element
Returns
Optional reference to a diagram element

Definition at line 212 of file diagram.h.

213{
214 for (const auto &element : element_view<ElementT>::view()) {
215 const auto full_name = element.get().full_name(false);
216
217 if (full_name == name) {
218 return {element};
219 }
220 }
221
222 return {};
223}

◆ find() [3/3]

template<typename ElementT >
opt_ref< ElementT > clanguml::package_diagram::model::diagram::find ( eid_t  id) const

Find an element in the diagram by id.

This method allows for typed search, where the type of searched for element is determined from template specialization.

Template Parameters
ElementTType of element (e.g. package)
Parameters
idId of the element
Returns
Optional reference to a diagram element

Definition at line 225 of file diagram.h.

226{
227 for (const auto &element : element_view<ElementT>::view()) {
228 if (element.get().id() == id) {
229 return {element};
230 }
231 }
232
233 return {};
234}

◆ get() [1/2]

common::optional_ref< clanguml::common::model::diagram_element > clanguml::package_diagram::model::diagram::get ( const std::string &  full_name) const
overridevirtual

Search for element in the diagram by fully qualified name.

Parameters
full_nameFully qualified element name.
Returns
Optional reference to a diagram element.

Implements clanguml::common::model::diagram.

Definition at line 38 of file diagram.cc.

40{
41 return find<package>(full_name);
42}

◆ get() [2/2]

common::optional_ref< clanguml::common::model::diagram_element > clanguml::package_diagram::model::diagram::get ( eid_t  id) const
overridevirtual

Search for element in the diagram by id.

Parameters
idElement id.
Returns
Optional reference to a diagram element.

Implements clanguml::common::model::diagram.

Definition at line 44 of file diagram.cc.

46{
47 return find<package>(id);
48}

◆ is_empty()

bool clanguml::package_diagram::model::diagram::is_empty ( ) const
overridevirtual

Check whether the diagram is empty.

Returns
True, if diagram is empty

Implements clanguml::common::model::diagram.

Definition at line 91 of file diagram.cc.

91{ return element_view<package>::is_empty(); }

◆ operator=() [1/2]

diagram & clanguml::package_diagram::model::diagram::operator= ( const diagram )
delete

◆ operator=() [2/2]

diagram & clanguml::package_diagram::model::diagram::operator= ( diagram &&  )
default

◆ packages()

const common::reference_vector< clanguml::common::model::package > & clanguml::package_diagram::model::diagram::packages ( ) const

Get list of references to packages in the diagram model.

Returns
List of references to packages in the diagram model.

Definition at line 33 of file diagram.cc.

34{
35 return element_view<package>::view();
36}

◆ to_alias()

std::string clanguml::package_diagram::model::diagram::to_alias ( eid_t  id) const

Get alias of existing diagram element.

Parameters
idId of a package in the diagram
Returns
PlantUML alias of the element

Definition at line 50 of file diagram.cc.

51{
52 LOG_DBG("Looking for alias for {}", id);
53
54 auto p = find<package>(id);
55 if (p.has_value() && p.value().id() == id)
56 return p.value().alias();
57
58 return {};
59}

◆ type()

common::model::diagram_t clanguml::package_diagram::model::diagram::type ( ) const
overridevirtual

Get the diagram model type - in this case package.

Returns
Type of package diagram.

Implements clanguml::common::model::diagram.

Definition at line 27 of file diagram.cc.


The documentation for this class was generated from the following files: