0.5.4
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
clanguml::common::model::template_parameter Class Reference

Represents template parameter, template arguments or concept constraints. More...

Detailed Description

Represents template parameter, template arguments or concept constraints.

This class can represent both template parameter and template arguments, including variadic parameters and instantiations with nested templates

Definition at line 82 of file template_parameter.h.

#include <template_parameter.h>

Public Member Functions

void set_type (const std::string &type)
 
std::optional< std::string > type () const
 
void set_id (const eid_t &id)
 
const std::optional< eid_t > & id () const
 
void set_name (const std::string &name)
 
std::optional< std::string > name () const
 
void set_default_value (const std::string &value)
 
const std::optional< std::string > & default_value () const
 
void is_variadic (bool is_variadic) noexcept
 
bool is_variadic () const noexcept
 
int calculate_specialization_match (const template_parameter &base_template_parameter) const
 Calculate the match between this and other parameter.
 
bool is_template_parameter () const
 
void is_template_parameter (bool is_template_parameter)
 
bool is_template_template_parameter () const
 
void is_template_template_parameter (bool is_template_template_parameter)
 
bool is_unexposed () const
 
void set_unexposed (bool unexposed)
 
void is_function_template (bool ft)
 
bool is_function_template () const
 
void is_member_pointer (bool m)
 
bool is_member_pointer () const
 
void is_data_pointer (bool m)
 
bool is_data_pointer () const
 
void is_array (bool a)
 
bool is_array () const
 
void add_template_param (template_parameter &&ct)
 
void add_template_param (const template_parameter &ct)
 
const std::vector< template_parameter > & template_params () const
 
void clear_params ()
 
bool is_association () const
 
bool is_specialization () const
 
bool is_same_specialization (const template_parameter &other) const
 Whether this is the same type of specialization as other.
 
bool find_nested_relationships (std::vector< std::pair< eid_t, common::model::relationship_t > > &nested_relationships, common::model::relationship_t hint, const std::function< bool(const std::string &full_name)> &should_include) const
 Find all relationships in this and its nested templates.
 
void set_concept_constraint (std::string constraint)
 
const std::optional< std::string > & concept_constraint () const
 
template_parameter_kind_t kind () const
 
void set_kind (template_parameter_kind_t kind)
 
void push_context (const context &q)
 Append a deduced context to the template parameter.
 
const std::deque< context > & deduced_context () const
 
void deduced_context (std::deque< context > c)
 
void is_ellipsis (bool e)
 
bool is_ellipsis () const
 
std::string to_string (const clanguml::common::model::namespace_ &using_namespace, bool relative, bool skip_qualifiers=false) const
 Render the template_parameter into string.
 

Static Public Member Functions

static template_parameter make_template_type (const std::string &name, const std::optional< std::string > &default_value={}, bool is_variadic=false)
 Build template type parameter.
 
static template_parameter make_template_template_type (const std::string &name, const std::optional< std::string > &default_value={}, bool is_variadic=false)
 Build template template parameter type.
 
static template_parameter make_non_type_template (const std::string &type, const std::optional< std::string > &name, const std::optional< std::string > &default_value={}, bool is_variadic=false)
 Build non-type template parameter.
 
static template_parameter make_argument (const std::string &type, const std::optional< std::string > &default_value={})
 Build template argument.
 
static template_parameter make_unexposed_argument (const std::string &type, const std::optional< std::string > &default_value={})
 Build template argument with unexposed type.
 

Private Member Functions

 template_parameter ()=default
 
std::string deduced_context_str () const
 

Private Attributes

template_parameter_kind_t kind_ {template_parameter_kind_t::template_type}
 
std::optional< std::string > type_
 
std::optional< std::string > name_
 
std::optional< std::string > default_value_
 
bool is_template_parameter_ {false}
 
bool is_template_template_parameter_ {false}
 
bool is_ellipsis_ {false}
 
bool is_variadic_ {false}
 
bool is_function_template_ {false}
 
bool is_data_pointer_ {false}
 
bool is_member_pointer_ {false}
 
bool is_array_ {false}
 
