0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
src
common
model
jinja_context.h
Go to the documentation of this file.
1
/**
2
* @file src/common/model/jinja_context.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 "
common/model/diagram.h
"
21
#include "
common/model/diagram_element.h
"
22
#include "
common/model/element.h
"
23
#include "
common/model/element_view.h
"
24
#include "
util/error.h
"
25
26
#include <inja/inja.hpp>
27
28
#include <string>
29
30
namespace
clanguml::common::jinja
{
31
32
struct
diagram_context_tag;
33
struct
element_context_tag;
34
35
/**
36
* @brief Jinja diagram element context wrapper
37
*
38
* This template allows to have custom adl serializers for JSON, which only work
39
* for Jinja templates, and not JSON generator.
40
*
41
* @tparam T Diagram model element
42
*/
43
template
<
typename
T,
typename
Tag>
class
jinja_context
{
44
public
:
45
explicit
jinja_context
(
46
const
T &e,
const
inja::json &
diagram_context
) noexcept
47
:
value_
{e}
48
,
diagram_context_
{
diagram_context
}
49
{
50
}
51
52
explicit
jinja_context
(
const
T &e) noexcept
53
:
jinja_context
(e, {})
54
{
55
}
56
57
const
T &
get
() const noexcept {
return
value_
; }
58
59
template
<
typename
U>
const
jinja_context<U, Tag>
as
()
const
60
{
61
return
jinja_context<U, Tag>
(
62
dynamic_cast<
const
U &
>
(
value_
),
diagram_context_
);
63
}
64
65
const
inja::json &
diagram_context
()
const
{
return
diagram_context_
; }
66
67
private
:
68
const
T &
value_
;
69
const
inja::json &
diagram_context_
;
70
};
71
72
template
<
typename
T>
73
using
element_context
=
jinja_context<T, element_context_tag>
;
74
template
<
typename
T>
75
using
diagram_context
=
jinja_context<T, diagram_context_tag>
;
76
77
void
to_json
(inja::json &ctx,
78
const
element_context<common::model::decorated_element>
&jc);
79
80
void
to_json
(
81
inja::json &ctx,
const
element_context<common::model::diagram_element>
&jc);
82
83
void
to_json
(
84
inja::json &ctx,
const
element_context<common::model::element>
&jc);
85
86
void
to_json
(
87
inja::json &ctx,
const
element_context<common::model::relationship>
&jc);
88
89
void
to_json
(
90
inja::json &ctx,
const
element_context<common::model::source_file>
&jc);
91
92
void
to_json
(
93
inja::json &ctx,
const
element_context<common::model::source_location>
&jc);
94
95
void
to_json
(inja::json &ctx,
96
const
diagram_context<common::model::decorated_element>
&jc);
97
98
void
to_json
(
99
inja::json &ctx,
const
diagram_context<common::model::diagram_element>
&jc);
100
101
void
to_json
(
102
inja::json &ctx,
const
diagram_context<common::model::element>
&jc);
103
104
void
to_json
(
105
inja::json &ctx,
const
diagram_context<common::model::source_file>
&jc);
106
107
void
to_json
(
108
inja::json &ctx,
const
diagram_context<common::model::source_location>
&jc);
109
110
std::optional<std::string>
render_template
(inja::Environment &env,
111
const
inja::json &
context
,
const
std::string &jinja_template);
112
113
std::optional<std::string>
render_template
(
114
inja::Environment &env,
const
std::string &jinja_template);
115
116
}
// namespace clanguml::common::jinja
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7