meta (prep for hook func):

* removed meta_type::reset
* added meta_reset overloads
This commit is contained in:
Michele Caini
2021-07-23 13:29:18 +02:00
parent 959bc269e4
commit 2b07b92039
18 changed files with 120 additions and 100 deletions

View File

@@ -942,7 +942,21 @@ objects from it and making its identifier no longer visible. The underlying node
will remain available though, as if it were implicitly generated:
```cpp
entt::resolve<my_type>().reset();
entt::meta_reset<my_type>();
```
The type can be re-registered later with a completely different name and form.
It's also possible to reset types by their unique identifiers if required:
```cpp
entt::meta_reset("my_type"_hs);
```
Finally, there exists a non-template overload of the `meta_reset` function that
doesn't accept argument and resets all searchable types (that is, all types that
were assigned an unique identifier):
```cpp
entt::meta_reset();
```
All types can be re-registered later with a completely different name and form.

View File

@@ -44,6 +44,30 @@ template<typename Id, typename Node>
}
template<auto... Member, typename Node>
void meta_reset(Node **curr) {
while(*curr) {
(meta_reset(&((*curr)->*Member)), ...);
*curr = std::exchange((*curr)->next, nullptr);
}
}
inline void meta_reset(internal::meta_type_node *node) ENTT_NOEXCEPT {
meta_reset(&node->prop);
meta_reset(&node->base);
meta_reset(&node->conv);
meta_reset<&internal::meta_ctor_node::prop>(&node->ctor);
meta_reset<&internal::meta_data_node::prop>(&node->data);
meta_reset<&internal::meta_func_node::prop>(&node->func);
node->id = {};
node->ctor = node->def_ctor;
node->dtor = nullptr;
node->next = nullptr;
}
}
@@ -570,6 +594,54 @@ template<typename Type>
}
/**
* @brief Resets a type and all its parts.
*
* Resets 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 reset but the link between the two types is removed.
*
* The type is also removed from the list of searchable types.
*/
template<typename Type>
void meta_reset() ENTT_NOEXCEPT {
meta_reset(internal::meta_info<Type>::resolve()->id);
}
/**
* @brief Resets a type and all its parts.
*
* @sa meta_reset
*
* @param id Unique identifier.
*/
inline void meta_reset(const id_type id) ENTT_NOEXCEPT {
for(auto** it = internal::meta_context::global(); *it; it = &(*it)->next) {
if((*it)->id == id) {
internal::meta_type_node *node = *it;
*it = (*it)->next;
internal::meta_reset(node);
break;
}
}
}
/**
* @brief Resets all searchable types.
*
* @sa meta_reset
*/
inline void meta_reset() ENTT_NOEXCEPT {
for(auto** it = internal::meta_context::global(); *it; it = &(*it)->next) {
internal::meta_reset(*it);
}
*internal::meta_context::global() = nullptr;
}
}

View File

@@ -1082,14 +1082,6 @@ class meta_type {
return nullptr;
}
template<auto... Member, typename Node>
void unregister_all(Node **curr) {
while(*curr) {
(unregister_all(&((*curr)->*Member)), ...);
*curr = std::exchange((*curr)->next, nullptr);
}
}
public:
/*! @brief Node type. */
using node_type = internal::meta_type_node;
@@ -1099,7 +1091,7 @@ public:
using size_type = typename node_type::size_type;
/*! @copydoc meta_prop::meta_prop */
meta_type(node_type *curr = nullptr) ENTT_NOEXCEPT
meta_type(const node_type *curr = nullptr) ENTT_NOEXCEPT
: node{curr}
{}
@@ -1107,7 +1099,7 @@ public:
* @brief Constructs an instance from a given base node.
* @param curr The base node with which to construct the instance.
*/
meta_type(base_node_type *curr) ENTT_NOEXCEPT
meta_type(const base_node_type *curr) ENTT_NOEXCEPT
: node{curr ? curr->type : nullptr}
{}
@@ -1567,38 +1559,8 @@ public:
return (!node && !other.node) || (node && other.node && node->info == other.node->info);
}
/**
* @brief Resets a type and all its parts.
*
* This function resets 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 reset but the link between the two types is removed.
*
* The type is also removed from the list of searchable types.
*/
void reset() ENTT_NOEXCEPT {
for(auto** it = internal::meta_context::global(); *it; it = &(*it)->next) {
if(*it == node) {
*it = (*it)->next;
break;
}
}
unregister_all(&node->prop);
unregister_all(&node->base);
unregister_all(&node->conv);
unregister_all<&internal::meta_ctor_node::prop>(&node->ctor);
unregister_all<&internal::meta_data_node::prop>(&node->data);
unregister_all<&internal::meta_func_node::prop>(&node->func);
node->id = {};
node->ctor = node->def_ctor;
node->dtor = nullptr;
}
private:
node_type *node;
const node_type *node;
};

View File

@@ -84,9 +84,7 @@ struct MetaAny: ::testing::Test {
}
void TearDown() override {
for(auto type: entt::resolve()) {
type.reset();
}
entt::meta_reset();
}
};

View File

@@ -23,9 +23,7 @@ struct MetaBase: ::testing::Test {
}
void TearDown() override {
for(auto type: entt::resolve()) {
type.reset();
}
entt::meta_reset();
}
};

View File

@@ -19,9 +19,7 @@ struct MetaContainer: ::testing::Test {
}
void TearDown() override {
for(auto type: entt::resolve()) {
type.reset();
}
entt::meta_reset();
}
};

View File

@@ -26,9 +26,7 @@ struct MetaConv: ::testing::Test {
}
void TearDown() override {
for(auto type: entt::resolve()) {
type.reset();
}
entt::meta_reset();
}
};

View File

@@ -55,9 +55,7 @@ struct MetaCtor: ::testing::Test {
}
void TearDown() override {
for(auto type: entt::resolve()) {
type.reset();
}
entt::meta_reset();
}
};

View File

@@ -118,9 +118,7 @@ struct MetaData: ::testing::Test {
}
void TearDown() override {
for(auto type: entt::resolve()) {
type.reset();
}
entt::meta_reset();
}
};

View File

@@ -33,9 +33,7 @@ struct MetaDtor: ::testing::Test {
}
void TearDown() override {
for(auto type: entt::resolve()) {
type.reset();
}
entt::meta_reset();
}
};

View File

@@ -96,9 +96,7 @@ struct MetaFunc: ::testing::Test {
}
void TearDown() override {
for(auto type: entt::resolve()) {
type.reset();
}
entt::meta_reset();
}
};

View File

@@ -22,9 +22,7 @@ struct MetaHandle: ::testing::Test {
}
void TearDown() override {
for(auto type: entt::resolve()) {
type.reset();
}
entt::meta_reset();
}
};

View File

@@ -29,9 +29,7 @@ struct MetaProp: ::testing::Test {
}
void TearDown() override {
for(auto type: entt::resolve()) {
type.reset();
}
entt::meta_reset();
}
};

View File

@@ -14,9 +14,7 @@ struct MetaRange: ::testing::Test {
}
void TearDown() override {
for(auto type: entt::resolve()) {
type.reset();
}
entt::meta_reset();
}
};

View File

@@ -156,9 +156,7 @@ struct MetaType: ::testing::Test {
}
void TearDown() override {
for(auto type: entt::resolve()) {
type.reset();
}
entt::meta_reset();
}
};
@@ -488,7 +486,7 @@ TEST_F(MetaType, Reset) {
// implicitly generated default constructor
ASSERT_TRUE(entt::resolve<clazz_t>().ctor<>());
entt::resolve("clazz"_hs).reset();
entt::meta_reset("clazz"_hs);
ASSERT_FALSE(entt::resolve("clazz"_hs));
ASSERT_NE(entt::resolve<clazz_t>().id(), "clazz"_hs);
@@ -514,11 +512,7 @@ TEST_F(MetaType, ResetAll) {
ASSERT_TRUE(entt::resolve("overloaded_func"_hs));
ASSERT_TRUE(entt::resolve("double"_hs));
for(auto type: entt::resolve()) {
// we exploit the fact that the iterators aren't invalidated
// because EnTT leaves a dangling ::next in the underlying node
type.reset();
}
entt::meta_reset();
ASSERT_FALSE(entt::resolve("clazz"_hs));
ASSERT_FALSE(entt::resolve("overloaded_func"_hs));
@@ -624,15 +618,15 @@ TEST_F(MetaType, ResetAndReRegistrationAfterReset) {
ASSERT_NE(*entt::internal::meta_context::global(), nullptr);
entt::resolve<double>().reset();
entt::resolve<unsigned int>().reset();
entt::resolve<base_t>().reset();
entt::resolve<derived_t>().reset();
entt::resolve<abstract_t>().reset();
entt::resolve<concrete_t>().reset();
entt::resolve<overloaded_func_t> ().reset ();
entt::resolve<property_t>().reset();
entt::resolve<clazz_t>().reset();
entt::meta_reset<double>();
entt::meta_reset<unsigned int>();
entt::meta_reset<base_t>();
entt::meta_reset<derived_t>();
entt::meta_reset<abstract_t>();
entt::meta_reset<concrete_t>();
entt::meta_reset<overloaded_func_t>();
entt::meta_reset<property_t>();
entt::meta_reset<clazz_t>();
ASSERT_FALSE(entt::resolve("double"_hs));
ASSERT_FALSE(entt::resolve("base"_hs));

View File

@@ -26,8 +26,8 @@ ENTT_API void set_up() {
}
ENTT_API void tear_down() {
entt::resolve<position>().reset();
entt::resolve<velocity>().reset();
entt::meta_reset<position>();
entt::meta_reset<velocity>();
}
ENTT_API entt::meta_any wrap_int(int value) {

View File

@@ -26,8 +26,8 @@ void set_up() {
}
void tear_down() {
entt::resolve<position>().reset();
entt::resolve<velocity>().reset();
entt::meta_reset<position>();
entt::meta_reset<velocity>();
}
CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {

View File

@@ -26,8 +26,8 @@ void set_up() {
}
void tear_down() {
entt::resolve<position>().reset();
entt::resolve<velocity>().reset();
entt::meta_reset<position>();
entt::meta_reset<velocity>();
}
CR_EXPORT int cr_main(cr_plugin *ctx, cr_op operation) {