0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
src
common
generators
nested_element_stack.h
Go to the documentation of this file.
1
/**
2
* @file src/common/generators/nested_element_stack.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 <cstdint>
21
#include <map>
22
#include <string>
23
#include <vector>
24
25
namespace
clanguml::common::generators
{
26
27
/**
28
* This is a helper class for generating nested groups of elements
29
* in the diagrams, e.g. PlantUML `together` option.
30
*
31
* @tparam T Type of stack elements
32
*/
33
template
<
typename
T>
class
nested_element_stack
{
34
public
:
35
nested_element_stack
(
bool
is_flat
)
36
:
is_flat_
{
is_flat
}
37
{
38
current_level_groups_
.push_back({});
39
}
40
41
/**
42
* Switch to next level in the element stack
43
*/
44
void
enter
()
45
{
46
if
(!
is_flat_
)
47
current_level_
++;
48
49
current_level_groups_
.push_back({});
50
}
51
52
/**
53
* Switch to previous level in the element stack
54
*/
55
void
leave
()
56
{
57
if
(!
is_flat_
)
58
current_level_
--;
59
60
current_level_groups_
.pop_back();
61
}
62
63
/**
64
* Add element pointer to a specified group at the current level
65
*/
66
void
group_together
(
const
std::string &group_name, T *e)
67
{
68
current_level_groups_
[
current_level_
][group_name].push_back(e);
69
}
70
71
/**
72
* Get map of element groups at the current level.
73
*
74
* @return Reference to element groups.
75
*/
76
const
std::map<std::string, std::vector<T *>> &
get_current_groups
()
77
{
78
return
current_level_groups_
.at(
current_level_
);
79
}
80
81
/**
82
* Get element group by name - the group must exist at the current level.
83
*
84
* @param group_name Element group name
85
* @return
86
*/
87
const
std::vector<T *> &
get_group
(
const
std::string &group_name)
88
{
89
return
get_current_groups
().at(group_name);
90
}
91
92
bool
is_flat
()
const
{
return
is_flat_
; }
93
94
private
:
95
bool
is_flat_
;
96
97
uint32_t
current_level_
{0};
98
99
std::vector<std::map<std::string, std::vector<T *>>>
current_level_groups_
;
100
};
101
102
}
// namespace clanguml::common::generators
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7