0.5.4
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-2024 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
auto
ns =
ns_
|
name
();
53
return
ns.to_string();
54
}
55
56
/**
57
* Set elements namespace.
58
*
59
* @param ns Namespace.
60
*/
61
void
set_namespace
(
const
namespace_
&ns) {
ns_
= ns; }
62
63
/**
64
* Return elements namespace.
65
*
66
* @return Namespace.
67
*/
68
namespace_
get_namespace
()
const
{
return
ns_
; }
69
70
/**
71
* Return elements relative namespace.
72
*
73
* @return Namespace.
74
*/
75
namespace_
get_relative_namespace
()
const
76
{
77
return
ns_
.
relative_to
(
using_namespace_
);
78
}
79
80
/**
81
* Return elements namespace as path.
82
*
83
* Namespace is a nested path in diagrams where packages are generated
84
* from namespaces.
85
*
86
* @return Namespace.
87
*/
88
const
namespace_
&
path
()
const
{
return
ns_
; }
89
90
/**
91
* Set elements owning module.
92
*
93
* @param module C++20 module.
94
*/
95
void
set_module
(
const
std::string &
module
) {
module_
=
module
; }
96
97
/**
98
* Return elements owning module, if any.
99
*
100
* @return C++20 module.
101
*/
102
std::optional<std::string>
module
()
const
{
return
module_
; }
103
104
/**
105
* Set whether the element is in a private module
106
*
107
* @param module C++20 module.
108
*/
109
void
set_module_private
(
const
bool
module_private
)
110
{
111
module_private_
=
module_private
;
112
}
113
114
/**
115
* Check whether the element is in a private module.
116
*
117
* @return C++20 module.
118
*/
119
bool
module_private
()
const
{
return
module_private_
; }
120
121
/**
122
* Return elements full name.
123
*
124
* @return Fully qualified elements name.
125
*/
126
std::string
full_name
(
bool
relative)
const override
127
{
128
if
(relative)
129
return
name
();
130
131
return
name_and_ns
();
132
}
133
134
/**
135
* Return elements full name but without namespace.
136
*
137
* @return Elements full name without namespace.
138
*/
139
virtual
std::string
full_name_no_ns
()
const
{
return
name
(); }
140
141
/**
142
* Return the relative namespace from config.
143
*
144
* @return Namespace.
145
*/
146
const
namespace_
&
using_namespace
()
const
;
147
148
friend
bool
operator==
(
const
element
&l,
const
element
&r);
149
150
friend
std::ostream &
operator<<
(std::ostream &out,
const
element
&rhs);
151
152
inja::json
context
()
const override
;
153
154
private
:
155
namespace_
ns_
;
156
namespace_
using_namespace_
;
157
std::optional<std::string>
module_
;
158
bool
module_private_
{
false
};
159
};
160
}
// namespace clanguml::common::model
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7