Struct as_view

Synopsis

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

template<bool Const, typename Entity>
struct as_view

Description

Converts a registry to a view.

Template Parameters:

Const - Constness of the accepted registry.

Entity - A valid entity type (see entt_traits for more details).

Methods

as_viewConstructs a converter for a given registry.
operator basic_view< Entity, Exclude, Component... >Conversion function from a registry to a view.

Source

Lines 21-45 in src/entt/entity/helper.hpp.

template<bool Const, typename Entity>
struct as_view {
    /*! @brief Type of registry to convert. */
    using registry_type = std::conditional_t<Const, const basic_registry<Entity>, basic_registry<Entity>>;

    /**
     * @brief Constructs a converter for a given registry.
     * @param source A valid reference to a registry.
     */
    as_view(registry_type &source) ENTT_NOEXCEPT: reg{source} {}

    /**
     * @brief Conversion function from a registry to a view.
     * @tparam Exclude Types of components used to filter the view.
     * @tparam Component Type of components used to construct the view.
     * @return A newly created view.
     */
    template<typename Exclude, typename... Component>
    operator basic_view<Entity, Exclude, Component...>() const {
        return reg.template view<Component...>(Exclude{});
    }

private:
    registry_type &reg;
};





Add Discussion

Log in to comment