0.6.0
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 89 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 (const clang::Decl *decl, std::vector< std::tuple< eid_t, common::model::relationship_t, const clang::Decl * > > &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_empty ()
 Build template type parameter.
 
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 333 of file template_parameter.cc.

334{
335 template_params_.push_back(ct);
336}

◆ 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 328 of file template_parameter.cc.

329{
330 template_params_.emplace_back(std::move(ct));
331}

◆ 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 238 of file template_parameter.cc.

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

◆ clear_params()

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

Erase all nested template parameters.

Definition at line 364 of file template_parameter.h.

364{ 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 578 of file template_parameter.cc.

579{
580 return concept_constraint_;
581}

◆ 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 632 of file template_parameter.cc.

633{
634 return context_;
635}

◆ 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 637 of file template_parameter.cc.

638{
639 context_ = std::move(c);
640}

◆ deduced_context_str()

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

Definition at line 344 of file template_parameter.cc.

345{
346 std::vector<std::string> deduced_contexts;
347
348 for (const auto &c : deduced_context()) {
349 deduced_contexts.push_back(c.to_string());
350 }
351
352 return fmt::format("{}", fmt::join(deduced_contexts, " "));
353}

◆ 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 226 of file template_parameter.cc.

227{
228 return default_value_;
229}

◆ find_nested_relationships()

bool clanguml::common::model::template_parameter::find_nested_relationships ( const clang::Decl *  decl,
std::vector< std::tuple< eid_t, common::model::relationship_t, const clang::Decl * > > &  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
declSource declaration where this relationship originates from
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 492 of file template_parameter.cc.

498{
499 bool added_aggregation_relationship{false};
500
501 // If this type argument should be included in the relationship
502 // just add it and skip recursion (e.g. this is a user defined type)
503 const auto maybe_type = type();
504
507
508 if (maybe_type && should_include(maybe_type.value())) {
509 if (is_association())
511
512 const auto maybe_id = id();
513 if (maybe_id) {
514 nested_relationships.emplace_back(maybe_id.value(), hint, decl);
515 added_aggregation_relationship =
517 }
518 }
519 // Otherwise (e.g. this is a std::shared_ptr) and we're actually
520 // interested what is stored inside it
521 else {
522 for (const auto &template_argument : template_params()) {
523
524 const auto maybe_id = template_argument.id();
525 const auto maybe_arg_type = template_argument.type();
526
527 if (maybe_id && maybe_arg_type && should_include(*maybe_arg_type)) {
528
529 if (template_argument.is_association() &&
532
533 nested_relationships.emplace_back(maybe_id.value(), hint, decl);
534
535 added_aggregation_relationship =
537 }
538 else {
539 if (template_argument.is_function_template())
541
542 added_aggregation_relationship =
543 template_argument.find_nested_relationships(
544 decl, nested_relationships, hint, should_include);
545 }
546 }
547 }
548
549 return added_aggregation_relationship;
550}

◆ 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 189 of file template_parameter.h.

189{ 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 625 of file template_parameter.cc.

625{ 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 624 of file template_parameter.cc.

624{ 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 583 of file template_parameter.cc.

584{
585 return std::any_of(
586 deduced_context().begin(), deduced_context().end(), [](const auto &c) {
587 return c.pr == rpqualifier::kPointer ||
589 });
590}

◆ 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 622 of file template_parameter.cc.

622{ 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 621 of file template_parameter.cc.

621{ 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 644 of file template_parameter.cc.

644{ 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 642 of file template_parameter.cc.

642{ 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 610 of file template_parameter.cc.

611{
613}

◆ 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 606 of file template_parameter.cc.

607{
609}

◆ 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 616 of file template_parameter.cc.

617{
618 return is_member_pointer_;
619}

◆ 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 615 of file template_parameter.cc.

615{ 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 156 of file template_parameter.cc.

158{
159 return is_array() == other.is_array() &&
160 is_function_template() == other.is_function_template() &&
161 is_data_pointer() == other.is_data_pointer() &&
162 is_member_pointer() == other.is_member_pointer();
163}

◆ 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 150 of file template_parameter.cc.

151{
152 return is_function_template() || is_array() || is_data_pointer() ||
153 is_member_pointer() || !deduced_context().empty();
154}

◆ 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 552 of file template_parameter.cc.

553{
555}

◆ 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 557 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 562 of file template_parameter.cc.

563{
565}

◆ 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 567 of file template_parameter.cc.

◆ is_unexposed()

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

Definition at line 599 of file template_parameter.cc.

599{ 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 236 of file template_parameter.cc.

236{ 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 231 of file template_parameter.cc.

232{
234}

◆ 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 592 of file template_parameter.cc.

592{ 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 131 of file template_parameter.cc.

133{
136 p.set_type(type);
137 if (default_value)
138 p.set_default_value(default_value.value());
139 return p;
140}

◆ make_empty()

template_parameter clanguml::common::model::template_parameter::make_empty ( )
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 82 of file template_parameter.cc.

83{
86 return p;
87}

◆ 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 116 of file template_parameter.cc.

119{
122 p.set_type(type);
123 if (name)
124 p.set_name(name.value());
125 if (default_value)
126 p.set_default_value(default_value.value());
127 p.is_variadic(is_variadic);
128 return p;
129}

◆ 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 103 of file template_parameter.cc.

106{
109 p.set_name(name + "<>");
110 if (default_value)
111 p.set_default_value(default_value.value());
112 p.is_variadic(is_variadic);
113 return p;
114}

◆ 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 89 of file template_parameter.cc.

92{
95 p.set_name(name);
96 p.is_variadic(is_variadic);
97 p.is_template_parameter(true);
98 if (default_value)
99 p.set_default_value(default_value.value());
100 return p;
101}

◆ 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 142 of file template_parameter.cc.

144{
146 p.set_unexposed(true);
147 return p;
148}

◆ 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 204 of file template_parameter.cc.

205{
206 if (!name_)
207 return {};
208
210 name_.has_value() && name_.value().empty())
211 return "typename";
212
214 return name_.value() + "...";
215
216 return name_;
217}

◆ 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 627 of file template_parameter.cc.

628{
629 context_.push_front(q);
630}

◆ 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 573 of file template_parameter.cc.

574{
575 concept_constraint_ = std::move(constraint);
576}

◆ 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 219 of file template_parameter.cc.

220{
222
223 default_value_ = value;
224}

◆ 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 182 of file template_parameter.h.

182{ 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 594 of file template_parameter.cc.

595{
596 kind_ = kind;
597}

◆ 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 188 of file template_parameter.cc.

189{
191
192 if (name.empty()) {
193 return;
194 }
195
196 if (util::ends_with(name, std::string{"..."})) {
197 name_ = name.substr(0, name.size() - 3);
198 is_variadic_ = true;
199 }
200 else
201 name_ = name;
202}

◆ 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 165 of file template_parameter.cc.

166{
168
169 if (util::ends_with(type, std::string{"..."})) {
170 type_ = type.substr(0, type.size() - 3);
171 is_variadic_ = true;
172 }
173 else
174 type_ = type;
175}

◆ set_unexposed()

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

Definition at line 601 of file template_parameter.cc.

602{
603 is_unexposed_ = unexposed;
604}

◆ 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 339 of file template_parameter.cc.

340{
341 return template_params_;
342}

◆ 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 355 of file template_parameter.cc.

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

◆ 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 177 of file template_parameter.cc.

178{
179 if (!type_)
180 return {};
181
182 if (is_variadic_)
183 return type_.value() + "...";
184
185 return type_;
186}

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 543 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 538 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 507 of file template_parameter.h.

◆ id_

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

Definition at line 550 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 535 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 529 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 520 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 526 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 532 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 512 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 517 of file template_parameter.h.

◆ is_unexposed_

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

Definition at line 552 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 523 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 496 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 504 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 548 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 501 of file template_parameter.h.


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