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

Diagram element representing a class or class template. More...

Detailed Description

Diagram element representing a class or class template.

Definition at line 42 of file class.h.

#include <class.h>

Public Member Functions

 class_ (const common::model::namespace_ &using_namespace)
 
 class_ (const class_ &)=delete
 
 class_ (class_ &&) noexcept=delete
 
class_operator= (const class_ &)=delete
 
class_operator= (class_ &&)=delete
 
std::string type_name () const override
 
bool is_struct () const
 
void is_struct (bool is_struct)
 
bool is_union () const
 
void is_union (bool is_union)
 
void add_member (class_member &&member)
 
void add_method (class_method &&method)
 
void add_parent (class_parent &&parent)
 
const std::vector< class_member > & members () const
 
const std::vector< class_method > & methods () const
 
const std::vector< class_parent > & parents () const
 
std::vector< class_parent > & parents ()
 
std::string full_name (bool relative=true) const override
 Get class full name.
 
std::string full_name_no_ns () const override
 Get unqualified class ful name.
 
bool is_abstract () const
 
std::optional< std::string > doxygen_link () const override
 Generate Doxygen style HTML link for the class.
 
void apply_filter (const common::model::diagram_filter &filter, const std::set< eid_t > &removed) override
 
- Public Member Functions inherited from clanguml::common::model::template_element
 ~template_element () override=default
 
bool is_template () const
 
void is_template (bool is_template)
 
int calculate_template_specialization_match (const template_element &other) const
 Calculate template specialization match with other class.
 
bool template_specialization_found () const
 
void template_specialization_found (bool found)
 
 element (namespace_ using_namespace, path_type pt=path_type::kNamespace)
 
- Public Member Functions inherited from clanguml::common::model::element
 element (namespace_ using_namespace, path_type pt=path_type::kNamespace)
 
 ~element () override=default
 
std::string name_and_ns () const
 
void set_namespace (const namespace_ &ns)
 
namespace_ get_namespace () const
 
namespace_ get_relative_namespace () const
 
const namespace_path () const
 
void set_module (const std::string &module)
 
std::optional< std::string > module () const
 
void set_module_private (const bool module_private)
 
bool module_private () const
 
std::string full_name (bool relative) const override
 
virtual std::string full_name_no_ns () const
 
const namespace_using_namespace () const
 
inja::json context () const override
 
- Public Member Functions inherited from clanguml::common::model::diagram_element
 diagram_element ()
 
 ~diagram_element () override=default
 
const eid_tid () const
 Returns diagram element id.
 
void set_id (eid_t id)
 
std::optional< eid_tparent_element_id () const
 
void set_parent_element_id (eid_t id)
 
virtual std::string alias () const
 Return elements' diagram alias.
 
void set_name (const std::string &name)
 
std::string name () const
 
virtual std::string type_name () const
 
virtual std::string full_name (bool) const
 Return the elements fully qualified name.
 
std::vector< relationship > & relationships ()
 
const std::vector< relationship > & relationships () const
 
void add_relationship (relationship &&cr)
 
void append (const decorated_element &e)
 
virtual inja::json context () const
 
bool is_nested () const
 
void nested (bool nested)
 
bool complete () const
 
void complete (bool completed)
 
virtual void apply_filter (const diagram_filter &filter, const std::set< eid_t > &removed)
 
- Public Member Functions inherited from clanguml::common::model::decorated_element
virtual ~decorated_element ()=default
 
bool skip () const
 
bool skip_relationship () const
 
std::pair< relationship_t, std::string > get_relationship () const
 
std::string style_spec () const
 
const std::vector< std::shared_ptr< decorators::decorator > > & decorators () const
 
void add_decorators (const std::vector< std::shared_ptr< decorators::decorator > > &decorators)
 
void append (const decorated_element &de)
 
std::optional< comment_tcomment () const
 
void set_comment (const comment_t &c)
 
virtual std::optional< std::string > doxygen_link () const
 
- Public Member Functions inherited from clanguml::common::model::source_location
 source_location ()=default
 
 source_location (std::string f, unsigned int l)
 
const std::string & file () const
 
void set_file (const std::string &file)
 
const std::string & file_relative () const
 
void set_file_relative (const std::string &file)
 
const std::string & translation_unit () const
 
void set_translation_unit (const std::string &translation_unit)
 
unsigned int line () const
 
void set_line (const unsigned line)
 
unsigned int column () const
 
void set_column (const unsigned column)
 
unsigned int location_id () const
 
void set_location_id (unsigned int h)
 