std::deque< contextcontext_
 
std::optional< std::string > concept_constraint_
 
std::vector< template_parametertemplate_params_
 
std::optional< eid_tid_
 
bool is_unexposed_ {false}
 

Constructor & Destructor Documentation

◆ template_parameter()

clanguml::common::model::template_parameter::template_parameter ( )
privatedefault

This class should be only constructed using builder methods.

Member Function Documentation

◆ add_template_param() [1/2]

void clanguml::common::model::template_parameter::add_template_param ( const template_parameter ct)

Add a nested template parameter.

Parameters
ctTemplate parameter l-value.

Definition at line 324 of file template_parameter.cc.

325{
326 template_params_.push_back(ct);
327}

◆ add_template_param() [2/2]

void clanguml::common::model::template_parameter::add_template_param ( template_parameter &&  ct)

Add a nested template parameter.

Parameters
ctTemplate parameter r-value.

Definition at line 319 of file template_parameter.cc.

320{
321 template_params_.emplace_back(std::move(ct));
322}

◆ calculate_specialization_match()

int clanguml::common::model::template_parameter::calculate_specialization_match ( const template_parameter base_template_parameter) const

Calculate the match between this and other parameter.

This method calculates to what degree *this matches the base_template_parameter as it's less specific specialization.

The higher the value, the more likely it is that *this is a specialization of base_template_parameter.

Todo:
This is not scientific - there probably is more strict way to calculate this...
See also
calculate_template_params_specialization_match()
Parameters
base_template_parameter
Returns
Specialization match value

Definition at line 229 of file template_parameter.cc.

231{
232 int res{0};
233
234 // If the potential base template has a deduction context (e.g. const&),
235 // the specialization must have the same and possibly more
236 if (base_template_parameter.is_specialization()) {
237 if (!deduced_context().empty() &&
238 (base_template_parameter.deduced_context().empty() ||
240 base_template_parameter.deduced_context())))
241 return 0;
242
243 if (!base_template_parameter.deduced_context().empty() &&
244 deduced_context().empty())
245 return 0;
246 }
247
248 if (is_template_parameter() &&
249 base_template_parameter.is_template_parameter() &&
250 template_params().empty() &&
251 base_template_parameter.template_params().empty() &&
252 is_variadic() == is_variadic() &&
254 base_template_parameter.is_function_template() &&
255 is_member_pointer() == base_template_parameter.is_member_pointer()) {
256 return 1;
257 }
258
259 auto maybe_base_template_parameter_type = base_template_parameter.type();
260 auto maybe_template_parameter_type = type();
261
262 if (maybe_base_template_parameter_type.has_value() &&
263 maybe_template_parameter_type.has_value() &&
264 !base_template_parameter.is_template_parameter() &&
266 if (maybe_base_template_parameter_type.value() !=
267 maybe_template_parameter_type.value())
268 return 0;
269
270 res++;
271 }
272
273 if (base_template_parameter.is_array() && !is_array())
274 return 0;
275
276 if (base_template_parameter.is_function_template() &&
278 return 0;
279
280 if (base_template_parameter.is_member_pointer() && !is_member_pointer())
281 return 0;
282
283 if (base_template_parameter.is_data_pointer() && !is_data_pointer())
284 return 0;
285
286 if (!base_template_parameter.template_params().empty() &&
287 !template_params().empty() &&
288 is_same_specialization(base_template_parameter)) {
290 template_params(), base_template_parameter.template_params());
291
292 if (params_match == 0)
293 return 0;
294
295 res += params_match;
296 }
297 else if ((base_template_parameter.is_template_parameter() ||
298 base_template_parameter.is_template_template_parameter()) &&
300 return 1;
301 }
302 else if (base_template_parameter.is_template_parameter() &&
303 base_template_parameter.template_params().empty()) {
304 // If the base is a regular template param, only possible with deduced
305 // context (deduced context already matches if exists)
306 res++;
307
308 if (!deduced_context().empty() &&
309 !base_template_parameter.deduced_context().empty() &&
311 deduced_context(), base_template_parameter.deduced_context()))
312 res += static_cast<int>(
313 base_template_parameter.deduced_context().size());
314 }
315
316 return res;
317}

◆ clear_params()

void clanguml::common::model::template_parameter::clear_params ( )
inline

Erase all nested template parameters.

Definition at line 347 of file template_parameter.h.

347{ template_params_.clear(); }

◆ concept_constraint()

const std::optional< std::string > & clanguml::common::model::template_parameter::concept_constraint ( ) const

Get the name of the concept constraint for this parameter, if any

Returns
Optional concept constraint name

Definition at line 565 of file template_parameter.cc.

566{
567 return concept_constraint_;
568}

◆ deduced_context() [1/2]

const std::deque< context > & clanguml::common::model::template_parameter::deduced_context ( ) const

Get the entire deduce context of the template parameter

Returns
Deduced context of this template parameter

Definition at line 619 of file template_parameter.cc.

620{
621 return context_;
622}

◆ deduced_context() [2/2]

void clanguml::common::model::template_parameter::deduced_context ( std::deque< context c)

Set the deduced context for the template parameter

Parameters
cDeduced context.

Definition at line 624 of file template_parameter.cc.

625{
626 context_ = std::move(c);
627}

◆ deduced_context_str()

std::string clanguml::common::model::template_parameter::deduced_context_str ( ) const
private

Definition at line 335 of file template_parameter.cc.

336{
337 std::vector<std::string> deduced_contexts;
338
339 for (const auto &c : deduced_context()) {
340 deduced_contexts.push_back(c.to_string());
341 }
342
343 return fmt::format("{}", fmt::join(deduced_contexts, " "));
344}

◆ default_value()

const std::optional< std::string > & clanguml::common::model::template_parameter::default_value ( ) const

Get the template parameters default value if any

Returns
Default value

Definition at line 217 of file template_parameter.cc.

218{
219 return default_value_;
220}

◆ find_nested_relationships()

bool clanguml::common::model::template_parameter::find_nested_relationships ( std::vector< std::pair< eid_t, common::model::relationship_t > > &  nested_relationships,
common::model::relationship_t  hint,
const std::function< bool(const std::string &full_name)> &  should_include 
) const

Find all relationships in this and its nested templates.

Parameters
nested_relationshipsOutput to store found relationships
hintProvide hint for the found relationships
should_includeFunctor to determine whether nested template parameter or argument should be considered
Returns

Definition at line 479 of file template_parameter.cc.

485{
486 bool added_aggregation_relationship{false};
487
488 // If this type argument should be included in the relationship
489 // just add it and skip recursion (e.g. this is a user defined type)
490 const auto maybe_type = type();
491
494
495 if (maybe_type && should_include(maybe_type.value())) {
496 if (is_association())
498
499 const auto maybe_id = id();
500 if (maybe_id) {
501 nested_relationships.emplace_back(maybe_id.value(), hint);
502 added_aggregation_relationship =
504 }
505 }
506 // Otherwise (e.g. this is a std::shared_ptr) and we're actually
507 // interested what is stored inside it
508 else {
509 for (const auto &template_argument : template_params()) {
510
511 const auto maybe_id = template_argument.id();
512 const auto maybe_arg_type = template_argument.type();
513
514 if (maybe_id && maybe_arg_type && should_include(*maybe_arg_type)) {
515
516 if (template_argument.is_association() &&
519
520 nested_relationships.emplace_back(maybe_id.value(), hint);
521
522 added_aggregation_relationship =
524 }
525 else {
526 if (template_argument.is_function_template())
528
529 added_aggregation_relationship =
530 template_argument.find_nested_relationships(
531 nested_relationships, hint, should_include);
532 }
533 }
534 }
535
536 return added_aggregation_relationship;
537}

◆ id()

const std::optional< eid_t > & clanguml::common::model::template_parameter::id ( ) const
inline

Get id of the template parameter

Returns
Id of the template parameter

Definition at line 172 of file template_parameter.h.

172{ return id_; }

◆ is_array() [1/2]

bool clanguml::common::model::template_parameter::is_array ( ) const

Whether this is an array template parameter.

Returns
True, if this is an array template parameter.

Definition at line 612 of file template_parameter.cc.

612{ return is_array_; }

◆ is_array() [2/2]

void clanguml::common::model::template_parameter::is_array ( bool  a)

Set, whether this is an array template parameter.

Parameters
mArray parameter status

Definition at line 611 of file template_parameter.cc.

611{ is_array_ = a; }

◆ is_association()

bool clanguml::common::model::template_parameter::is_association ( ) const

Does the template parameters deduced context contain any references or pointers?

Returns
True if any of the deduced context is a reference or pointer.

Definition at line 570 of file template_parameter.cc.

571{
572 return std::any_of(
573 deduced_context().begin(), deduced_context().end(), [](const auto &c) {
574 return c.pr == rpqualifier::kPointer ||
576 });
577}

◆ is_data_pointer() [1/2]

bool clanguml::common::model::template_parameter::is_data_pointer ( ) const

Whether this is a data pointer parameter.

Returns
True, if this is a data pointer parameter.

Definition at line 609 of file template_parameter.cc.

609{ return is_data_pointer_; }

◆ is_data_pointer() [2/2]

void clanguml::common::model::template_parameter::is_data_pointer ( bool  m)

Set, whether this is a data template parameter.

Parameters
mData pointer parameter status

Definition at line 608 of file template_parameter.cc.

608{ is_data_pointer_ = m; }

◆ is_ellipsis() [1/2]

bool clanguml::common::model::template_parameter::is_ellipsis ( ) const

Check whether the parameter is an ellipsis

Returns
True if the parameter is an ellipsis

Definition at line 631 of file template_parameter.cc.

631{ return is_ellipsis_; }

◆ is_ellipsis() [2/2]

void clanguml::common::model::template_parameter::is_ellipsis ( bool  e)

Set, whether the parameter is an ellipsis (...)

Parameters
eTrue, if parameter is an ellipsis

Definition at line 629 of file template_parameter.cc.

629{ is_ellipsis_ = e; }

◆ is_function_template() [1/2]

bool clanguml::common::model::template_parameter::is_function_template ( ) const

Whether this is a function template parameter.

Returns
True, if *this is a function template parameter

Definition at line 597 of file template_parameter.cc.

598{
600}

◆ is_function_template() [2/2]

void clanguml::common::model::template_parameter::is_function_template ( bool  ft)

Set, whether this is a function template parameter.

Parameters
ftFunction template parameter status

Definition at line 593 of file template_parameter.cc.

594{
596}

◆ is_member_pointer() [1/2]

bool clanguml::common::model::template_parameter::is_member_pointer ( ) const

Whether this is a member pointer parameter.

Returns
True if this is member pointer parameter.

Definition at line 603 of file template_parameter.cc.

604{
605 return is_member_pointer_;
606}

◆ is_member_pointer() [2/2]

void clanguml::common::model::template_parameter::is_member_pointer ( bool  m)

Set, whether this is a member pointer template parameter.

Parameters
mMember pointer template parameter status

Definition at line 602 of file template_parameter.cc.

602{ is_member_pointer_ = m; }

◆ is_same_specialization()

bool clanguml::common::model::template_parameter::is_same_specialization ( const template_parameter other) const

Whether this is the same type of specialization as other.

This method is used for instance to check if 2 template parameters are function templates.

Parameters
otherAnother template parameter or argument
Returns
True, if both template parameters are the same type of specialzations.

Definition at line 147 of file template_parameter.cc.

149{
150 return is_array() == other.is_array() &&
151 is_function_template() == other.is_function_template() &&
152 is_data_pointer() == other.is_data_pointer() &&
153 is_member_pointer() == other.is_member_pointer();
154}

◆ is_specialization()

bool clanguml::common::model::template_parameter::is_specialization ( ) const

Is this template argument or parameter a specialization of some more generic template.

Returns
True, if this is specialization of some more generic template parameter.

Definition at line 141 of file template_parameter.cc.

142{
143 return is_function_template() || is_array() || is_data_pointer() ||
144 is_member_pointer() || !deduced_context().empty();
145}

◆ is_template_parameter() [1/2]

bool clanguml::common::model::template_parameter::is_template_parameter ( ) const

Whether this is a template parameter.

Returns
True, if *this is a template parameter

Definition at line 539 of file template_parameter.cc.

540{
542}

◆ is_template_parameter() [2/2]

void clanguml::common::model::template_parameter::is_template_parameter ( bool  is_template_parameter)

Set, whether this is a template parameter.

Parameters
is_template_parameterTemplate parameter status

Definition at line 544 of file template_parameter.cc.

◆ is_template_template_parameter() [1/2]

bool clanguml::common::model::template_parameter::is_template_template_parameter ( ) const

Whether this is a template template parameter.

Returns
True, if *this is a template template parameter

Definition at line 549 of file template_parameter.cc.

550{
552}

◆ is_template_template_parameter() [2/2]

void clanguml::common::model::template_parameter::is_template_template_parameter ( bool  is_template_template_parameter)

Set, whether this is a template template parameter.

Parameters
is_template_parameterTemplate template parameter status

Definition at line 554 of file template_parameter.cc.

◆ is_unexposed()

bool clanguml::common::model::template_parameter::is_unexposed ( ) const

Definition at line 586 of file template_parameter.cc.

586{ return is_unexposed_; }

◆ is_variadic() [1/2]

bool clanguml::common::model::template_parameter::is_variadic ( ) const
noexcept

Check whether template parameter is variadic

Returns
True, if template parameter is variadic

Definition at line 227 of file template_parameter.cc.

227{ return is_variadic_; }

◆ is_variadic() [2/2]

void clanguml::common::model::template_parameter::is_variadic ( bool  is_variadic)
noexcept

Set template parameters variadic status.

Parameters
is_variadicTrue, if template parameter is variadic

Definition at line 222 of file template_parameter.cc.

223{
225}

◆ kind()

template_parameter_kind_t clanguml::common::model::template_parameter::kind ( ) const

Get the kind of the template parameter or argument

Returns
Template parameter kind

Definition at line 579 of file template_parameter.cc.

579{ return kind_; }

◆ make_argument()

template_parameter clanguml::common::model::template_parameter::make_argument ( const std::string &  type,
const std::optional< std::string > &  default_value = {} 
)
static

Build template argument.

Parameters
typeType of template argument
default_valueDefault value of the parameter if any
Returns
template_parameter instance

Definition at line 122 of file template_parameter.cc.

124{
127 p.set_type(type);
128 if (default_value)
129 p.set_default_value(default_value.value());
130 return p;
131}

◆ make_non_type_template()

template_parameter clanguml::common::model::template_parameter::make_non_type_template ( const std::string &  type,
const std::optional< std::string > &  name,
const std::optional< std::string > &  default_value = {},
bool  is_variadic = false 
)
static

Build non-type template parameter.

Parameters
typeType of non-type parameter (e.g. int)
nameName of parameter
default_valueDefault value of the parameter if any
is_variadicWhether the template parameter is variadic
Returns
template_parameter instance

Definition at line 107 of file template_parameter.cc.

110{
113 p.set_type(type);
114 if (name)
115 p.set_name(name.value());
116 if (default_value)
117 p.set_default_value(default_value.value());
118 p.is_variadic(is_variadic);
119 return p;
120}

◆ make_template_template_type()

template_parameter clanguml::common::model::template_parameter::make_template_template_type ( const std::string &  name,
const std::optional< std::string > &  default_value = {},
bool  is_variadic = false 
)
static

Build template template parameter type.

Parameters
nameName of template template parameter
default_valueDefault value of the parameter if any
is_variadicWhether the template parameter is variadic
Returns
template_parameter instance

Definition at line 94 of file template_parameter.cc.

97{
100 p.set_name(name + "<>");
101 if (default_value)
102 p.set_default_value(default_value.value());
103 p.is_variadic(is_variadic);
104 return p;
105}

◆ make_template_type()

template_parameter clanguml::common::model::template_parameter::make_template_type ( const std::string &  name,
const std::optional< std::string > &  default_value = {},
bool  is_variadic = false 
)
static

Build template type parameter.

Parameters
nameName of template parameter (e.g. T)
default_valueDefault value of the parameter if any
is_variadicWhether the template parameter is variadic
Returns
template_parameter instance

Definition at line 80 of file template_parameter.cc.

83{
86 p.set_name(name);
87 p.is_variadic(is_variadic);
88 p.is_template_parameter(true);
89 if (default_value)
90 p.set_default_value(default_value.value());
91 return p;
92}

◆ make_unexposed_argument()

template_parameter clanguml::common::model::template_parameter::make_unexposed_argument ( const std::string &  type,
const std::optional< std::string > &  default_value = {} 
)
static

Build template argument with unexposed type.

This method is used to build template argument from an unexposed string, i.e. when Clang just returns a string for the template argument type instead of actual type AST.

Parameters
typeString representation of the type
default_valueDefault value of the parameter if any
Returns
template_parameter instance

Definition at line 133 of file template_parameter.cc.

135{
137 p.set_unexposed(true);
138 return p;
139}

◆ name()

std::optional< std::string > clanguml::common::model::template_parameter::name ( ) const

Get the name of template parameter, if any

Returns
Name of template parameter

Definition at line 195 of file template_parameter.cc.

196{
197 if (!name_)
198 return {};
199
201 name_.has_value() && name_.value().empty())
202 return "typename";
203
205 return name_.value() + "...";
206
207 return name_;
208}

