0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
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 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 > p)
 
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 begin ()
 
auto end ()
 
auto cbegin () const
 
auto cend () const
 
auto begin () const
 
auto end () const
 
void print_tree (const int level) const
 
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.
 

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 135 of file diagram.h.

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

◆ 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 311 of file diagram.h.

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

◆ 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 268 of file diagram.h.

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

◆ 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 252 of file diagram.h.

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

◆ 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 339 of file diagram.h.

340{
341 return element_view<ElementT>::view();
342}

◆ 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 235 of file diagram.h.

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

◆ 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 210 of file diagram.h.

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

◆ 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 223 of file diagram.h.

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

◆ 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: