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::common::model::diagram_element Class Reference

Base class for standalone diagram elements. More...

Detailed Description

Base class for standalone diagram elements.

This is a base cass of any standalone elements such as classes, structs, concepts, packages and so on participants and so on.

Definition at line 43 of file diagram_element.h.

#include <diagram_element.h>

Public Member Functions

 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)
 

Private Attributes

eid_t id_ {}
 
std::optional< eid_tparent_element_id_ {}
 
std::string name_
 
std::vector< relationshiprelationships_
 
bool nested_ {false}
 
bool complete_ {false}
 

Friends

bool operator== (const diagram_element &l, const diagram_element &r)
 
std::ostream & operator<< (std::ostream &out, const diagram_element &rhs)
 

Constructor & Destructor Documentation

◆ diagram_element()

clanguml::common::model::diagram_element::diagram_element ( )
default

◆ ~diagram_element()

clanguml::common::model::diagram_element::~diagram_element ( )
overridedefault

Member Function Documentation

◆ add_relationship()

void clanguml::common::model::diagram_element::add_relationship ( relationship &&  cr)

Add relationships, whose source is this element.

Parameters
crRelationship to another diagram element.

Definition at line 52 of file diagram_element.cc.

53{
54 if ((cr.type() == relationship_t::kInstantiation) &&
55 (cr.destination() == id())) {
56 LOG_DBG("Skipping self instantiation relationship for {}",
57 cr.destination());
58 return;
59 }
60
62 LOG_DBG("Adding relationship from: '{}' ({}) - {} - '{}'", id(),
63 full_name(true), to_string(cr.type()), cr.destination());
64
65 relationships_.emplace_back(std::move(cr));
66 }
67}

◆ alias()

std::string clanguml::common::model::diagram_element::alias ( ) const
virtual

Return elements' diagram alias.

Todo:
This is a PlantUML specific method - it shouldn't be here.
Returns
PlantUML's diagram element alias.

Reimplemented in clanguml::sequence_diagram::model::method.

Definition at line 44 of file diagram_element.cc.

45{
46 // Only generate alias for global id's
47 assert(id_.is_global());
48
49 return fmt::format("C_{:022}", id_.value());
50}

◆ append()

void clanguml::common::model::diagram_element::append ( const decorated_element e)

Add element to the diagram.

Parameters
eDiagram element.

Definition at line 79 of file diagram_element.cc.

80{
82}

◆ apply_filter()

void clanguml::common::model::diagram_element::apply_filter ( const diagram_filter filter,
const std::set< eid_t > &  removed 
)
virtual

Reimplemented in clanguml::class_diagram::model::class_.

Definition at line 106 of file diagram_element.cc.

108{
110
111 auto &rels = relationships();
112 rels.erase(std::remove_if(std::begin(rels), std::end(rels),
113 [&removed](auto &&r) {
114 return removed.count(r.destination()) > 0;
115 }),
116 std::end(rels));
117}

◆ complete() [1/2]

bool clanguml::common::model::diagram_element::complete ( ) const

Returns the diagrams completion status.

Returns
Whether the diagram is complete.

Definition at line 102 of file diagram_element.cc.

102{ return complete_; }

◆ complete() [2/2]

void clanguml::common::model::diagram_element::complete ( bool  completed)

Set the diagrams completion status.

Parameters
completed

Definition at line 104 of file diagram_element.cc.

104{ complete_ = completed; }

◆ context()

inja::json clanguml::common::model::diagram_element::context ( ) const
virtual

Return elements inja JSON context.

Returns
Element context.

Reimplemented in clanguml::common::model::element, and clanguml::common::model::source_file.

Definition at line 84 of file diagram_element.cc.

85{
86 inja::json ctx;
87 ctx["name"] = name();
88 ctx["type"] = type_name();
89 ctx["alias"] = alias();
90 ctx["full_name"] = full_name(false);
91 auto maybe_doxygen_link = doxygen_link();
92 if (maybe_doxygen_link)
93 ctx["doxygen_link"] = maybe_doxygen_link.value();
94
95 return ctx;
96}

◆ full_name()

virtual std::string clanguml::common::model::diagram_element::full_name ( bool  ) const
inlinevirtual

Return the elements fully qualified name.

This method should be implemented in each subclass, and ensure that for instance it includes fully qualified namespace, template params, etc.