◆ push_context()

void clanguml::common::model::template_parameter::push_context ( const context q)

Append a deduced context to the template parameter.

Parameters
qDeduced context

Definition at line 614 of file template_parameter.cc.

615{
616 context_.push_front(q);
617}

◆ set_concept_constraint()

void clanguml::common::model::template_parameter::set_concept_constraint ( std::string  constraint)

Set the concept constraint for this template parameter

Parameters
constraint

Definition at line 560 of file template_parameter.cc.

561{
562 concept_constraint_ = std::move(constraint);
563}

◆ set_default_value()

void clanguml::common::model::template_parameter::set_default_value ( const std::string &  value)

Set default value for template parameter

Parameters
valueDefault value

Definition at line 210 of file template_parameter.cc.

211{
213
214 default_value_ = value;
215}

◆ set_id()

void clanguml::common::model::template_parameter::set_id ( const eid_t id)
inline

Set unique id for the template parameter or argument

Parameters
idId of parameter

Definition at line 165 of file template_parameter.h.

165{ id_ = id; }

◆ set_kind()

void clanguml::common::model::template_parameter::set_kind ( template_parameter_kind_t  kind)

Set the kind of the template parameter or argument.

Parameters
kindKind of the template parameter

Definition at line 581 of file template_parameter.cc.

