From e4ba5c31d2e660fbf4937c575914cfffb5e6f586 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Tue, 10 Sep 2024 16:12:28 +0200 Subject: [PATCH] meta: deprecate meta properties in favor of custom data --- TODO | 1 - docs/md/meta.md | 53 +-------------------------------------- src/entt/meta/factory.hpp | 2 +- src/entt/meta/meta.hpp | 14 +++++------ 4 files changed, 9 insertions(+), 61 deletions(-) diff --git a/TODO b/TODO index db4c12e1f..4524e556e 100644 --- a/TODO +++ b/TODO @@ -32,7 +32,6 @@ TODO: * cleanup common view from tricks to handle single swap-only and in-place, if constexpr branches * entity based component_traits * review cmake warning about FetchContent_Populate (need .28 and EXCLUDE_FROM_ALL for FetchContent) -* deprecate meta properties in favor of custom data * make meta objects safe to use with null nodes * suppress -Wself-move on CI with g++13 * view and view iterator specializations for multi, single and filtered elements diff --git a/docs/md/meta.md b/docs/md/meta.md index c89b02ca6..8230eead2 100644 --- a/docs/md/meta.md +++ b/docs/md/meta.md @@ -16,7 +16,6 @@ * [Policies: the more, the less](#policies-the-more-the-less) * [Named constants and enums](#named-constants-and-enums) * [User defined data](#user-defined-data) - * [Properties and meta objects](#properties-and-meta-objects) * [Traits](#traits) * [Custom data](#custom-data) * [Unregister types](#unregister-types) @@ -841,15 +840,10 @@ object optimization performed by the `meta_any` class. ## User defined data Sometimes (for example, when it comes to creating an editor) it might be useful -to attach _properties_, _traits_ or arbitrary _custom data_ to the meta objects -created. +to attach _traits_ or arbitrary _custom data_ to the meta objects created. The main difference between them is that: -* Properties are usually key-only or key-value pairs with lower access - performance. They are deprecated today but have long been the only way to - bind user data with meta objects. - * Traits are simple user-defined flags with much higher access performance. The library reserves up to 16 bits for traits, that is 16 flags for a bitmask or 2^16 values otherwise. @@ -860,51 +854,6 @@ The main difference between them is that: In all cases, this support is currently available only for meta types, meta data and meta functions. -### Properties and meta objects - -Properties are set via a meta factory and are not editable once created: - -```cpp -entt::meta().prop("tooltip"_hs, "message"); -``` - -They are always in the key/value form. The key is a numeric identifier, mostly -similar to the identifier used to register meta objects. There are no -restrictions on the type of the value instead, as long as it's movable.
-Key only properties are also supported out of the box: - -```cpp -entt::meta().prop(my_enum::key_only); -``` - -To attach multiple properties to a meta object, just invoke `prop` more than -once.
-It's also possible to call `prop` at different times, as long as the factory is -reset to the meta object of interest: - -```cpp -entt::meta() - .data<&my_type::data_member, entt::as_ref_t>("member"_hs) - .prop("key"_hs, value); -``` - -Once created, all meta objects offer a couple of member functions named `prop` -to iterate all properties at once or to search a specific property by key: - -```cpp -// iterate all properties of a meta type -for(auto &&[id, prop]: entt::resolve().prop()) { - // ... -} - -// search for a given property by name -auto prop = entt::resolve().prop("tooltip"_hs); -``` - -Meta properties are objects having a fairly poor interface, all in all. They -only provide the `value` member function to retrieve the contained value in the -form of a `meta_any` object. - ### Traits User-defined traits are set via a meta factory: diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index 704d09dcb..c45bb65d5 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -498,7 +498,7 @@ public: * @return A meta factory for the parent type. */ template - meta_factory prop(id_type id, [[maybe_unused]] Value &&...value) { + [[deprecated("use ::custom() instead")]] meta_factory prop(id_type id, [[maybe_unused]] Value &&...value) { if constexpr(sizeof...(Value) == 0u) { base_type::prop(internal::meta_prop_node{id, &internal::resolve}); } else { diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 078609ce0..2e9556601 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -765,7 +765,7 @@ private: }; /*! @brief Opaque wrapper for properties of any type. */ -struct meta_prop { +struct [[deprecated("use meta_custom instead")]] meta_prop { /*! @brief Default constructor. */ meta_prop() noexcept = default; @@ -938,7 +938,7 @@ struct meta_data { * @brief Returns a range to visit registered meta properties. * @return An iterable range to visit registered meta properties. */ - [[nodiscard]] meta_range prop() const noexcept { + [[nodiscard]] [[deprecated("use ::custom() instead")]] meta_range prop() const noexcept { return {{*ctx, node->prop.cbegin()}, {*ctx, node->prop.cend()}}; } @@ -947,7 +947,7 @@ struct meta_data { * @param key The key to use to search for a property. * @return The registered meta property for the given key, if any. */ - [[nodiscard]] meta_prop prop(const id_type key) const { + [[nodiscard]] [[deprecated("use ::custom() instead")]] meta_prop prop(const id_type key) const { for(auto &&elem: node->prop) { if(elem.id == key) { return meta_prop{*ctx, elem}; @@ -1083,7 +1083,7 @@ struct meta_func { } /*! @copydoc meta_data::prop */ - [[nodiscard]] meta_range prop() const noexcept { + [[nodiscard]] [[deprecated("use ::custom() instead")]] meta_range prop() const noexcept { return {{*ctx, node->prop.cbegin()}, {*ctx, node->prop.cend()}}; } @@ -1092,7 +1092,7 @@ struct meta_func { * @param key The key to use to search for a property. * @return The registered meta property for the given key, if any. */ - [[nodiscard]] meta_prop prop(const id_type key) const { + [[nodiscard]] [[deprecated("use ::custom() instead")]] meta_prop prop(const id_type key) const { for(auto &&elem: node->prop) { if(elem.id == key) { return meta_prop{*ctx, elem}; @@ -1562,7 +1562,7 @@ public: * @brief Returns a range to visit registered top-level meta properties. * @return An iterable range to visit registered top-level meta properties. */ - [[nodiscard]] meta_range prop() const noexcept { + [[nodiscard]] [[deprecated("use ::custom() instead")]] meta_range prop() const noexcept { using range_type = meta_range; return node.details ? range_type{{*ctx, node.details->prop.cbegin()}, {*ctx, node.details->prop.cend()}} : range_type{}; } @@ -1572,7 +1572,7 @@ public: * @param key The key to use to search for a property. * @return The registered meta property for the given key, if any. */ - [[nodiscard]] meta_prop prop(const id_type key) const { + [[nodiscard]] [[deprecated("use ::custom() instead")]] meta_prop prop(const id_type key) const { const auto *elem = internal::look_for<&internal::meta_type_descriptor::prop>(internal::meta_context::from(*ctx), node, key); return elem ? meta_prop{*ctx, *elem} : meta_prop{}; }