From e99e1dc2acda1362281acc78235e8655829a09ec Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Sun, 19 Apr 2020 17:47:18 +0200 Subject: [PATCH] meta: factory::alias -> factory::type (with type_info::id as a default identifier) --- docs/md/meta.md | 39 +++++++++++++++++++++------------------ src/entt/meta/factory.hpp | 17 ++++++++++++----- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/docs/md/meta.md b/docs/md/meta.md index e2b7860cc..69fc688f1 100644 --- a/docs/md/meta.md +++ b/docs/md/meta.md @@ -46,13 +46,13 @@ identifier is required, it's likely that a user defined literal is used as follows: ```cpp -auto factory = entt::meta().alias("reflected_type"_hs); +auto factory = entt::meta().type("reflected_type"_hs); ``` For what it's worth, this is likely completely equivalent to: ```cpp -auto factory = entt::meta().alias(42); +auto factory = entt::meta().type(42); ``` Obviously, human-readable identifiers are more convenient to use and highly @@ -75,18 +75,21 @@ The returned value is a factory object to use to continue building the meta type. In order to make the type _visible_, users can assign it an identifier: ```cpp -auto factory = entt::meta().alias("reflected_type"_hs); +auto factory = entt::meta().type("reflected_type"_hs); +``` + +Or use the default one, that is, the built-in identifier for the given type: + +```cpp +auto factory = entt::meta().type(); ``` -When working with named types, it isn't even necessary to specify the -identifier. In fact, it isn't allowed and it will trigger a compilation -error.
Identifiers are important because users can retrieve meta types at runtime by -searching for them by _name_ other than by type. On the other hand, there are -cases in which users can be interested in adding features to a reflected type so -that the reflection system can use it correctly under the hood, but they don't -want to allow searching the type by _name_. In this case, it's sufficient not -to invoke `type` and the type will not be searchable _by name_. +searching for them by _name_ other than by type.
+On the other hand, there are cases in which users can be interested in adding +features to a reflected type so that the reflection system can use it correctly +under the hood, but they don't want to also make the type _searchable_. In this +case, it's sufficient not to invoke `type`. A factory is such that all its member functions returns the factory itself or a decorated version of it. This object can be used to add the following: @@ -490,7 +493,7 @@ object.
Apparently, it's more difficult to say than to do: ```cpp -entt::meta().alias("reflected_type"_hs).prop("tooltip"_hs, "message"); +entt::meta().type("reflected_type"_hs).prop("tooltip"_hs, "message"); ``` Properties are always in the key/value form. There are no restrictions on the @@ -500,25 +503,25 @@ Multiple formats are supported when it comes to defining a property: * Properties as key/value pairs: ```cpp - entt::meta().alias("reflected_type"_hs).prop("tooltip"_hs, "message"); + entt::meta().type("reflected_type"_hs).prop("tooltip"_hs, "message"); ``` * Properties as `std::pair`s: ```cpp - entt::meta().alias("reflected_type"_hs).prop(std::make_pair("tooltip"_hs, "message")); + entt::meta().type("reflected_type"_hs).prop(std::make_pair("tooltip"_hs, "message")); ``` * Key only properties: ```cpp - entt::meta().alias("reflected_type"_hs).prop(my_enum::key_only); + entt::meta().type("reflected_type"_hs).prop(my_enum::key_only); ``` * Properties as `std::tuple`s: ```cpp - entt::meta().alias("reflected_type"_hs).prop(std::make_tuple(std::make_pair("tooltip"_hs, "message"), my_enum::key_only)); + entt::meta().type("reflected_type"_hs).prop(std::make_tuple(std::make_pair("tooltip"_hs, "message"), my_enum::key_only)); ``` A tuple contains one or more properties. All of them are treated individually. @@ -526,7 +529,7 @@ Multiple formats are supported when it comes to defining a property: * Annotations: ```cpp - entt::meta().alias("reflected_type"_hs).prop(&property_generator); + entt::meta().type("reflected_type"_hs).prop(&property_generator); ``` An annotation is an invocable object that returns one or more properties. All @@ -537,7 +540,7 @@ each property to associate with the last meta object created: ```cpp entt::meta() - .alias("reflected_type"_hs) + .type("reflected_type"_hs) .prop(entt::hashed_string{"Name"}, "Reflected Type") .data<&my_type::data_member>("member"_hs) .prop(std::make_pair("tooltip"_hs, "Member")) diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index b46974623..24bd4b0e7 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -10,6 +10,7 @@ #include #include "../config/config.h" #include "../core/fwd.hpp" +#include "../core/type_info.hpp" #include "../core/type_traits.hpp" #include "../core/utility.hpp" #include "meta.hpp" @@ -385,22 +386,28 @@ class meta_factory { public: /** - * @brief Extends a meta type by assigning it an alias. - * @param value Unique identifier. + * @brief Makes a meta type _searchable_. + * @param id Optional unique identifier. * @return An extended meta factory for the given type. */ - auto alias(const id_type value) ENTT_NOEXCEPT { + auto type(const id_type id = type_info::id()) { auto * const node = internal::meta_info::resolve(); - ENTT_ASSERT(!exists(value, *internal::meta_context::global)); + ENTT_ASSERT(!exists(id, *internal::meta_context::global)); ENTT_ASSERT(!exists(node, *internal::meta_context::global)); - node->alias = value; + node->alias = id; node->next = *internal::meta_context::global; *internal::meta_context::global = node; return meta_factory{&node->prop}; } + /*! @copydoc type */ + [[deprecated("use ::type instead")]] + auto alias(const id_type id) ENTT_NOEXCEPT { + return type(id); + } + /** * @brief Assigns a meta base to a meta type. *