582{
583 kind_ = kind;
584}

◆ set_name()

void clanguml::common::model::template_parameter::set_name ( const std::string &  name)

Set the name of the template parameter

Parameters
nameName of template parameter

Definition at line 179 of file template_parameter.cc.

180{
182
183 if (name.empty()) {
184 return;
185 }
186
187 if (util::ends_with(name, std::string{"..."})) {
188 name_ = name.substr(0, name.size() - 3);
189 is_variadic_ = true;
190 }
191 else
192 name_ = name;
193}

◆ set_type()

void clanguml::common::model::template_parameter::set_type ( const std::string &  type)

Set the type of template argument

Parameters
typeName of the type

Definition at line 156 of file template_parameter.cc.

157{
159
160 if (util::ends_with(type, std::string{"..."})) {
161 type_ = type.substr(0, type.size() - 3);
162 is_variadic_ = true;
163 }
164 else
165 type_ = type;
166}

◆ set_unexposed()

void clanguml::common::model::template_parameter::set_unexposed ( bool  unexposed)

Definition at line 588 of file template_parameter.cc.

589{
590 is_unexposed_ = unexposed;
591}

◆ template_params()

const std::vector< template_parameter > & clanguml::common::model::template_parameter::template_params ( ) const

Get the reference to all nested template parameters.

