0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
sequence_diagram_generator.h
Go to the documentation of this file.
1/**
2 * @file src/sequence_diagram/generators/plantuml/sequence_diagram_generator.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
21#include "config/config.h"
24#include "util/util.h"
25
26#include <glob/glob.hpp>
27
28#include <filesystem>
29#include <fstream>
30#include <iostream>
31#include <sstream>
32
33namespace clanguml {
34namespace sequence_diagram {
35namespace generators {
36namespace plantuml {
37
39
42
43template <typename C, typename D>
46
47/**
48 * @brief Sequence diagram PlantUML generator
49 */
50class generator : public common_generator<diagram_config, diagram_model> {
51public:
53
55
56 /**
57 * @brief Main generator method.
58 *
59 * This method is called first and coordinates the entire diagram
60 * generation.
61 *
62 * @param ostr Output stream.
63 */
64 void generate_diagram(std::ostream &ostr) const override;
65
66 /**
67 * @brief Generate sequence diagram message.
68 *
69 * @param m Message model
70 * @param ostr Output stream
71 */
73 std::ostream &ostr) const;
74
75 /**
76 * @brief Generate sequence diagram return message
77 *
78 * @param m Message model
79 * @param ostr Output stream
80 */
82 std::ostream &ostr) const;
83
84 /**
85 * @brief Generate sequence diagram participant
86 *
87 * @param ostr Output stream
88 * @param id Participant id
89 * @param force If true, generate the participant even if its not in
90 * the set of active participants
91 * @return Id of the generated participant
92 */
94 std::ostream &ostr, eid_t id, bool force = false) const;
95
96 /**
97 * @brief Generate sequence diagram participant by name
98 *
99 * This is convienience wrapper over `generate_participant()` by id.
100 *
101 * @param ostr Output stream
102 * @param name Full participant name
103 */
105 std::ostream &ostr, const std::string &name) const;
106
107 /**
108 * @brief Generate sequence diagram activity.
109 *
110 * @param a Activity model
111 * @param ostr Output stream
112 * @param visited List of already visited participants, this is necessary
113 * for breaking infinite recursion on recursive calls
114 */
116 std::ostream &ostr, std::vector<eid_t> &visited) const;
117
118private:
119 /**
120 * @brief Check if specified participant has already been generated.
121 *
122 * @param id Participant id.
123 * @return True, if participant has already been generated.
124 */
125 bool is_participant_generated(eid_t id) const;
126
127 /**
128 * @brief Generate PlantUML alias for participant
129 *
130 * @param participant Sequence diagram participant model
131 * @return Particpant alias
132 */
133 std::string generate_alias(const model::participant &participant) const;
134
135 /**
136 * @brief Escape the symbols in the name for PlantUML
137 *
138 * @param name Full participant name
139 * @return Escaped name
140 */
141 std::string render_name(std::string name) const;
142
143 /**
144 * @brief Generate message call note
145 *
146 * @param ostr Output stream
147 * @param m Message
148 */
150 std::ostream &ostr, const model::message &m) const;
151
152 /**
153 * @brief Convert config to model message render mode.
154 *
155 * @return Method render mode.
156 */
159
160 mutable std::set<eid_t> generated_participants_;
161 mutable std::set<unsigned int> generated_comment_ids_;
162 mutable std::vector<model::message> already_generated_in_static_context_;
163};
164
165} // namespace plantuml
166} // namespace generators
167} // namespace sequence_diagram
168} // namespace clanguml