registry: swap
This commit is contained in:
@@ -425,6 +425,23 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Exchanges the contents with those of a given registry.
|
||||
* @param other Registry to exchange the content with.
|
||||
*/
|
||||
void swap(basic_registry &other) {
|
||||
using std::swap;
|
||||
propagate_on_container_swap(free_list.second(), other.free_list.second());
|
||||
swap(free_list.first(), other.free_list.first());
|
||||
swap(pools, other.pools);
|
||||
swap(groups, other.groups);
|
||||
swap(epool, other.epool);
|
||||
swap(vars, other.vars);
|
||||
|
||||
rebind();
|
||||
other.rebind();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the associated allocator.
|
||||
* @return The associated allocator.
|
||||
|
||||
@@ -396,6 +396,36 @@ TEST(Registry, Move) {
|
||||
ASSERT_EQ(test.parent, ®istry);
|
||||
}
|
||||
|
||||
TEST(Registry, Swap) {
|
||||
entt::registry registry;
|
||||
const auto entity = registry.create();
|
||||
owner test{};
|
||||
|
||||
registry.on_construct<int>().connect<&owner::receive>(test);
|
||||
registry.on_destroy<int>().connect<&owner::receive>(test);
|
||||
|
||||
ASSERT_EQ(test.parent, nullptr);
|
||||
|
||||
registry.emplace<int>(entity);
|
||||
|
||||
ASSERT_EQ(test.parent, ®istry);
|
||||
|
||||
entt::registry other;
|
||||
other.swap(registry);
|
||||
other.erase<int>(entity);
|
||||
|
||||
registry = {};
|
||||
registry.emplace<int>(registry.create(entity));
|
||||
|
||||
ASSERT_EQ(test.parent, &other);
|
||||
|
||||
registry.swap(other);
|
||||
registry.emplace<int>(entity);
|
||||
registry.emplace<int>(registry.create(entity));
|
||||
|
||||
ASSERT_EQ(test.parent, ®istry);
|
||||
}
|
||||
|
||||
TEST(Registry, ReplaceAggregate) {
|
||||
entt::registry registry;
|
||||
const auto entity = registry.create();
|
||||
|
||||
Reference in New Issue
Block a user