0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
src
common
generators
json
generator.cc
Go to the documentation of this file.
1
/**
2
* @file src/common/generators/json/generator.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 "
generator.h
"
20
21
namespace
clanguml::common
{
22
namespace
model {
23
using
nlohmann::json;
24
25
using
clanguml::common::generators::display_name_adapter
;
26
27
void
to_json
(nlohmann::json &j,
const
source_location
&sl)
28
{
29
j =
json
{{
"file"
, sl.
file_relative
()},
30
{
"translation_unit"
, sl.
translation_unit
()}, {
"line"
, sl.
line
()},
31
{
"column"
, sl.
column
()}};
32
}
33
34
void
to_json
(nlohmann::json &j,
const
element
&c)
35
{
36
j =
json
{{
"id"
, std::to_string(c.
id
().
value
())}, {
"name"
, c.
name
()},
37
{
"namespace"
, c.
get_namespace
().
to_string
()}, {
"type"
, c.
type_name
()},
38
{
"display_name"
,
display_name_adapter
(c).
full_name
(
true
)}};
39
40
if
(
const
auto
&comment = c.
comment
(); comment)
41
j[
"comment"
] = comment.value();
42
43
if
(!c.
file
().empty()) {
44
j[
"source_location"
] =
45
dynamic_cast<
const
common::model::source_location
&
>
(c);
46
}
47
}
48
49
void
to_json
(nlohmann::json &j,
const
template_parameter
&c)
50
{
51
j[
"kind"
] =
to_string
(c.
kind
());
52
if
(
const
auto
&t = c.
type
(); t)
53
j[
"type"
] = t.value();
54
if
(
const
auto
&n = c.
name
(); n)
55
j[
"name"
] = n.value();
56
if
(
const
auto
&d = c.
default_value
(); d)
57
j[
"default"
] = d.value();
58
j[
"is_variadic"
] = c.
is_variadic
();
59
j[
"template_parameters"
] = c.
template_params
();
60
}
61
62
void
to_json
(nlohmann::json &j,
const
relationship
&c)
63
{
64
j[
"type"
] =
to_string
(c.
type
());
65
j[
"destination"
] = std::to_string(c.
destination
().
value
());
66
if
(!c.
multiplicity_source
().empty())
67
j[
"multiplicity_source"
] = c.
multiplicity_source
();
68
if
(!c.
multiplicity_destination
().empty())
69
j[
"multiplicity_destination"
] = c.
multiplicity_destination
();
70
if
(c.
access
() !=
access_t::kNone
)
71
j[
"access"
] =
to_string
(c.
access
());
72
if
(!c.
label
().empty())
73
j[
"label"
] = c.
label
();
74
if
(
const
auto
&comment = c.
comment
(); comment)
75
j[
"comment"
] = comment.value();
76
}
77
}
// namespace model
78
}
// namespace clanguml::common
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7