meta: cleanup and renaming

This commit is contained in:
Michele Caini
2019-10-10 23:28:13 +02:00
parent 085a281f8a
commit a0c3a82c76
6 changed files with 64 additions and 86 deletions

4
TODO
View File

@@ -31,9 +31,11 @@
* range based registry::remove and some others?
* add examples (and credits) from @alanjfs :)
* explore the possibility to wrap other backend with a XHandler component
* use [[nodiscard]] consistently for safety purposes
* make meta work across boundaries
- type(id, props...) -> type(id).properties(props...) with internal meta_prop_node ** as a sink
- entt::reflect<T>().type("foo"_hs, entt::as_property); or similar
- name-less reflect with properties
- forbid reflecting two times the same type
- entt::reflect -> entt::meta
- tests, doc

View File

@@ -700,15 +700,14 @@ public:
}
/**
* @brief Unregisters a meta type and all its parts.
* @brief Resets a meta type and all its parts.
*
* This function unregisters a meta type and all its data members, member
* This function resets a meta type and all its data members, member
* functions and properties, as well as its constructors, destructors and
* conversion functions if any.<br/>
* Base classes aren't unregistered but the link between the two types is
* removed.
* Base classes aren't reset but the link between the two types is removed.
*/
void unregister() ENTT_NOEXCEPT {
void reset() ENTT_NOEXCEPT {
internal::meta_info<Type>::reset();
}
};
@@ -719,55 +718,18 @@ public:
*
* This is the point from which everything starts.<br/>
* By invoking this function with a type that is not yet reflected, a meta type
* is created to which it will be possible to attach data and functions through
* a dedicated factory.
*
* @tparam Type Type to reflect.
* @tparam Property Types of properties to assign to the reflected type.
* @param identifier Unique identifier.
* @param property Properties to assign to the reflected type.
* @return A meta factory for the given type.
*/
template<typename Type, typename... Property>
inline meta_factory<Type> reflect(const ENTT_ID_TYPE identifier, Property &&... property) ENTT_NOEXCEPT {
return meta_factory<Type>{}.type(identifier, std::forward<Property>(property)...);
}
/**
* @brief Utility function to use for reflection.
*
* This is the point from which everything starts.<br/>
* By invoking this function with a type that is not yet reflected, a meta type
* is created to which it will be possible to attach data and functions through
* a dedicated factory.
* is created to which it will be possible to attach meta objects through a
* dedicated factory.
*
* @tparam Type Type to reflect.
* @return A meta factory for the given type.
*/
template<typename Type>
inline meta_factory<Type> reflect() ENTT_NOEXCEPT {
inline meta_factory<Type> meta() ENTT_NOEXCEPT {
return meta_factory<Type>{};
}
/**
* @brief Utility function to unregister a type.
*
* This function unregisters a type and all its data members, member functions
* and properties, as well as its constructors, destructors and conversion
* functions if any.<br/>
* Base classes aren't unregistered but the link between the two types is
* removed.
*
* @tparam Type Type to unregister.
*/
template<typename Type>
inline void unregister() ENTT_NOEXCEPT {
meta_factory<Type>{}.unregister();
}
/**
* @brief Returns the meta type associated with a given type.
* @tparam Type Type to use to search for a meta type.

View File

@@ -143,35 +143,41 @@ struct concrete_type: an_abstract_type, another_abstract_type {
struct Meta: ::testing::Test {
static void SetUpTestCase() {
entt::reflect<double>().conv<int>();
entt::meta<double>().conv<int>();
entt::reflect<char>("char"_hs, std::make_pair(properties::prop_int, 42))
entt::meta<char>()
.type("char"_hs, std::make_pair(properties::prop_int, 42))
.data<&set<char>, &get<char>>("value"_hs);
entt::reflect<properties>()
entt::meta<properties>()
.data<properties::prop_bool>("prop_bool"_hs)
.data<properties::prop_int>("prop_int"_hs)
.data<&set<properties>, &get<properties>>("value"_hs);
entt::reflect<unsigned int>().data<0u>("min"_hs).data<100u>("max"_hs);
entt::meta<unsigned int>().data<0u>("min"_hs).data<100u>("max"_hs);
entt::reflect<base_type>("base"_hs);
entt::meta<base_type>()
.type("base"_hs);
entt::reflect<derived_type>("derived"_hs, std::make_pair(properties::prop_int, 99))
entt::meta<derived_type>()
.type("derived"_hs, std::make_pair(properties::prop_int, 99))
.base<base_type>()
.ctor<const base_type &, int, char>(std::make_pair(properties::prop_bool, false))
.ctor<&derived_factory>(std::make_pair(properties::prop_int, 42))
.conv<&derived_type::f>()
.conv<&derived_type::g>();
entt::reflect<empty_type>("empty"_hs)
entt::meta<empty_type>()
.type("empty"_hs)
.dtor<&empty_type::destroy>();
entt::reflect<fat_type>("fat"_hs)
entt::meta<fat_type>()
.type("fat"_hs)
.base<empty_type>()
.dtor<&fat_type::destroy>();
entt::reflect<data_type>("data"_hs)
entt::meta<data_type>()
.type("data"_hs)
.data<&data_type::i, entt::as_alias_t>("i"_hs, std::make_pair(properties::prop_int, 0))
.data<&data_type::j>("j"_hs, std::make_pair(properties::prop_int, 1))
.data<&data_type::h>("h"_hs, std::make_pair(properties::prop_int, 2))
@@ -179,11 +185,13 @@ struct Meta: ::testing::Test {
.data<&data_type::empty>("empty"_hs)
.data<&data_type::v, entt::as_void_t>("v"_hs);
entt::reflect<array_type>("array"_hs)
entt::meta<array_type>()
.type("array"_hs)
.data<&array_type::global>("global"_hs)
.data<&array_type::local>("local"_hs);
entt::reflect<func_type>("func"_hs)
entt::meta<func_type>()
.type("func"_hs)
.func<entt::overload<int(const base_type &, int, int)>(&func_type::f)>("f3"_hs)
.func<entt::overload<int(int, int)>(&func_type::f)>("f2"_hs, std::make_pair(properties::prop_bool, false))
.func<entt::overload<int(int) const>(&func_type::f)>("f1"_hs, std::make_pair(properties::prop_bool, false))
@@ -193,34 +201,40 @@ struct Meta: ::testing::Test {
.func<&func_type::v, entt::as_void_t>("v"_hs)
.func<&func_type::a, entt::as_alias_t>("a"_hs);
entt::reflect<setter_getter_type>("setter_getter"_hs)
entt::meta<setter_getter_type>()
.type("setter_getter"_hs)
.data<&setter_getter_type::static_setter, &setter_getter_type::static_getter>("x"_hs)
.data<&setter_getter_type::setter, &setter_getter_type::getter>("y"_hs)
.data<&setter_getter_type::static_setter, &setter_getter_type::getter>("z"_hs)
.data<&setter_getter_type::setter_with_ref, &setter_getter_type::getter_with_ref>("w"_hs);
entt::reflect<an_abstract_type>("an_abstract_type"_hs, std::make_pair(properties::prop_bool, false))
entt::meta<an_abstract_type>()
.type("an_abstract_type"_hs, std::make_pair(properties::prop_bool, false))
.data<&an_abstract_type::i>("i"_hs)
.func<&an_abstract_type::f>("f"_hs)
.func<&an_abstract_type::g>("g"_hs);
entt::reflect<another_abstract_type>("another_abstract_type"_hs, std::make_pair(properties::prop_int, 42))
entt::meta<another_abstract_type>()
.type("another_abstract_type"_hs, std::make_pair(properties::prop_int, 42))
.data<&another_abstract_type::j>("j"_hs)
.func<&another_abstract_type::h>("h"_hs);
entt::reflect<concrete_type>("concrete"_hs)
entt::meta<concrete_type>()
.type("concrete"_hs)
.base<an_abstract_type>()
.base<another_abstract_type>()
.func<&concrete_type::f>("f"_hs);
}
static void SetUpAfterUnregistration() {
entt::reflect<double>().conv<float>();
entt::meta<double>().conv<float>();
entt::reflect<derived_type>("my_type"_hs, std::make_pair(properties::prop_bool, false))
entt::meta<derived_type>()
.type("my_type"_hs, std::make_pair(properties::prop_bool, false))
.ctor<>();
entt::reflect<another_abstract_type>("your_type"_hs)
entt::meta<another_abstract_type>()
.type("your_type"_hs)
.data<&another_abstract_type::j>("a_data_member"_hs)
.func<&another_abstract_type::h>("a_member_function"_hs);
}
@@ -1968,25 +1982,25 @@ TEST_F(Meta, Variables) {
ASSERT_EQ(c, 'x');
}
TEST_F(Meta, Unregister) {
TEST_F(Meta, Reset) {
ASSERT_NE(*entt::internal::meta_info<>::ctx, nullptr);
ASSERT_NE(entt::internal::meta_info<>::local, nullptr);
entt::unregister<char>();
entt::unregister<concrete_type>();
entt::unregister<setter_getter_type>();
entt::unregister<fat_type>();
entt::unregister<data_type>();
entt::unregister<func_type>();
entt::unregister<array_type>();
entt::unregister<double>();
entt::unregister<properties>();
entt::unregister<base_type>();
entt::unregister<derived_type>();
entt::unregister<empty_type>();
entt::unregister<an_abstract_type>();
entt::unregister<another_abstract_type>();
entt::unregister<unsigned int>();
entt::meta<char>().reset();
entt::meta<concrete_type>().reset();
entt::meta<setter_getter_type>().reset();
entt::meta<fat_type>().reset();
entt::meta<data_type>().reset();
entt::meta<func_type>().reset();
entt::meta<array_type>().reset();
entt::meta<double>().reset();
entt::meta<properties>().reset();
entt::meta<base_type>().reset();
entt::meta<derived_type>().reset();
entt::meta<empty_type>().reset();
entt::meta<an_abstract_type>().reset();
entt::meta<another_abstract_type>().reset();
entt::meta<unsigned int>().reset();
ASSERT_EQ(*entt::internal::meta_info<>::ctx, nullptr);
ASSERT_EQ(entt::internal::meta_info<>::local, nullptr);

View File

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

View File

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

View File

@@ -118,7 +118,7 @@ TEST(Lib, Meta) {
a_module_meta_ctx(entt::meta_ctx{});
another_module_meta_ctx(entt::meta_ctx{});
entt::reflect<double>("double"_hs).conv<int>();
entt::meta<double>().type("double"_hs).conv<int>();
another_module_meta_init();
a_module_meta_init();
@@ -130,7 +130,7 @@ TEST(Lib, Meta) {
a_module_meta_deinit();
another_module_meta_deinit();
entt::unregister<double>();
entt::meta<double>().reset();
ASSERT_FALSE(entt::resolve("double"_hs));
ASSERT_FALSE(entt::resolve("char"_hs));