Returns

Definition at line 330 of file template_parameter.cc.

331{
332 return template_params_;
333}

◆ to_string()

std::string clanguml::common::model::template_parameter::to_string ( const clanguml::common::model::namespace_ using_namespace,
bool  relative,
bool  skip_qualifiers = false 
) const

Render the template_parameter into string.

This method renders the template parameter along with any of its nested template parameters

Parameters
using_namespace
relative
skip_qualifiers
Returns

Definition at line 346 of file template_parameter.cc.

349{
350 if (is_ellipsis())
351 return "...";
352
354
355 assert(!(type().has_value() && concept_constraint().has_value()));
356
357 if (is_array()) {
358 auto it = template_params_.begin();
359 auto element_type = it->to_string(using_namespace, relative);
360 std::advance(it, 1);
361
362 std::vector<std::string> dimension_args;
363 for (; it != template_params_.end(); it++)
364 dimension_args.push_back(it->to_string(using_namespace, relative));
365
366 return fmt::format(
367 "{}[{}]", element_type, fmt::join(dimension_args, "]["));
368 }
369
370 if (is_function_template()) {
371 auto it = template_params_.begin();
372 auto return_type = it->to_string(using_namespace, relative);
373 std::advance(it, 1);
374
375 std::vector<std::string> function_args;
376 for (; it != template_params_.end(); it++)
377 function_args.push_back(it->to_string(using_namespace, relative));
378
379 return fmt::format(
380 "{}({})", return_type, fmt::join(function_args, ","));
381 }
382
383 if (is_data_pointer()) {
384 assert(template_params().size() == 2);
385
386 std::string unqualified = fmt::format("{} {}::*",
387 template_params().at(0).to_string(using_namespace, relative),
388 template_params().at(1).to_string(using_namespace, relative));
389
390 if (skip_qualifiers)
391 return unqualified;
392
393 return util::join(" ", unqualified, deduced_context_str());
394 }
395
396 if (is_member_pointer()) {
397 assert(template_params().size() > 1);
398
399 auto it = template_params().begin();
400 auto return_type = it->to_string(using_namespace, relative);
401 it++;
402 auto class_type = it->to_string(using_namespace, relative);
403 it++;
404 std::vector<std::string> args;
405
406 for (; it != template_params().end(); it++) {
407 args.push_back(it->to_string(using_namespace, relative));
408 }
409
410 std::string unqualified = fmt::format(
411 "{} ({}::*)({})", return_type, class_type, fmt::join(args, ","));
412 if (skip_qualifiers)
413 return unqualified;
414
415 return util::join(" ", unqualified, deduced_context_str());
416 }
417
418 std::string res;
419 const auto maybe_type = type();
420 if (maybe_type) {
421 if (!relative)
422 res += namespace_{*maybe_type}.to_string();
423 else
424 res += namespace_{*maybe_type}
425 .relative_to(using_namespace)
426 .to_string();
427 }
428
429 const auto &maybe_concept_constraint = concept_constraint();
430
431 if (maybe_concept_constraint) {
432 if (!relative)
433 res += namespace_{maybe_concept_constraint.value()}.to_string();
434 else
435 res += namespace_{maybe_concept_constraint.value()}
436 .relative_to(using_namespace)
437 .to_string();
438 }
439
440 const auto maybe_name = name();
441
442 if (maybe_name) {
443 if ((maybe_type && !maybe_type.value().empty()) ||
444 maybe_concept_constraint)
445 res += " ";
446
447 if (!relative)
448 res += namespace_{*maybe_name}.to_string();
449 else
450 res += namespace_{*maybe_name}
451 .relative_to(using_namespace)
452 .to_string();
453 }
454
455 // Render nested template params
456 if (!template_params_.empty()) {
457 std::vector<std::string> params;
458 params.reserve(template_params_.size());
459 for (const auto &template_param : template_params_) {
460 params.push_back(
461 template_param.to_string(using_namespace, relative));
462 }
463
464 res += fmt::format("<{}>", fmt::join(params, ","));
465 }
466
467 if (!skip_qualifiers)
468 res = util::join(" ", res, deduced_context_str());
469
470 const auto &maybe_default_value = default_value();
471 if (maybe_default_value) {
472 res += "=";
473 res += maybe_default_value.value();
474 }
475
476 return res;
477}

