0.5.4
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-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
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
// This is sadly necessary to catch accidental comparisons to empty
62
// std::optional<id_t>:
63
//
64
// std::optional<id_t> id{};
65
// if(id != 0) { /* id is nullopt, not 0 - so this executes... */ }
66
//
67
assert(v != 0);
68
69
return
lhs.
value_
!= v;
70
}
71
72
bool
operator!=
(
const
eid_t
&lhs,
const
eid_t
&rhs) {
return
!(lhs == rhs); }
73
74
bool
operator<
(
const
eid_t
&lhs,
const
eid_t
&rhs)
75
{
76
if
(lhs.
is_global_
!= rhs.
is_global_
) {
77
return
lhs.
value_
< rhs.
value_
+ 1;
78
}
79
80
return
lhs.
value_
< rhs.
value_
;
// Compare values if is_global_ are the same
81
}
82
83
eid_t::type
eid_t::value
()
const
{
return
value_
; }
84
85
int64_t
eid_t::ast_local_value
()
const
86
{
87
assert(!
is_global_
);
88
89
return
static_cast<
int64_t
>
(
value_
);
90
}
91
92
std::string
to_string
(
const
std::string &s) {
return
s; }
93
94
std::string
to_string
(
const
string_or_regex
&sr) {
return
sr.
to_string
(); }
95
96
std::string
to_string
(
const
generator_type_t
type)
97
{
98
switch
(type) {
99
case
generator_type_t::plantuml
:
100
return
"plantuml"
;
101
case
generator_type_t::mermaid
:
102
return
"mermaid"
;
103
case
generator_type_t::json
:
104
return
"json"
;
105
default
:
106
return
"<unknown>"
;
107
}
108
}
109
}
// namespace clanguml::common
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7