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

Class representing an include diagram model. More...

Detailed Description

Class representing an include 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 include.
 
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.
 
void add_file (std::unique_ptr< common::model::source_file > &&f)
 Add include diagram element, an include file.
 
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.
 
const common::reference_vector< source_file > & files () const
 Get list of references to files in the diagram model.
 
opt_ref< diagram_elementget_with_namespace (const std::string &name, const common::model::namespace_ &ns) const override
 Find diagram element with a specified name and path.
 
inja::json context () const override
 
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< source_file >
void add (std::reference_wrapper< source_file > element)
 Add reference to diagram element.
 
const reference_vector< source_file > & view () const
 Get collection of reference to diagram elements.
 
reference_vector< source_file > & view ()
 Get collection of reference to diagram elements.
 
common::optional_ref< source_fileget (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)
 

Constructor & Destructor Documentation

◆ diagram() [1/3]

clanguml::include_diagram::model::diagram::diagram ( )
default

◆ diagram() [2/3]

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

◆ diagram() [3/3]

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

Member Function Documentation

◆ add_file()

void clanguml::include_diagram::model::diagram::add_file ( std::unique_ptr< common::model::source_file > &&  f)

Add include diagram element, an include file.

Parameters
fInclude diagram element

Definition at line 44 of file diagram.cc.

45{
46 // Don't add the same file more than once
47 if (find<source_file>(f->id()))
48 return;
49
50 LOG_DBG("Adding source file: {}, {}", f->name(), f->fs_path().string());
51
52 auto &ff = *f;
53
54 assert(!ff.name().empty());
55 assert(ff.id().value() != 0);
56
57 auto p = ff.path();
58
59 if (!f->path().is_empty()) {
60 // If the parent path is not empty, ensure relative parent directories
61 // of this source_file are in the diagram
62 common::model::filesystem_path parent_path_so_far{
64 for (const auto &directory : f->path()) {
65 auto source_file_path = parent_path_so_far | directory;
66 if (parent_path_so_far.is_empty())
67 source_file_path = {directory};
68
69 auto dir = std::make_unique<common::model::source_file>(
70 std::filesystem::path{source_file_path.to_string()});
72
73 assert(!dir->name().empty());
74
75 if (!get_element(source_file_path).has_value()) {
76 add_file(std::move(dir));
77
78 LOG_DBG("Added directory '{}' at path '{}'", directory,
79 parent_path_so_far.to_string());
80 }
81
82 parent_path_so_far.append(directory);
83 }
84 }
85
86 assert(p.type() == common::model::path_type::kFilesystem);
87
88 if (add_element(p, std::move(f)))
89 element_view<source_file>::add(ff);
90}

◆ apply_filter()

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

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

Definition at line 136 of file diagram.cc.

137{
138 // First find all element ids which should be removed
139 std::set<eid_t> to_remove;
140
141 for (auto &f : element_view<source_file>::view())
142 if (f.get().type() != common::model::source_file_t::kDirectory &&
143 !filter().should_include(f.get())) {
144 to_remove.emplace(f.get().id());
145 }
146
147 for (auto &sf : element_view<source_file>::view())
148 sf.get().apply_filter(filter(), to_remove);
149
150 element_view<source_file>::remove(to_remove);
151
153}

◆ context()

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

Return diagrams JSON context for inja templates.

Returns
JSON context.

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

Definition at line 118 of file diagram.cc.

119{
120 inja::json ctx;
121 ctx["name"] = name();
122 ctx["type"] = "include";
123
124 inja::json::array_t elements{};
125
126 // Add files and directories
127 for (const auto &f : files()) {
128 elements.emplace_back(f.get().context());
129 }
130
131 ctx["elements"] = elements;
132
133 return ctx;
134}

◆ files()

const common::reference_vector< common::model::source_file > & clanguml::include_diagram::model::diagram::files ( ) const

Get list of references to files in the diagram model.

Returns
List of references to concepts in the diagram model.

Definition at line 93 of file diagram.cc.

94{
95 return element_view<source_file>::view();
96}

◆ find() [1/2]

template<typename ElementT >
opt_ref< ElementT > clanguml::include_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 ElementT.

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

Definition at line 138 of file diagram.h.

139{
140 // Convert the name to the OS preferred path
141 std::filesystem::path namePath{name};
142 namePath.make_preferred();
143
144 for (const auto &element : element_view<ElementT>::view()) {
145 const auto full_name = element.get().full_name(false);
146
147 if (full_name == namePath.string()) {
148 return {element};
149 }
150 }
151
152 return {};
153}

◆ find() [2/2]

template<typename ElementT >
opt_ref< ElementT > clanguml::include_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 ElementT.

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

Definition at line 155 of file diagram.h.

156{
157 for (const auto &element : element_view<ElementT>::view()) {
158 if (element.get().id() == id) {
159 return {element};
160 }
161 }
162
163 return {};
164}

◆ get() [1/2]

common::optional_ref< common::model::diagram_element > clanguml::include_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 32 of file diagram.cc.

34{
35 return find<source_file>(full_name);
36}

◆ get() [2/2]

common::optional_ref< common::model::diagram_element > clanguml::include_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 38 of file diagram.cc.

40{
41 return find<source_file>(id);
42}

◆ get_with_namespace()

common::optional_ref< clanguml::common::model::diagram_element > clanguml::include_diagram::model::diagram::get_with_namespace ( const std::string &  name,
const common::model::namespace_ ns 
) const
overridevirtual

Find diagram element with a specified name and path.

Parameters
nameName of the element
nsPath relative to the diagram
Returns
Optional reference to diagram element, if found.

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

Definition at line 99 of file diagram.cc.

101{
102 // Convert to preferred OS path
103 std::filesystem::path namePath{name};
104 auto namePreferred = namePath.make_preferred().string();
105
106 auto element_opt = get(namePreferred);
107
108 if (!element_opt) {
109 // If no element matches, try to prepend the 'using_namespace'
110 // value to the element and search again
111 auto fully_qualified_name = ns | namePreferred;
112 element_opt = get(fully_qualified_name.to_string());
113 }
114
115 return element_opt;
116}

◆ is_empty()

bool clanguml::include_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 155 of file diagram.cc.

155{ return element_view<source_file>::is_empty(); }

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ type()

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

Get the diagram model type - in this case include.

Returns
Type of include 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: