Function add_if

Summary

#include <include/flecs/addons/cpp/mixins/entity/builder.hpp>

(1) Self & add_if(bool cond, flecs::id_t component)

(2) template <typename T>
    Self & add_if(bool cond)

(3) Self & add_if(bool cond, flecs::entity_t first, flecs::entity_t second)

(4) template <typename First>
    Self & add_if(bool cond, flecs::entity_t second)

(5) template <typename First, typename Second>
    Self & add_if(bool cond)

(6) template <typename E, if_t< is_enum< E >::value > = 0>
    Self & add_if(bool cond, E constant)

Function overload

Synopsis

#include <include/flecs/addons/cpp/mixins/entity/builder.hpp>

Self & add_if(bool cond, flecs::id_t component)

Description

Conditional add. This operation adds if condition is true, removes if condition is false.

Parameters

cond - The condition to evaluate.

component - The component to add.

Source

Lines 101-107 in include/flecs/addons/cpp/mixins/entity/builder.hpp.

Self& add_if(bool cond, flecs::id_t component) {
    if (cond) {
        return this->add(component);
    } else {
        return this->remove(component);
    }
}

Synopsis

#include <include/flecs/addons/cpp/mixins/entity/builder.hpp>

template <typename T>
Self & add_if(bool cond)

Description

Conditional add. This operation adds if condition is true, removes if condition is false.

Template Parameters

T - The component to add.

Parameters

cond - The condition to evaluate.

Source

Lines 115-122 in include/flecs/addons/cpp/mixins/entity/builder.hpp.

template <typename T>
Self& add_if(bool cond) {
    if (cond) {
        return this->add<T>();
    } else {
        return this->remove<T>();
    }
}

Synopsis

#include <include/flecs/addons/cpp/mixins/entity/builder.hpp>

Self & add_if(bool cond, flecs::entity_t first, flecs::entity_t second)

Description

Conditional add. This operation adds if condition is true, removes if condition is false.

Parameters

cond - The condition to evaluate.

first - The first element of the pair.

second - The second element of the pair.

Source

Lines 131-144 in include/flecs/addons/cpp/mixins/entity/builder.hpp.

Self& add_if(bool cond, flecs::entity_t first, flecs::entity_t second) {
    if (cond) {
        return this->add(first, second);
    } else {
        /* If second is 0 or if relationship is exclusive, use wildcard for
         * second which will remove all instances of the relationship.
         * Replacing 0 with Wildcard will make it possible to use the second
         * as the condition. */
        if (!second || ecs_has_id(this->m_world, first, flecs::Exclusive)) {
            second = flecs::Wildcard;
        }
        return this->remove(first, second);
    }
}

Synopsis

#include <include/flecs/addons/cpp/mixins/entity/builder.hpp>

template <typename First>
Self & add_if(bool cond, flecs::entity_t second)

Description

Conditional add. This operation adds if condition is true, removes if condition is false.

Template Parameters

First - The first element of the pair

Parameters

cond - The condition to evaluate.

second - The second element of the pair.

Source

Lines 153-156 in include/flecs/addons/cpp/mixins/entity/builder.hpp.

template <typename First>
Self& add_if(bool cond, flecs::entity_t second) {
    return this->add_if(cond, _::cpp_type<First>::id(this->m_world), second);
}

Synopsis

#include <include/flecs/addons/cpp/mixins/entity/builder.hpp>

template <typename First, typename Second>
Self & add_if(bool cond)

Description

Conditional add. This operation adds if condition is true, removes if condition is false.

Template Parameters

First - The first element of the pair

Second - The second element of the pair

Parameters

cond - The condition to evaluate.

Source

Lines 165-168 in include/flecs/addons/cpp/mixins/entity/builder.hpp.

template <typename First, typename Second>
Self& add_if(bool cond) {
    return this->add_if<First>(cond, _::cpp_type<Second>::id(this->m_world));
}

Synopsis

#include <include/flecs/addons/cpp/mixins/entity/builder.hpp>

template <typename E, if_t< is_enum< E >::value > = 0>
Self & add_if(bool cond, E constant)

Description

Conditional add. This operation adds if condition is true, removes if condition is false.

Parameters

cond - The condition to evaluate.

constant - The enumeration constant.

Source

Lines 176-180 in include/flecs/addons/cpp/mixins/entity/builder.hpp.

template <typename E, if_t< is_enum<E>::value > = 0>
Self& add_if(bool cond, E constant) {
    const auto& et = enum_type<E>(this->m_world);
    return this->add_if<E>(cond, et.entity(constant));
}