◆ type()

std::optional< std::string > clanguml::common::model::template_parameter::type ( ) const

Get the type of template parameter if any

Returns
Optional name of type

Definition at line 168 of file template_parameter.cc.

169{
170 if (!type_)
171 return {};
172
173 if (is_variadic_)
174 return type_.value() + "...";
175
176 return type_;
177}

Member Data Documentation

◆ concept_constraint_

std::optional<std::string> clanguml::common::model::template_parameter::concept_constraint_
private

Stores optional fully qualified name of constraint for this template parameter

Definition at line 525 of file template_parameter.h.

◆ context_

std::deque<context> clanguml::common::model::template_parameter::context_
private

Stores the template parameter/argument deduction context e.g. const&

Definition at line 520 of file template_parameter.h.

◆ default_value_

std::optional<std::string> clanguml::common::model::template_parameter::default_value_
private

Default value of the template parameter

Definition at line 489 of file template_parameter.h.

◆ id_

std::optional<eid_t> clanguml::common::model::template_parameter::id_
private

Definition at line 532 of file template_parameter.h.

◆ is_array_

bool clanguml::common::model::template_parameter::is_array_ {false}
private

Is template argument an array

Definition at line 517 of file template_parameter.h.

◆ is_data_pointer_

bool clanguml::common::model::template_parameter::is_data_pointer_ {false}
private

Whether the template

Definition at line 511 of file template_parameter.h.

◆ is_ellipsis_

bool clanguml::common::model::template_parameter::is_ellipsis_ {false}
private

Whether template argument is ellipsis (...)

Definition at line 502 of file template_parameter.h.

◆ is_function_template_

bool clanguml::common::model::template_parameter::is_function_template_ {false}
private

Whether the template is a function template (e.g. R(T))

Definition at line 508 of file template_parameter.h.

◆ is_member_pointer_

bool clanguml::common::model::template_parameter::is_member_pointer_ {false}
private

Whether the template is a member pointer (e.g. R(C::*)(int))

Definition at line 514 of file template_parameter.h.

◆ is_template_parameter_

bool clanguml::common::model::template_parameter::is_template_parameter_ {false}
private

Whether the template parameter is a regular template parameter. When false, it is a non-type template parameter

Definition at line 494 of file template_parameter.h.

◆ is_template_template_parameter_

bool clanguml::common::model::template_parameter::is_template_template_parameter_ {false}
private

Whether the template parameter is a template template parameter. Can only be true when is_template_parameter_ is true

Definition at line 499 of file template_parameter.h.

◆ is_unexposed_

bool clanguml::common::model::template_parameter::is_unexposed_ {false}
private

Definition at line 534 of file template_parameter.h.

◆ is_variadic_

bool clanguml::common::model::template_parameter::is_variadic_ {false}
private

Whether the template parameter is variadic

Definition at line 505 of file template_parameter.h.

◆ kind_

template_parameter_kind_t clanguml::common::model::template_parameter::kind_ {template_parameter_kind_t::template_type}
private

Definition at line 478 of file template_parameter.h.

◆ name_

std::optional<std::string> clanguml::common::model::template_parameter::name_
private

The name of the parameter (e.g. 'T' or 'N')

Definition at line 486 of file template_parameter.h.

◆ template_params_

std::vector<template_parameter> clanguml::common::model::template_parameter::template_params_
private

Nested template parameters. If this is a function template, the first element is the return type

Definition at line 530 of file template_parameter.h.

◆ type_

std::optional<std::string> clanguml::common::model::template_parameter::type_
private

Represents the type of non-type template parameters e.g. 'int' or type of template arguments

Definition at line 483 of file template_parameter.h.


The documentation for this class was generated from the following files: