0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
src
common
model
element_view.h
Go to the documentation of this file.
1
/**
2
* @file src/common/model/element_view.h
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
#pragma once
19
20
#include "
common/types.h
"
21
22
namespace
clanguml::common::model
{
23
24
using
clanguml::common::eid_t
;
25
26
/**
27
* Provides type based views over elements in a diagram.
28
*
29
* @tparam T Type of diagram element
30
*/
31
template
<
typename
T>
class
element_view
{
32
public
:
33
/**
34
* @brief Add reference to diagram element
35
*
36
* @param element Reference to diagram element of specific type
37
*/
38
void
add
(std::reference_wrapper<T>
element
)
39
{
40
elements_
.emplace_back(std::move(
element
));
41
}
42
43
/**
44
* @brief Get collection of reference to diagram elements
45
*
46
* @return
47
*/
48
const
reference_vector<T>
&
view
()
const
{
return
elements_
; }
49
50
/**
51
* @brief Get collection of reference to diagram elements
52
*
53
* @return
54
*/
55
reference_vector<T>
&
view
() {
return
elements_
; }
56
57
/**
58
* @brief Get typed diagram element by id
59
* @param id Global id of a diagram element
60
*
61
* @return
62
*/
63
common::optional_ref<T>
get
(
eid_t
id
)
const
64
{
65
for
(
const
auto
&e :
elements_
) {
66
if
(e.get().id() == id) {
67
return
{e};
68
}
69
}
70
71
return
{};
72
}
73
74
/**
75
* @brief Check whether the element view is empty
76
*
77
* @return True, if the view does not contain any elements
78
*/
79
bool
is_empty
()
const
{
return
elements_
.empty(); }
80
81
void
remove
(
const
std::set<eid_t> &element_ids)
82
{
83
elements_
.erase(std::remove_if(
elements_
.begin(),
elements_
.end(),
84
[&element_ids](
auto
&&e) {
85
return element_ids.count(e.get().id()) > 0;
86
}),
87
elements_
.end());
88
}
89
90
private
:
91
reference_vector<T>
elements_
;
92
};
93
94
}
// namespace clanguml::common::model
Copyright © 2022-present
Bartek Kryza
Generated by
1.9.7