diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 7a9027f0c..f4fdfaffb 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -149,6 +149,9 @@ class meta_associative_container { any storage{}; }; +/*! @brief Possible modes of a meta any object. */ +using meta_any_policy = any_policy; + /*! @brief Opaque wrapper for values of any type. */ class meta_any { enum class operation : std::uint8_t { @@ -197,7 +200,7 @@ class meta_any { } void release() { - if(node.dtor.dtor && owner()) { + if(node.dtor.dtor && (storage.policy() == any_policy::owner)) { node.dtor.dtor(storage.data()); } } @@ -455,7 +458,7 @@ class meta_any { */ [[nodiscard]] bool allow_cast(const meta_type &type) { if(auto other = std::as_const(*this).allow_cast(type); other) { - if(other.owner()) { + if((other.storage.policy() == any_policy::owner)) { std::swap(*this, other); } @@ -593,8 +596,16 @@ class meta_any { } /*! @copydoc any::owner */ - [[nodiscard]] bool owner() const noexcept { - return storage.owner(); + [[deprecated("use policy() and meta_any_policy instead")]] [[nodiscard]] bool owner() const noexcept { + return (storage.policy() == any_policy::owner); + } + + /** + * @brief Returns the current mode of a meta any object. + * @return The current mode of the meta any object. + */ + [[nodiscard]] meta_any_policy policy() const noexcept { + return storage.policy(); } private: diff --git a/test/entt/meta/meta_any.cpp b/test/entt/meta/meta_any.cpp index cb16b1674..cd084d87f 100644 --- a/test/entt/meta/meta_any.cpp +++ b/test/entt/meta/meta_any.cpp @@ -110,6 +110,7 @@ TEST_F(MetaAny, SBO) { ASSERT_TRUE(any); ASSERT_TRUE(any.owner()); + ASSERT_EQ(any.policy(), entt::meta_any_policy::owner); ASSERT_FALSE(any.try_cast()); ASSERT_EQ(any.cast(), 'c'); ASSERT_NE(any.data(), nullptr); @@ -123,6 +124,7 @@ TEST_F(MetaAny, NoSBO) { ASSERT_TRUE(any); ASSERT_TRUE(any.owner()); + ASSERT_EQ(any.policy(), entt::meta_any_policy::owner); ASSERT_FALSE(any.try_cast()); ASSERT_EQ(any.cast(), instance); ASSERT_NE(any.data(), nullptr); @@ -168,6 +170,7 @@ TEST_F(MetaAny, SBOAsRefConstruction) { ASSERT_TRUE(any); ASSERT_FALSE(any.owner()); + ASSERT_EQ(any.policy(), entt::meta_any_policy::ref); ASSERT_EQ(any.type(), entt::resolve()); ASSERT_FALSE(any.try_cast()); @@ -204,6 +207,7 @@ TEST_F(MetaAny, SBOAsConstRefConstruction) { ASSERT_TRUE(any); ASSERT_FALSE(any.owner()); + ASSERT_EQ(any.policy(), entt::meta_any_policy::cref); ASSERT_EQ(any.type(), entt::resolve()); ASSERT_FALSE(any.try_cast()); @@ -436,6 +440,7 @@ TEST_F(MetaAny, NoSBOAsRefConstruction) { ASSERT_TRUE(any); ASSERT_FALSE(any.owner()); + ASSERT_EQ(any.policy(), entt::meta_any_policy::ref); ASSERT_EQ(any.type(), entt::resolve()); ASSERT_FALSE(any.try_cast()); @@ -470,6 +475,7 @@ TEST_F(MetaAny, NoSBOAsConstRefConstruction) { ASSERT_TRUE(any); ASSERT_FALSE(any.owner()); + ASSERT_EQ(any.policy(), entt::meta_any_policy::cref); ASSERT_EQ(any.type(), entt::resolve()); ASSERT_FALSE(any.try_cast()); @@ -707,6 +713,7 @@ TEST_F(MetaAny, VoidInPlaceTypeConstruction) { ASSERT_TRUE(any); ASSERT_TRUE(any.owner()); + ASSERT_EQ(any.policy(), entt::meta_any_policy::owner); ASSERT_FALSE(any.try_cast()); ASSERT_EQ(any.data(), nullptr); ASSERT_EQ(any.type(), entt::resolve());