meta: meta_factory::type supports named types (the identifier isn't required in this case)

This commit is contained in:
Michele Caini
2019-10-14 14:26:01 +02:00
parent e5a075a329
commit 0e3bdc02ea
4 changed files with 30 additions and 10 deletions

2
TODO
View File

@@ -32,10 +32,10 @@
* add examples (and credits) from @alanjfs :)
* explore the possibility to wrap other backend with a XHandler component
* use [[nodiscard]] consistently for safety purposes
* static reflection, hint: template<> meta_type_t<Type>: meta_descriptor<name, func..., props..., etc...>
* make meta work across boundaries
- extend and make factory::prop more flexible
- entt::reflect<T>().type("foo"_hs, entt::as_property); or similar
- name-less reflect/type (for named types)
- a better context
- tests, doc

View File

@@ -262,13 +262,7 @@ class meta_factory {
return node && (node->identifier == identifier || duplicate(identifier, node->next));
}
public:
/**
* @brief Extends a meta type by assigning it an identifier.
* @param identifier Unique identifier.
* @return An extended meta factory for the parent type.
*/
auto type(const ENTT_ID_TYPE identifier) ENTT_NOEXCEPT {
auto record(const ENTT_ID_TYPE identifier) ENTT_NOEXCEPT {
auto * const node = internal::meta_info<Type>::resolve();
ENTT_ASSERT(!duplicate(identifier, *internal::meta_info<>::ctx));
@@ -280,6 +274,32 @@ public:
return extended_meta_factory<Type>{&node->prop};
}
public:
/**
* @brief Extends a meta type by assigning it an identifier.
*
* This function is intended only for unnamed types.
*
* @param identifier Unique identifier.
* @return An extended meta factory for the parent type.
*/
auto type(const ENTT_ID_TYPE identifier) ENTT_NOEXCEPT {
static_assert(!is_named_type_v<Type>);
return record(identifier);
}
/**
* @brief Extends a meta type by assigning it an identifier.
*
* This function is intended only for named types
*
* @return An extended meta factory for the parent type.
*/
auto type() ENTT_NOEXCEPT {
static_assert(is_named_type_v<Type>);
return record(named_type_traits_t<Type>::value);
}
/**
* @brief Assigns a meta base to a meta type.
*

View File

@@ -52,7 +52,7 @@ LIB_EXPORT void a_module_meta_ctx(entt::meta_ctx context) {
}
LIB_EXPORT void a_module_meta_init() {
entt::meta<char>().type("char"_hs).data<'c'>("c"_hs);
entt::meta<char>().type().data<'c'>("c"_hs);
}
LIB_EXPORT void a_module_meta_deinit() {

View File

@@ -57,7 +57,7 @@ LIB_EXPORT void another_module_meta_ctx(entt::meta_ctx context) {
}
LIB_EXPORT void another_module_meta_init() {
entt::meta<int>().type("int"_hs).data<0>("0"_hs);
entt::meta<int>().type().data<0>("0"_hs);
}
LIB_EXPORT void another_module_meta_deinit() {