0.5.4
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.
 
inja::json context () const override
 Return the elements JSON context for inja templates.
 
bool is_empty () const override
 Check whether the diagram is empty.
 
void apply_filter () override
 
- 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 inja::json context () const =0
 
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_view< package >
void add (std::reference_wrapper< package > element)
 Add reference to diagram element.
 
const reference_vector< package > & view () const
 Get collection of reference to diagram elements.
 
reference_vector< package > & view ()
 Get collection of reference to diagram elements.
 
common::optional_ref< packageget (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)
 
- 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
 
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) const
 
bool has_element (const std::string &name) const
 
template<typename F >
bool all_of (F &&f) const
 
bool is_empty () const
 
auto begin ()
 
auto end ()
 
auto cbegin () const
 
auto cend () const
 
auto begin () const
 
auto end () const
 
void print_tree (const int level)
 
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 309 of file diagram.h.

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

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

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

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

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

◆ apply_filter()

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

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

Definition at line 78 of file diagram.cc.

79{
80 // First find all element ids which should be removed
81 std::set<eid_t> to_remove;
82
83 for (const auto &c : packages())
84 if (!filter().should_include(c.get()))
85 to_remove.emplace(c.get().id());
86
87 element_view<package>::remove(to_remove);
88
89 nested_trait_ns::remove(to_remove);
90
91 for (auto &c : element_view<package>::view())
92 c.get().apply_filter(filter(), to_remove);
93}

◆ context()

inja::json clanguml::package_diagram::model::diagram::context ( ) const
overridevirtual

Return the elements JSON context for inja templates.

Returns
JSON node with elements context.

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

Definition at line 61 of file diagram.cc.

62{
63 inja::json ctx;
64 ctx["name"] = name();
65 ctx["type"] = "package";
66
67 inja::json::array_t elements{};
68
69 for (const auto &p : packages()) {
70 elements.emplace_back(p.get().context());
71 }
72
73 ctx["elements"] = elements;
74
75 return ctx;
76}

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

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

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

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

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

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

◆ 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 95 of file diagram.cc.

95{ 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: