meta: deprecate meta properties in favor of custom data
This commit is contained in:
1
TODO
1
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
|
||||
|
||||
@@ -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<my_type>().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.<br/>
|
||||
Key only properties are also supported out of the box:
|
||||
|
||||
```cpp
|
||||
entt::meta<my_type>().prop(my_enum::key_only);
|
||||
```
|
||||
|
||||
To attach multiple properties to a meta object, just invoke `prop` more than
|
||||
once.<br/>
|
||||
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<my_type>()
|
||||
.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<my_type>().prop()) {
|
||||
// ...
|
||||
}
|
||||
|
||||
// search for a given property by name
|
||||
auto prop = entt::resolve<my_type>().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:
|
||||
|
||||
@@ -498,7 +498,7 @@ public:
|
||||
* @return A meta factory for the parent type.
|
||||
*/
|
||||
template<typename... Value>
|
||||
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<void>});
|
||||
} else {
|
||||
|
||||
@@ -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<meta_prop, typename decltype(internal::meta_data_node::prop)::const_iterator> prop() const noexcept {
|
||||
[[nodiscard]] [[deprecated("use ::custom() instead")]] meta_range<meta_prop, typename decltype(internal::meta_data_node::prop)::const_iterator> 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<meta_prop, typename decltype(internal::meta_func_node::prop)::const_iterator> prop() const noexcept {
|
||||
[[nodiscard]] [[deprecated("use ::custom() instead")]] meta_range<meta_prop, typename decltype(internal::meta_func_node::prop)::const_iterator> 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<meta_prop, typename decltype(internal::meta_type_descriptor::prop)::const_iterator> prop() const noexcept {
|
||||
[[nodiscard]] [[deprecated("use ::custom() instead")]] meta_range<meta_prop, typename decltype(internal::meta_type_descriptor::prop)::const_iterator> prop() const noexcept {
|
||||
using range_type = meta_range<meta_prop, typename decltype(internal::meta_type_descriptor::prop)::const_iterator>;
|
||||
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{};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user