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 overload | Default constructor. | |
meta_handle overload | Default copy constructor, deleted on purpose. | |
meta_handle overload | Default move constructor. | |
meta_handle overload | Creates a handle that points to an unmanaged object. | |
operator bool | Returns false if a handle is invalid, true otherwise. | |
operator-> overload | Access operator for accessing the contained opaque object. | |
operator= overload | Default copy assignment operator, deleted on purpose. | |
operator= overload | Default move assignment operator. |
Source
Lines 611-671 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;
};