- Public Member Functions inherited from clanguml::common::model::template_trait
std::ostream & render_template_params (std::ostream &ostr, const common::model::namespace_ &using_namespace, bool relative) const
 
void add_template (template_parameter &&tmplt)
 
const std::vector< template_parameter > & template_params () const
 
int calculate_template_specialization_match (const template_trait &other) const
 Wrapper around calculate_template_params_specialization_match()
 
- Public Member Functions inherited from clanguml::common::model::stylable_element
void set_style (const std::string &style)
 
std::optional< std::string > style () const
 

Private Attributes

bool is_struct_ {false}
 
bool is_union_ {false}
 
std::vector< class_membermembers_
 
std::vector< class_methodmethods_
 
std::vector< class_parentbases_
 
std::string base_template_full_name_
 
std::string full_name_
 

Friends

bool operator== (const class_ &l, const class_ &r)
 

Constructor & Destructor Documentation

◆ class_() [1/3]

clanguml::class_diagram::model::class_::class_ ( const common::model::namespace_ using_namespace)

Definition at line 28 of file class.cc.

29 : template_element{using_namespace}
30{
31}

◆ class_() [2/3]

clanguml::class_diagram::model::class_::class_ ( const class_ )
delete

◆ class_() [3/3]

clanguml::class_diagram::model::class_::class_ ( class_ &&  )
deletenoexcept

Member Function Documentation

◆ add_member()

void clanguml::class_diagram::model::class_::add_member ( class_member &&  member)

Add a data member to the class.

Parameters
memberClass data member.

Definition at line 41 of file class.cc.

42{
43 members_.emplace_back(std::move(member));
44}

◆ add_method()

void clanguml::class_diagram::model::class_::add_method ( class_method &&  method)

Add a method to the class.

Parameters
methodClass method.

Definition at line 46 of file class.cc.

47{
48 methods_.emplace_back(std::move(method));
49}

◆ add_parent()

void clanguml::class_diagram::model::class_::add_parent ( class_parent &&  parent)

Add class parent (inheritance relationship).

Todo:
Maybe it would be good to refactor this into a regular relationship. We could drop the 'class_parent' class completely...
Parameters
parentClass parent.

Definition at line 51 of file class.cc.

52{
53 for (const auto &p : bases_) {
54 if (p.id() == parent.id()) {
55 return;
56 }
57 }
58
59 bases_.emplace_back(std::move(parent));
60}

◆ apply_filter()

void clanguml::class_diagram::model::class_::apply_filter ( const common::model::diagram_filter filter,
const std::set< eid_t > &  removed 
)
overridevirtual

Reimplemented from clanguml::common::model::diagram_element.

Definition at line 116 of file class.cc.

118{
119 diagram_element::apply_filter(filter, removed);
120
123
124 // Remove class bases which are no longer in the diagram
125 parents().erase(
126 std::remove_if(parents().begin(), parents().end(),
127 [&removed](auto &&p) { return removed.count(p.id()) > 0; }),
128 parents().end());
129}

◆ doxygen_link()

std::optional< std::string > clanguml::class_diagram::model::class_::doxygen_link ( ) const
overridevirtual

Generate Doxygen style HTML link for the class.

This method generates a link, which can be used in SVG diagrams to create links from classes to Doxygen documentation pages.

Returns
Doxygen-style HTML link for the class.

Reimplemented from clanguml::common::model::decorated_element.

Definition at line 131 of file class.cc.

132{
133 const auto *type = is_struct() ? "struct" : "class";
134
135 auto name = name_and_ns();
136 util::replace_all(name, "_", "__");
137 util::replace_all(name, "::", "_1_1");
138 util::replace_all(name, "##", "_1_1"); // nested classes
139 return fmt::format("{}{}.html", type, name);
140}

◆ full_name()

std::string clanguml::class_diagram::model::class_::full_name ( bool  relative = true) const
overridevirtual

Get class full name.

This method renders the entire class name including all template parameters and/or arguments.

Parameters
relativeWhether the class name should be relative to using_namespace
Returns
Full class name.

Reimplemented from clanguml::common::model::diagram_element.

Definition at line 84 of file class.cc.

85{
86 using namespace clanguml::util;
88
89 std::ostringstream ostr;
90
91 ostr << name_and_ns();
92
93 render_template_params(ostr, using_namespace(), relative);
94
95 std::string res;
96
97 if (relative)
98 res = using_namespace().relative(ostr.str());
99 else
100 res = ostr.str();
101
102 if (res.empty())
103 return "<<anonymous>>";
104
105 return res;
106}

