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 references to actual objects when needed.

Methods

meta_handle overloadDefault constructor.
meta_handle overloadDefault copy constructor, deleted on purpose.
meta_handle overloadDefault move constructor.
meta_handle overloadCreates a handle that points to an unmanaged object.
operator boolReturns false if a handle is invalid, true otherwise.
operator-> overloadAccess operator for accessing the contained opaque object.
operator= overloadDefault copy assignment operator, deleted on purpose.
operator= overloadDefault move assignment operator.

Source

Lines 603-665 in src/entt/meta/meta.hpp.

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

    /*! @brief Default copy constructor, deleted on purpose. */
    meta_handle(const meta_handle &) = delete;

    /*! @brief Default move constructor. */
    meta_handle(meta_handle &&) = default;

    /**
     * @brief Default copy assignment operator, deleted on purpose.
     * @return This meta handle.
     */
    meta_handle & operator=(const meta_handle &) = delete;

    /**
     * @brief Default move assignment operator.
     * @return This meta handle.
     */
    meta_handle & operator=(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::decay_t<Type>, meta_handle>>>
    meta_handle(Type &value) ENTT_NOEXCEPT
        : meta_handle{}
    {
        if constexpr(std::is_same_v<std::decay_t<Type>, meta_any>) {
            any = value.as_ref();
        } else {
            any.emplace<Type &>(value);
        }
    }

    /**
     * @brief Returns false if a handle is invalid, true otherwise.
     * @return False if the handle is invalid, true otherwise.
     */
    [[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
        return static_cast<bool>(any);
    }

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

    /*! @copydoc operator-> */
    [[nodiscard]] const meta_any * operator->() const {
        return &any;
    }

private:
    meta_any any;
};





Add Discussion

Log in to comment