0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
src
common
model
element.h
Go to the documentation of this file.
1
/**
2
* @file src/common/model/element.h
3
*
4
* Copyright (c) 2021-2025 Bartek Kryza <bkryza@gmail.com>
5
*
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
9
*
10
* http://www.apache.org/licenses/LICENSE-2.0
11
*
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
17
*/
18
#pragma once
19
20
#include "
diagram_element.h
"
21
#include "
namespace.h
"
22
#include "
relationship.h
"
23
#include "
source_location.h
"
24
#include "
util/util.h
"
25
26
#include <inja/inja.hpp>
27
28
#include <atomic>
29
#include <exception>
30
#include <string>
31
#include <vector>
32
33
namespace
clanguml::common::model
{
34
35
/**
36
* @brief Base class for any element qualified by namespace.
37
*/
38
class
element
:
public
diagram_element
{
39
public
:
40
element
(
namespace_
using_namespace
,
path_type
pt =
path_type::kNamespace
);
41
42
~element
()
override
=
default
;
43
44
/**
45
* Return the elements fully qualified name, but without template
46
* arguments or function params.
47
*
48
* @return Fully qualified element name.
49
*/
50
std::string
name_and_ns
()
const
51
{
52
return
util::memoized<name_and_ns_tag, std::string>::memoize
(
53
true
, [
this
]() {
return
name_and_ns_impl
(); });
54
}
55
56
/**
57
* Set elements namespace.
58
*
59
* @param ns Namespace.
60
*/
61
void
set_namespace
(
const
namespace_
&ns)
62
{
63
util::memoized<name_and_ns_tag, std::string>::invalidate
();
64
ns_
= ns;
65
}
66
67
/**
68
* Return elements namespace.
69
*
70
* @return Namespace.
71
*/
72
namespace_
get_namespace
()
const
{
return
ns_
; }
73
74
/**
75
* Return elements relative namespace.
76
*
77
* @return Namespace.
78
*/
79
namespace_
get_relative_namespace
()
const
80
{
81
return
ns_
.
relative_to
(
using_namespace_
);
82
}
83
84
/**
85
* Return elements namespace as path.
86
*
87
* Namespace is a nested path in diagrams where packages are generated
88
* from namespaces.
89
*
90
* @return Namespace.
91
*/
92
const
namespace_
&
path
()
const
{
return
ns_
; }
93
94
/**
95
* Set elements owning module.
96
*
97
* @param module C++20 module.
98
*/
99
void
set_module
(
const
std::string &
module
) {
module_
=
module
; }
100
101
/**
102
* Return elements owning module, if any.
103
*
104
* @return C++20 module.
105
*/
106
std::optional<std::string>
module
()
const
{
return
module_
; }
107
108
/**
109
* Set whether the element is in a private module
110
*
111
* @param module C++20 module.
112
*/
113
void
set_module_private
(
const
bool
module_private
)
114
{
115
module_private_
=
module_private
;
116
}
117
118
/**
119
* Check whether the element is in a private module.
120
*
121
* @return C++20 module.
122
*/
123
bool
module_private
()
const
{
return
module_private_
; }
124
125
/**
126
* Return elements full name but without namespace.
127
*
128
* @return Elements full name without namespace.
129
*/
130
virtual
std::string
full_name_no_ns
()
const
{
return
name
(); }
131
132
/**
133
* Return the relative namespace from config.
134
*
135
* @return Namespace.
136
*/
137
const
namespace_
&
using_namespace
()
const
;
138
139
friend
bool
operator==
(
const
element
&l,
const
element
&r);
140
141
friend
std::ostream &
operator<<
(std::ostream &out,
const
element
&rhs);
142
143
protected
:
144
/**
145
* Return elements full name.
146
*
147
* @return Fully qualified elements name.
148
*/
149
std::string
full_name_impl
(
bool
relative)
const override
150
{
151
if
(relative)
152
return
name
();
153
154
return
name_and_ns
();
155
}
156
157
virtual
std::string
name_and_ns_impl
()
const
158
{
159
auto
ns =
ns_
|
name
();
160
return
ns.to_string();
161
}
162
163
private
:
164
namespace_
ns_
;
165
namespace_
using_namespace_
;
166
std::optional<std::string>
module_
;
167
bool
module_private_
{
false
};
168
};
169
170
}
// namespace clanguml::common::model
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7