From faf7e281195b604f33bb9875b7c5563c244e37a7 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 7 Oct 2019 22:40:41 +0200 Subject: [PATCH] meta: added meta context object --- src/entt/meta/meta.hpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index ebaf02d4d..3147a9374 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -318,7 +318,7 @@ class meta_any { template static Type * release(Type *instance) { - auto * const node = internal::meta_info::resolve(); + const auto * const node = internal::meta_info::resolve(); [[maybe_unused]] const bool destroyed = (!node->dtor || node->dtor->invoke(*instance)); ENTT_ASSERT(destroyed); return instance; @@ -1748,6 +1748,43 @@ private: }; +/*! @brief Opaque container for a meta context. */ +class meta_ctx { + auto ctx() const ENTT_NOEXCEPT { + return &internal::meta_info<>::local; + } + +public: + /*! @brief Default constructor. */ + meta_ctx() ENTT_NOEXCEPT = default; + + /*! @brief Default copy constructor, deleted on purpose. */ + meta_ctx(const meta_ctx &) = delete; + /*! @brief Default move constructor, deleted on purpose. */ + meta_ctx(meta_ctx &&) = delete; + + /** + * @brief Copy assignment operator. + * @param other The instance to copy from. + * @return This meta object. + */ + meta_ctx & operator=(const meta_ctx &other) { + internal::meta_info<>::ctx = other.ctx(); + return *this; + } + + /** + * @brief Move assignment operator. + * @param other The instance to move from. + * @return This meta object. + */ + meta_ctx & operator=(meta_ctx &&other) { + internal::meta_info<>::ctx = other.ctx(); + return *this; + } +}; + + /*! @copydoc operator!=(const meta_prop &, const meta_prop &) */ inline bool operator!=(const meta_type &lhs, const meta_type &rhs) ENTT_NOEXCEPT { return !(lhs == rhs);