Struct meta_handle

Synopsis

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

struct meta_handle

Description

Opaque pointers to instances of any type.

A handle doesn't perform copies and isn't responsible for the contained object. It doesn't prolong the lifetime of the pointed instance.
Handles are used to generate meta references to actual objects when needed.

Methods

meta_handle OverloadDefault constructor.
meta_handle OverloadCreates a handle that points to an unmanaged object.
operator*Dereference operator for accessing the contained opaque object.
operator->Access operator for accessing the contained opaque object.

Source

Lines 535-573 in src/entt/meta/meta.hpp.

struct meta_handle {
    /*! @brief Default constructor. */
    meta_handle() = default;

    /**
     * @brief Creates a handle that points to an unmanaged object.
     * @tparam Type Type of object to use to initialize the handle.
     * @param value An instance of an object to use to initialize the handle.
     */
    template<typename Type, typename = std::enable_if_t<!std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, meta_handle>>>
    meta_handle(Type &value) ENTT_NOEXCEPT
        : meta_handle{}
    {
        if constexpr(std::is_same_v<std::remove_cv_t<std::remove_reference_t<Type>>, meta_any>) {
            any = value.ref();
        } else {
            any = std::ref(value);
        }
    }

    /**
     * @brief Dereference operator for accessing the contained opaque object.
     * @return A meta any that shares a reference to an unmanaged object.
     */
    [[nodiscard]] meta_any operator*() const {
        return any;
    }

    /**
     * @brief Access operator for accessing the contained opaque object.
     * @return A meta any that shares a reference to an unmanaged object.
     */
    [[nodiscard]] meta_any * operator->() {
        return &any;
    }

private:
    meta_any any;
};





Add Discussion

Log in to comment