Struct storage_adapter_mixin

Synopsis

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

template<typename Type>
struct storage_adapter_mixin: Type

Description

Mixin type to use to wrap basic storage classes.

Template Parameters

Type - The type of the underlying storage.

Inheritance

Ancestors: Type

Methods

emplaceAssigns entities to a storage.
insertAssigns entities to a storage.
patchPatches the given instance for an entity.
remove OverloadRemoves entities from a storage.

Source

Lines 544-614 in src/entt/entity/storage.hpp.

template<typename Type>
struct storage_adapter_mixin: Type {
    static_assert(std::is_same_v<typename Type::value_type, std::decay_t<typename Type::value_type>>, "Invalid object type");

    /*! @brief Type of the objects associated with the entities. */
    using value_type = typename Type::value_type;
    /*! @brief Underlying entity identifier. */
    using entity_type = typename Type::entity_type;
    /*! @brief Storage category. */
    using storage_category = typename Type::storage_category;

    /**
     * @brief Assigns entities to a storage.
     * @tparam Args Types of arguments to use to construct the object.
     * @param entity A valid entity identifier.
     * @param args Parameters to use to initialize the object.
     * @return A reference to the newly created object.
     */
    template<typename... Args>
    decltype(auto) emplace(basic_registry<entity_type> &, const entity_type entity, Args &&... args) {
        return Type::emplace(entity, std::forward<Args>(args)...);
    }

    /**
     * @brief Assigns entities to a storage.
     * @tparam It Type of input iterator.
     * @tparam Args Types of arguments to use to construct the objects
     * associated with the entities.
     * @param first An iterator to the first element of the range of entities.
     * @param last An iterator past the last element of the range of entities.
     * @param args Parameters to use to initialize the objects associated with
     * the entities.
     */
    template<typename It, typename... Args>
    void insert(basic_registry<entity_type> &, It first, It last, Args &&... args) {
        Type::insert(first, last, std::forward<Args>(args)...);
    }

    /**
     * @brief Removes entities from a storage.
     * @param entity A valid entity identifier.
     */
    void remove(basic_registry<entity_type> &, const entity_type entity) {
        Type::remove(entity);
    }

    /**
     * @copybrief remove
     * @tparam It Type of input iterator.
     * @param first An iterator to the first element of the range of entities.
     * @param last An iterator past the last element of the range of entities.
     */
    template<typename It>
    void remove(basic_registry<entity_type> &, It first, It last) {
        Type::remove(first, last);
    }

    /**
     * @brief Patches the given instance for an entity.
     * @tparam Func Types of the function objects to invoke.
     * @param entity A valid entity identifier.
     * @param func Valid function objects.
     * @return A reference to the patched instance.
     */
    template<typename... Func>
    decltype(auto) patch(basic_registry<entity_type> &, const entity_type entity, [[maybe_unused]] Func &&... func) {
        auto &instance = this->get(entity);
        (std::forward<Func>(func)(instance), ...);
        return instance;
    }
};





Add Discussion

Log in to comment