xentara-plugin v2.0.3
The Xentara Plugin Framework
Loading...
Searching...
No Matches
xentara::model::ForEachAttributeFunction Class Reference

A function object used to iterate over all the attributes of an element. More...

#include <xentara/model/ForEachAttributeFunction.hpp>

Public Types

using result_type = bool
 The result type.
 

Public Member Functions

template<std::invocable< const std::shared_ptr< const model::Attribute > & > Callable>
 ForEachAttributeFunction (Callable &&callable)
 Constructor that sets the callable to be called.
 
auto operator() (const std::shared_ptr< const model::Attribute > &attribute) const -> bool
 Function call operator.
 
auto operator() (const model::Attribute &attribute) const -> bool
 Function call operator for an attribute that is not tied to a specific element.
 

Detailed Description

A function object used to iterate over all the attributes of an element.

See also
skill::Element::forEachAttribute()
Examples
PublishingConfigAttributes.cpp.

Member Typedef Documentation

◆ result_type

Constructor & Destructor Documentation

◆ ForEachAttributeFunction()

template<std::invocable< const std::shared_ptr< const model::Attribute > & > Callable>
xentara::model::ForEachAttributeFunction::ForEachAttributeFunction ( Callable &&  callable)

Constructor that sets the callable to be called.

Parameters
callableThe callable to be called for each attribute. The return type must be bool, and must evaluate to true to stop iterating over the attributes, or to false to continue iterating.

Member Function Documentation

◆ operator()() [1/2]

auto xentara::model::ForEachAttributeFunction::operator() ( const model::Attribute attribute) const -> bool

Function call operator for an attribute that is not tied to a specific element.

This is a convenience overload that allows you to call the function using an attribute that is not actually a shared object, and is of no risk of disappearing while being used by another element.

The most common use for this overload is for attributes having static storage duration, meaning that it is either:

  1. a global variable,
  2. a static member variable, or
  3. a static local variable in a function.

You can also use this overload if the attribute variable is a member of the skill object, or of any other object that never gets destroyed until Xentara shuts down. Basically, this function can be used for any attribute that is guaranteed to outlive all Xentara elements in the model.

Attention
Do not call this overload with a member of one of your skill elements. Instead, derive the corresponding element class from skill::EnableSharedFromThis and use sharedFromThis<Alias>() to create a shared pointer to the attribute, and pass it to the overload operator()(const std::shared_ptr<const model::Attribute> &) defined in the base class.
Parameters
attributeThe attribute.
Returns
Returns true to stop iterating over the attributes.

◆ operator()() [2/2]

auto xentara::model::ForEachAttributeFunction::operator() ( const std::shared_ptr< const model::Attribute > &  attribute) const -> bool

Function call operator.

Parameters
attributeThe attribute.
Returns
Returns true to stop iterating over the attributes.