meta: removed reset-all function (it was logically broken across boundaries)

This commit is contained in:
Michele Caini
2019-11-11 00:35:33 +01:00
parent 82f33b82e3
commit ea86d33bc1
7 changed files with 43 additions and 73 deletions

View File

@@ -583,14 +583,3 @@ entt::meta<my_type>().reset();
```
The type can be re-registered later with a completely different name and form.
To unregister all the types at once instead, a generic meta factory is the way
to go:
```cpp
entt::meta().reset();
```
This function may touch more meta types than those explicitly created by the
user. In fact, all locally created meta types are visited and reset, including
those implicitly generated by the meta system under the hood.

View File

@@ -248,28 +248,6 @@ template<typename...>
class meta_factory;
/*! @brief Generic meta factory to be used for reflection purposes. */
template<>
class meta_factory<> {
public:
/**
* @brief Resets all meta types and all their parts.
*
* This function resets all meta type and their data members, member
* functions and properties, as well as their constructors, destructors,
* base classes and conversion functions if any.
*/
void reset() ENTT_NOEXCEPT {
auto *it = internal::meta_info<>::context;
while(it) {
internal::meta_info<>::reset(it);
it = it->context;
}
}
};
/**
* @brief Extended meta factory to be used for reflection purposes.
* @tparam Type Reflected type for which the factory was created.
@@ -410,8 +388,6 @@ class meta_factory<Type> {
ENTT_ASSERT(!duplicate(node, *internal::meta_info<>::global));
node->identifier = identifier;
node->next = *internal::meta_info<>::global;
if(node->next) { node->next->hook = &node->next; }
node->hook = internal::meta_info<>::global;
*internal::meta_info<>::global = node;
return meta_factory<Type, Type>{&node->prop};
@@ -832,21 +808,16 @@ 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 meta objects through a
* dedicated factory. If no type is provided instead, a generic meta factory is
* returned.
* dedicated factory.
*
* @tparam Type Type to reflect, if any.
* @return An eventually generic meta factory.
* @tparam Type Type to reflect.
* @return An meta factory for the given type.
*/
template<typename... Type>
inline meta_factory<Type...> meta() ENTT_NOEXCEPT {
if constexpr(sizeof...(Type) == 0) {
return meta_factory{};
} else {
auto * const node = internal::meta_info<Type...>::resolve();
// extended meta factory to allow assigning properties to opaque meta types
return meta_factory<Type..., Type...>{&node->prop};
}
template<typename Type>
inline meta_factory<Type> meta() ENTT_NOEXCEPT {
auto * const node = internal::meta_info<Type>::resolve();
// extended meta factory to allow assigning properties to opaque meta types
return meta_factory<Type, Type>{&node->prop};
}

View File

@@ -102,9 +102,7 @@ struct meta_func_node {
struct meta_type_node {
using size_type = std::size_t;
meta_type_node * const context;
ENTT_ID_TYPE identifier;
meta_type_node ** hook;
meta_type_node * next;
meta_prop_node * prop;
const bool is_void;
@@ -201,15 +199,16 @@ template<>
struct meta_node<> {
inline static meta_type_node *local = nullptr;
inline static meta_type_node **global = &local;
inline static meta_type_node *context = nullptr;
static void reset(meta_type_node *node) ENTT_NOEXCEPT {
if(node->hook) {
*node->hook = node->next;
auto **it = global;
if(node->next) {
node->next->hook = node->hook;
}
while(*it && *it != node) {
it = &(*it)->next;
}
if(*it) {
*it = (*it)->next;
}
const auto unregister_all = y_combinator{
@@ -231,7 +230,6 @@ struct meta_node<> {
unregister_all(&node->func, &internal::meta_func_node::prop);
node->identifier = {};
node->hook = nullptr;
node->next = nullptr;
node->dtor = nullptr;
}
@@ -244,15 +242,9 @@ struct meta_node<Type> {
static meta_type_node * resolve() ENTT_NOEXCEPT {
static meta_type_node node{
[]() {
auto *curr = meta_node<>::context;
meta_node<>::context = &node;
return curr;
}(),
{},
nullptr,
nullptr,
nullptr,
std::is_void_v<Type>,
std::is_integral_v<Type>,
std::is_floating_point_v<Type>,

View File

@@ -2043,18 +2043,36 @@ TEST_F(Meta, Reset) {
ASSERT_NE(*entt::internal::meta_info<>::global, nullptr);
ASSERT_NE(entt::internal::meta_info<>::local, nullptr);
ASSERT_TRUE(entt::resolve("char"_hs));
ASSERT_TRUE(entt::resolve("base"_hs));
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<props>().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_FALSE(entt::resolve("char"_hs));
ASSERT_TRUE(entt::resolve("base"_hs));
entt::meta().reset();
ASSERT_EQ(*entt::internal::meta_info<>::global, nullptr);
ASSERT_EQ(entt::internal::meta_info<>::local, nullptr);
ASSERT_FALSE(entt::resolve("char"_hs));
ASSERT_FALSE(entt::resolve("base"_hs));
ASSERT_FALSE(entt::resolve("derived"_hs));
ASSERT_FALSE(entt::resolve("empty"_hs));
ASSERT_FALSE(entt::resolve("fat"_hs));
ASSERT_FALSE(entt::resolve("data"_hs));
ASSERT_FALSE(entt::resolve("func"_hs));
ASSERT_FALSE(entt::resolve("setter_getter"_hs));
ASSERT_FALSE(entt::resolve("an_abstract_type"_hs));
ASSERT_FALSE(entt::resolve("another_abstract_type"_hs));
ASSERT_FALSE(entt::resolve("concrete"_hs));
ASSERT_EQ(*entt::internal::meta_info<>::global, nullptr);
ASSERT_EQ(entt::internal::meta_info<>::local, nullptr);

View File

@@ -56,5 +56,5 @@ LIB_EXPORT void a_module_meta_init() {
}
LIB_EXPORT void a_module_meta_deinit() {
entt::meta().reset();
entt::meta<char>().reset();
}

View File

@@ -61,5 +61,5 @@ LIB_EXPORT void another_module_meta_init() {
}
LIB_EXPORT void another_module_meta_deinit() {
entt::meta().reset();
entt::meta<int>().reset();
}

View File

@@ -129,7 +129,7 @@ TEST(Lib, Meta) {
ASSERT_TRUE(entt::resolve<char>().data("c"_hs));
a_module_meta_deinit();
entt::meta().reset();
entt::meta<double>().reset();
another_module_meta_deinit();
ASSERT_FALSE(entt::resolve("double"_hs));