Class meta_associative_container

Synopsis

#include <src/entt/meta/meta.hpp>

class meta_associative_container

Description

Proxy object for associative containers.

Mentioned in

Classes

meta_iteratorOpaque iterator for associative containers.

Methods

meta_associative_container overloadDefault constructor.
meta_associative_container overloadConstruct a proxy object for associative containers.
beginReturns an iterator to the first element of a container.
clearClears the content of a container.
endReturns an iterator that is past the last element of a container.
eraseRemoves the specified element from a container.
findReturns an iterator to the element with a given key, if any.
insertInserts an element (a key/value pair) into a container.
key_onlyReturns true if a container is also key-only, false otherwise.
key_typeReturns the meta key type of a container.
mapped_typeReturns the meta mapped type of a container.
operator boolReturns false if a proxy is invalid, true otherwise.
sizeReturns the size of a container.
value_typeReturns the meta value type of a container.

Source

Lines 88-151 in src/entt/meta/meta.hpp.

class meta_associative_container {
    class meta_iterator;

public:
    /*! @brief Unsigned integer type. */
    using size_type = std::size_t;
    /*! @brief Meta iterator type. */
    using iterator = meta_iterator;

    /*! @brief Default constructor. */
    meta_associative_container() ENTT_NOEXCEPT = default;

    /**
     * @brief Construct a proxy object for associative containers.
     * @tparam Type Type of container to wrap.
     * @param instance The container to wrap.
     */
    template<typename Type>
    meta_associative_container(std::in_place_type_t<Type>, any instance) ENTT_NOEXCEPT
        : key_only_container{meta_associative_container_traits<Type>::key_only()},
          key_type_node{internal::meta_info<typename Type::key_type>::resolve()},
          mapped_type_node{nullptr},
          value_type_node{internal::meta_info<typename Type::value_type>::resolve()},
          size_fn{&meta_associative_container_traits<Type>::size},
          clear_fn{&meta_associative_container_traits<Type>::clear},
          begin_fn{&meta_associative_container_traits<Type>::begin},
          end_fn{&meta_associative_container_traits<Type>::end},
          insert_fn{&meta_associative_container_traits<Type>::insert},
          erase_fn{&meta_associative_container_traits<Type>::erase},
          find_fn{&meta_associative_container_traits<Type>::find},
          storage{std::move(instance)}
    {
        if constexpr(!meta_associative_container_traits<Type>::key_only()) {
            mapped_type_node = internal::meta_info<typename Type::mapped_type>::resolve();
        }
    }

    [[nodiscard]] inline bool key_only() const ENTT_NOEXCEPT;
    [[nodiscard]] inline meta_type key_type() const ENTT_NOEXCEPT;
    [[nodiscard]] inline meta_type mapped_type() const ENTT_NOEXCEPT;
    [[nodiscard]] inline meta_type value_type() const ENTT_NOEXCEPT;
    [[nodiscard]] inline size_type size() const ENTT_NOEXCEPT;
    inline bool clear();
    [[nodiscard]] inline iterator begin();
    [[nodiscard]] inline iterator end();
    inline bool insert(meta_any, meta_any);
    inline bool erase(meta_any);
    [[nodiscard]] inline iterator find(meta_any);
    [[nodiscard]] inline explicit operator bool() const ENTT_NOEXCEPT;

private:
    bool key_only_container{};
    internal::meta_type_node *key_type_node = nullptr;
    internal::meta_type_node *mapped_type_node = nullptr;
    internal::meta_type_node *value_type_node = nullptr;
    size_type(* size_fn)(const any &) ENTT_NOEXCEPT = nullptr;
    bool(* clear_fn)(any &) = nullptr;
    iterator(* begin_fn)(any &) = nullptr;
    iterator(* end_fn)(any &) = nullptr;
    bool(* insert_fn)(any &, meta_any &, meta_any &) = nullptr;
    bool(* erase_fn)(any &, meta_any &) = nullptr;
    iterator(* find_fn)(any &, meta_any &) = nullptr;
    any storage{};
};





Add Discussion

Log in to comment