0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
decorated_element.h
Go to the documentation of this file.
1/**
2 * @file src/common/model/decorated_element.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 "enums.h"
21
23#include "inja/inja.hpp"
24
25#include <any>
26#include <memory>
27#include <optional>
28#include <string>
29#include <unordered_map>
30#include <variant>
31#include <vector>
32
34
35using comment_t = inja::json;
36
37/**
38 * @brief Base class for decorated diagram elements
39 *
40 * Decorators in `clang-uml` mean that custom `@uml{}` directives can be
41 * applied to them in the code comments.
42 *
43 * @embed{decorated_element_hierarchy_class.svg}
44 *
45 * @see clanguml::decorators::decorator
46 *
47 */
49public:
50 virtual ~decorated_element() = default;
51
52 /**
53 * Whether this element should be skipped from the diagram.
54 *
55 * @return
56 */
57 bool skip() const;
58
59 /**
60 * Whether this relationship should be skipped from the diagram.
61 *
62 * @return
63 */
64 bool skip_relationship() const;
65
66 /**
67 * If this element is a member or a method, get relationship decorator
68 * if any.
69 *
70 * @code
71 * /// @uml{aggregation[0..1:1..5]}
72 * std::vector<C> ccc;
73 * @endcode
74 *
75 * @return Relationship specified as a decorator on class member.
76 */
77 std::pair<relationship_t, std::string> get_relationship() const;
78
79 /**
80 * Get stype specification for this element, if any.
81 *
82 * @code
83 * /// @uml{style[#back:lightgreen|yellow;header:blue/red]}
84 * class A { };
85 * @endcode
86 *
87 * @return
88 */
89 std::string style_spec() const;
90
91 /**
92 * Get all decorators for this element.
93 *
94 * @return List of decorator pointers.
95 */
96 const std::vector<std::shared_ptr<decorators::decorator>> &
97 decorators() const;
98
99 /**
100 * Add decorators to the element.
101 *
102 * @param decorators List of decorator pointers.
103 */
104 void add_decorators(
105 const std::vector<std::shared_ptr<decorators::decorator>> &decorators);
106
107 /**
108 * Append decorators from another element.
109 *
110 * @param de Source element to copy decorators from.
111 */
112 void append(const decorated_element &de);
113
114 /**
115 * Get entire comment model for this element.
116 *
117 * @return Comment model.
118 */
119 std::optional<comment_t> comment() const;
120
121 /**
122 * Set comment model for this element.
123 *
124 * Comment model is currently a JSON object.
125 *
126 * @param c Comment model.
127 */
128 void set_comment(const comment_t &c);
129
130 /**
131 * Return Doxygen HTML documentation link for the element.
132 *
133 * @return Element context.
134 */
135 virtual std::optional<std::string> doxygen_link() const;
136
137private:
138 std::vector<std::shared_ptr<decorators::decorator>> decorators_;
139 std::optional<comment_t> comment_;
140};
141
142} // namespace clanguml::common::model