◆ full_name_no_ns()

std::string clanguml::class_diagram::model::class_::full_name_no_ns ( ) const
overridevirtual

Get unqualified class ful name.

This method returns the class full name but without any namespace qualifier.

Returns
Full class name without namespace.

Reimplemented from clanguml::common::model::element.

Definition at line 71 of file class.cc.

72{
73 using namespace clanguml::util;
74
75 std::ostringstream ostr;
76
77 ostr << name();
78
80
81 return ostr.str();
82}

◆ is_abstract()

bool clanguml::class_diagram::model::class_::is_abstract ( ) const

Whether the class is abstract.

Returns
True, if at least one method is abstract (=0).

Definition at line 108 of file class.cc.

109{
110 // TODO check if all base abstract methods are overriden
111 // with non-abstract methods
112 return std::any_of(methods_.begin(), methods_.end(),
113 [](const auto &method) { return method.is_pure_virtual(); });
114}

◆ is_struct() [1/2]

bool clanguml::class_diagram::model::class_::is_struct ( ) const

Whether or not the class was declared in the code as 'struct'.

Returns
True, if the class was declared as 'struct'

Definition at line 33 of file class.cc.

33{ return is_struct_; }

◆ is_struct() [2/2]

void clanguml::class_diagram::model::class_::is_struct ( bool  is_struct)

Set, whether the class was declared as 'struct'.

Parameters
is_structTrue, if the class was declared as 'struct'

Definition at line 35 of file class.cc.

◆ is_union() [1/2]

bool clanguml::class_diagram::model::class_::is_union ( ) const

Whether or not the class is a union.

Returns
True, if the class is a union.

Definition at line 37 of file class.cc.

37{ return is_union_; }

◆ is_union() [2/2]

void clanguml::class_diagram::model::class_::is_union ( bool  is_union)

Set, whether the class is a union.

Parameters
uTrue, if the class is a union.

Definition at line 39 of file class.cc.

◆ members()

const std::vector< class_member > & clanguml::class_diagram::model::class_::members ( ) const

Get reference to class member list.

Returns
Reference to class members.

Definition at line 62 of file class.cc.

62{ return members_; }

◆ methods()

const std::vector< class_method > & clanguml::class_diagram::model::class_::methods ( ) const

Get reference to class method list.

Returns
Reference to class methods.

Definition at line 64 of file class.cc.

64{ return methods_; }

◆ operator=() [1/2]

class_ & clanguml::class_diagram::model::class_::operator= ( class_ &&  )
delete

◆ operator=() [2/2]

class_ & clanguml::class_diagram::model::class_::operator= ( const class_ )
delete

◆ parents() [1/2]

std::vector< class_parent > & clanguml::class_diagram::model::class_::parents ( )

Definition at line 67 of file class.cc.

67{ return bases_; }

◆ parents() [2/2]

const std::vector< class_parent > & clanguml::class_diagram::model::class_::parents ( ) const

Get reference to class parent list.

Returns
Reference to class parents.

Definition at line 66 of file class.cc.

66{ return bases_; }

◆ type_name()

std::string clanguml::class_diagram::model::class_::type_name ( ) const
inlineoverridevirtual

Get the type name of the diagram element.

Returns
Type name of the diagram element.

Reimplemented from clanguml::common::model::diagram_element.

Definition at line 59 of file class.h.

59{ return "class"; }

Friends And Related Symbol Documentation

◆ operator==

bool operator== ( const class_ l,
const class_ r 
)
friend

Definition at line 69 of file class.cc.

69{ return l.id() == r.id(); }

Member Data Documentation

◆ base_template_full_name_

std::string clanguml::class_diagram::model::class_::base_template_full_name_
private

Definition at line 183 of file class.h.

◆ bases_

std::vector<class_parent> clanguml::class_diagram::model::class_::bases_
private

Definition at line 182 of file class.h.

◆ full_name_

std::string clanguml::class_diagram::model::class_::full_name_
private

Definition at line 184 of file class.h.

◆ is_struct_

bool clanguml::class_diagram::model::class_::is_struct_ {false}
private

Definition at line 178 of file class.h.

◆ is_union_

bool clanguml::class_diagram::model::class_::is_union_ {false}
private

Definition at line 179 of file class.h.

◆ members_

std::vector<class_member> clanguml::class_diagram::model::class_::members_
private

Definition at line 180 of file class.h.

◆ methods_

std::vector<class_method> clanguml::class_diagram::model::class_::methods_
private

Definition at line 181 of file class.h.


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