0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
src
common
types.cc
Go to the documentation of this file.
1
/**
2
* @file src/common/types.cc
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
19
#include "
types.h
"
20
21
namespace
clanguml::common
{
22
23
eid_t::eid_t
()
24
: value_{0ULL}
25
, is_global_{true}
26
{
27
}
28
29
eid_t::eid_t
(int64_t
id
)
30
: value_{static_cast<
type
>(id)}
31
, is_global_{false}
32
{
33
}
34
35
eid_t::eid_t
(
type
id
)
36
: value_{id}
37
, is_global_{true}
38
{
39
}
40
41
eid_t
&
eid_t::operator=
(int64_t ast_id)
42
{
43
// Can't assign ast_id if the id is already a global one
44
assert(!
is_global_
);
45
46
value_
=
static_cast<
uint64_t
>
(ast_id);
47
return
*
this
;
48
}
49
50
bool
eid_t::is_global
()
const
{
return
is_global_
; }
51
52
bool
operator==
(
const
eid_t
&lhs,
const
eid_t
&rhs)
53
{
54
return
(lhs.
is_global_
== rhs.
is_global_
) && (lhs.
value_
== rhs.
value_
);
55
}
56
57
bool
operator==
(
const
eid_t
&lhs,
const
uint64_t &v) {
return
lhs.
value_
== v; }
58
59
bool
operator!=
(
const
eid_t
&lhs,
const
uint64_t &v)
60
{
61
assert(v != 0);
62
63
return
lhs.
value_
!= v;
64
}
65
66
bool
operator!=
(
const
eid_t
&lhs,
const
eid_t
&rhs) {
return
!(lhs == rhs); }
67
68
bool
operator<
(
const
eid_t
&lhs,
const
eid_t
&rhs)
69
{
70
if
(lhs.
is_global_
!= rhs.
is_global_
) {
71
return
lhs.
value_
< rhs.
value_
+ 1;
72
}
73
74
return
lhs.
value_
< rhs.
value_
;
// Compare values if is_global_ are the same
75
}
76
77
eid_t::type
eid_t::value
()
const
{
return
value_
; }
78
79
int64_t
eid_t::ast_local_value
()
const
80
{
81
assert(!
is_global_
);
82
83
return
static_cast<
int64_t
>
(
value_
);
84
}
85
86
std::string
to_string
(
const
bool
v) {
return
v ?
"true"
:
"false"
; }
87
88
std::string
to_string
(
const
std::string &s) {
return
s; }
89
90
std::string
to_string
(
const
string_or_regex
&sr) {
return
sr.
to_string
(); }
91
92
std::string
to_string
(
const
std::filesystem::path &p) {
return
p.string(); }
93
94
std::string
to_string
(
const
generator_type_t
type)
95
{
96
switch
(type) {
97
case
generator_type_t::plantuml
:
98
return
"plantuml"
;
99
case
generator_type_t::mermaid
:
100
return
"mermaid"
;
101
case
generator_type_t::json
:
102
return
"json"
;
103
case
generator_type_t::graphml
:
104
return
"graphml"
;
105
default
:
106
return
"<unknown>"
;
107
}
108
}
109
}
// namespace clanguml::common
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7