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/mermaid/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 mermaid {
37
39
42
43template <typename C, typename D>
45
46/**
47 * @brief Sequence diagram MermaidJS generator
48 */
49class generator : public common_generator<diagram_config, diagram_model> {
50public:
52
54
55 /**
56 * @brief Main generator method.
57 *
58 * This method is called first and coordinates the entire diagram
59 * generation.
60 *
61 * @param ostr Output stream.
62 */
63 void generate_diagram(std::ostream &ostr) const override;
64
65 /**
66 * @brief Generate the diagram type
67 *
68 * @param ostr Output stream
69 */
70 void generate_diagram_type(std::ostream &ostr) const override;
71
72 /**
73 * @brief Generate sequence diagram message.
74 *
75 * @param m Message model
76 * @param ostr Output stream
77 */
79 std::ostream &ostr) const;
80
81 /**
82 * @brief Generate sequence diagram return message
83 *
84 * @param m Message model
85 * @param ostr Output stream
86 */
88 std::ostream &ostr) const;
89
90 /**
91 * @brief Generate sequence diagram participant
92 *
93 * @param ostr Output stream
94 * @param id Participant id
95 * @param force If true, generate the participant even if its not in
96 * the set of active participants
97 * @return Id of the generated participant
98 */
100 std::ostream &ostr, eid_t id, bool force = false) const;
101
102 /**
103 * @brief Generate sequence diagram participant by name
104 *
105 * This is convenience wrapper over `generate_participant()` by id.
106 *
107 * @param ostr Output stream
108 * @param name Full participant name
109 */
111 std::ostream &ostr, const std::string &name) const;
112
113 /**
114 * @brief Generate sequence diagram activity.
115 *
116 * @param a Activity model
117 * @param ostr Output stream
118 * @param visited List of already visited participants, this is necessary
119 * for breaking infinite recursion on recursive calls
120 */
122 std::ostream &ostr, std::vector<eid_t> &visited) const;
123
124private:
125 /**
126 * @brief Check if specified participant has already been generated.
127 *
128 * @param id Participant id.
129 * @return True, if participant has already been generated.
130 */
131 bool is_participant_generated(eid_t id) const;
132
133 /**
134 * @brief Generate MermaidJS alias for participant
135 *
136 * @param participant Sequence diagram participant model
137 * @return Particpant alias
138 */
139 std::string generate_alias(const model::participant &participant) const;
140
141 /**
142 * @brief Generate message call note
143 *
144 * @param ostr Output stream
145 * @param m Message
146 */
148 std::ostream &ostr, const model::message &m) const;
149
150 /**
151 * @brief Convert config to model message render mode.
152 *
153 * @return Method render mode.
154 */
157
158 mutable std::set<eid_t> generated_participants_;
159 mutable std::set<unsigned int> generated_comment_ids_;
160 mutable std::vector<model::message> already_generated_in_static_context_;
161};
162
163} // namespace mermaid
164} // namespace generators
165} // namespace sequence_diagram
166} // namespace clanguml