Function ctx

Summary

#include <src/entt/entity/registry.hpp>

(1) template <typename Type>
    const Type & ctx() const

(2) template <typename Type>
    Type & ctx()

(3) template <typename Func>
    void ctx(Func func) const

Function overload

Synopsis

#include <src/entt/entity/registry.hpp>

template <typename Type>
const Type & ctx() const

Description

Returns a reference to an object in the context of the registry.

Warning
Attempting to get a context variable that doesn't exist results in undefined behavior.
Template Parameters

Type - Type of object to get.

Return
A valid reference to the object in the context of the registry.

Mentioned in

Source

Lines 1563-1568 in src/entt/entity/registry.hpp.

template<typename Type>
[[nodiscard]] const Type & ctx() const {
    const auto *instance = try_ctx<Type>();
    ENTT_ASSERT(instance);
    return *instance;
}

Synopsis

#include <src/entt/entity/registry.hpp>

template <typename Type>
Type & ctx()

Description

Returns a reference to an object in the context of the registry.

Warning
Attempting to get a context variable that doesn't exist results in undefined behavior.
Template Parameters

Type - Type of object to get.

Return
A valid reference to the object in the context of the registry.

Mentioned in

Source

Lines 1571-1574 in src/entt/entity/registry.hpp.

template<typename Type>
[[nodiscard]] Type & ctx() {
    return const_cast<Type &>(std::as_const(*this).template ctx<Type>());
}

Synopsis

#include <src/entt/entity/registry.hpp>

template <typename Func>
void ctx(Func func) const

Description

Visits a registry and returns the type info for its context variables.

The signature of the function should be equivalent to the following:

void(const type_info);

Returned identifiers are those of the context variables currently set.

See
type_info
Warning
It's not specified whether a context variable created during the visit is returned or not to the caller.
Template Parameters

Func - Type of the function object to invoke.

Parameters

func - A valid function object.

Mentioned in

Source

Lines 1597-1602 in src/entt/entity/registry.hpp.

template<typename Func>
void ctx(Func func) const {
    for(auto pos = vars.size(); pos; --pos) {
        func(vars[pos-1].info);
    }
}





Add Discussion

Log in to comment