Returns
Full elements name.

Reimplemented in clanguml::common::model::element, clanguml::common::model::package, clanguml::sequence_diagram::model::method, clanguml::class_diagram::model::class_, clanguml::class_diagram::model::concept_, clanguml::class_diagram::model::enum_, clanguml::sequence_diagram::model::class_, clanguml::sequence_diagram::model::function, clanguml::sequence_diagram::model::function_template, and clanguml::common::model::source_file.

Definition at line 120 of file diagram_element.h.

120{ return name(); }

◆ id()

const eid_t & clanguml::common::model::diagram_element::id ( ) const

Returns diagram element id.

Each element in the diagram is uniquely identified by id. The id is currently calculated from the full string representation of the element, in order to be uniquely identifiable among multiple translation units.

Returns
Elements id.

Definition at line 30 of file diagram_element.cc.

30{ return id_; }

◆ is_nested()

bool clanguml::common::model::diagram_element::is_nested ( ) const

Whether this element is nested in another element.

Returns

Definition at line 98 of file diagram_element.cc.

98{ return nested_; }

◆ name()

std::string clanguml::common::model::diagram_element::name ( ) const
inline

Return diagram element name.

Returns
Diagram element name.

Definition at line 103 of file diagram_element.h.

103{ return name_; }

◆ nested()

void clanguml::common::model::diagram_element::nested ( bool  nested)

Set element's nested status.

Parameters
nested

Definition at line 100 of file diagram_element.cc.

100{ nested_ = nested; }

◆ parent_element_id()

std::optional< eid_t > clanguml::common::model::diagram_element::parent_element_id ( ) const

Get elements parent package id.

Returns
Parent package id if element is nested.

Definition at line 34 of file diagram_element.cc.

35{
36 return parent_element_id_;
37}

◆ relationships() [1/2]

std::vector< relationship > & clanguml::common::model::diagram_element::relationships ( )

Return all relationships outgoing from this element.

Returns
List of relationships.

Definition at line 69 of file diagram_element.cc.

70{
71 return relationships_;
72}

◆ relationships() [2/2]

const std::vector< relationship > & clanguml::common::model::diagram_element::relationships ( ) const

Return all relationships outgoing from this element.

Returns
List of relationships.

Definition at line 74 of file diagram_element.cc.

75{
76 return relationships_;
77}

◆ set_id()

void clanguml::common::model::diagram_element::set_id ( eid_t  id)

Set elements id.

Parameters
idElements id.

Definition at line 32 of file diagram_element.cc.

32{ id_ = id; }

◆ set_name()

void clanguml::common::model::diagram_element::set_name ( const std::string &  name)
inline

Set diagram elements name.

Parameters
nameElements name.

Definition at line 96 of file diagram_element.h.

96{ name_ = name; }

◆ set_parent_element_id()

void clanguml::common::model::diagram_element::set_parent_element_id ( eid_t  id)

Set elements parent package id.

Parameters
idId of parent package.

Definition at line 39 of file diagram_element.cc.

40{
42}

◆ type_name()

virtual std::string clanguml::common::model::diagram_element::type_name ( ) const
inlinevirtual

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
const diagram_element rhs 
)
friend

Definition at line 124 of file diagram_element.cc.

125{
126 out << "(" << rhs.name() << ", full_name=[" << rhs.full_name(false) << "])";
127
128 return out;
129}

◆ operator==

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

Definition at line 119 of file diagram_element.cc.

120{
121 return l.id() == r.id();
122}

Member Data Documentation

◆ complete_

bool clanguml::common::model::diagram_element::complete_ {false}
private

Definition at line 199 of file diagram_element.h.

◆ id_

eid_t clanguml::common::model::diagram_element::id_ {}
private

Definition at line 194 of file diagram_element.h.

◆ name_

std::string clanguml::common::model::diagram_element::name_
private

Definition at line 196 of file diagram_element.h.

◆ nested_

bool clanguml::common::model::diagram_element::nested_ {false}
private

Definition at line 198 of file diagram_element.h.

◆ parent_element_id_

std::optional<eid_t> clanguml::common::model::diagram_element::parent_element_id_ {}
private

Definition at line 195 of file diagram_element.h.

◆ relationships_

std::vector<relationship> clanguml::common::model::diagram_element::relationships_
private

Definition at line 197 of file diagram_element.h.


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