0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Classes | Functions
clanguml::decorators Namespace Reference

Classes

struct  aggregation
 Make a member an aggregation relationship. More...
 
struct  association
 Make a member an association relationship. More...
 
struct  call
 Represents a call message in sequence diagram. More...
 
struct  composition
 Make a member a composition relationship. More...
 
struct  decorator
 Base class for clang-uml comment tags. More...
 
struct  decorator_toks
 
struct  note
 Represents a note diagram element. More...
 
struct  relationship
 Base class for decorators overriding default relationship types. More...
 
struct  skip
 Whether a decorated element should be skipped from a diagram. More...
 
struct  skip_relationship
 Whether a decorated relationships should be skipped from a diagram. More...
 
struct  style
 Apply specific style to a decorated diagram element. More...
 

Functions

std::pair< std::vector< std::shared_ptr< decorator > >, std::string > parse (std::string documentation_block, const std::string &clanguml_tag="uml")
 Parse a documentation block and extract all clang-uml decorators.
 

Function Documentation

◆ parse()

std::pair< std::vector< std::shared_ptr< decorator > >, std::string > clanguml::decorators::parse ( std::string  documentation_block,
const std::string &  clanguml_tag = "uml" 
)

Parse a documentation block and extract all clang-uml decorators.

Parameters
documentation_blockDocumentation block extracted from source code
clanguml_tagName of the clanguml tag (default uml)
Returns
Pair of: a list of clang-uml decorators extracted from comment and a comment stripped of any uml directives

Definition at line 190 of file decorators.cc.

192{
193 std::vector<std::shared_ptr<decorator>> res;
194 std::string stripped_comment;
195
196 const std::string begin_tag{"@" + clanguml_tag};
197 const auto begin_tag_size = begin_tag.size();
198
199 // First replace all \uml occurences with @uml
200 util::replace_all(
201 documentation_block, "\\" + clanguml_tag, "@" + clanguml_tag);
202 documentation_block = util::trim(documentation_block);
203
204 const std::string_view block_view{documentation_block};
205
206 auto pos = block_view.find("@" + clanguml_tag + "{");
207
208 if (pos == std::string::npos) {
209 // This comment had no uml directives
210 return {{}, util::trim(documentation_block)};
211 }
212
213 size_t last_end_pos{0};
214 while (pos < documentation_block.size()) {
215 auto c_begin = pos + begin_tag_size;
216 auto c_end = block_view.find('}', c_begin);
217
218 if (c_end == std::string::npos) {
219 return {res, util::trim(stripped_comment)};
220 }
221
222 auto com =
223 decorator::from_string(block_view.substr(c_begin + 1, c_end - 2));
224
225 if (com)
226 res.emplace_back(std::move(com));
227
228 const auto in_between_length = pos - last_end_pos;
229 stripped_comment += block_view.substr(last_end_pos, in_between_length);
230
231 last_end_pos = pos + (c_end - c_begin + begin_tag_size + 1);
232
233 pos = block_view.find("@" + clanguml_tag + "{", c_end);
234 }
235
236 return {res, util::trim(stripped_comment)};
237};