diff options
author | Alec Thomas <alec@swapoff.org> | 2012-10-20 21:05:51 -0400 |
---|---|---|
committer | Alec Thomas <alec@swapoff.org> | 2012-10-20 21:05:51 -0400 |
commit | ec441e05616b3e9a5a384236b8c0ff536ed859e5 (patch) | |
tree | ef7f7bd3fcfdd4f5ce671b639a2c26b451be0327 | |
parent | da091e7c6fbe409ab704187f6ada9db1f2e0dece (diff) |
Convert EntityManager::unpack() to use boost::shared_ptr.
-rw-r--r-- | entityx/Entity.h | 14 | ||||
-rw-r--r-- | entityx/Entity_test.cc | 20 | ||||
-rw-r--r-- | entityx/System_test.cc | 8 |
3 files changed, 21 insertions, 21 deletions
diff --git a/entityx/Entity.h b/entityx/Entity.h index 85ee2b7..6c0ab55 100644 --- a/entityx/Entity.h +++ b/entityx/Entity.h @@ -379,13 +379,13 @@ class EntityManager : boost::noncopyable { * * Useful for fast bulk iterations. * - * Position *p; - * Direction *d; + * boost::shared_ptr<Position> p; + * boost::shared_ptr<Direction> d; * unpack<Position, Direction>(e, p, d); */ template <typename A> - void unpack(Entity id, A *&a) { - a = component<A>(id).get(); + void unpack(Entity id, boost::shared_ptr<A> &a) { + a = component<A>(id); } /** @@ -395,12 +395,12 @@ class EntityManager : boost::noncopyable { * * Useful for fast bulk iterations. * - * Position *p; - * Direction *d; + * boost::shared_ptr<Position> p; + * boost::shared_ptr<Direction> d; * unpack<Position, Direction>(e, p, d); */ template <typename A, typename B, typename ... Args> - void unpack(Entity id, A *&a, B *&b, Args *& ... args) { + void unpack(Entity id, boost::shared_ptr<A> &a, boost::shared_ptr<B> &b, Args & ... args) { unpack<A>(id, a); unpack<B, Args ...>(id, b, args ...); } diff --git a/entityx/Entity_test.cc b/entityx/Entity_test.cc index 962d858..33f3773 100644 --- a/entityx/Entity_test.cc +++ b/entityx/Entity_test.cc @@ -155,7 +155,7 @@ TEST_F(EntityManagerTest, TestGetEntitiesWithComponentAndUnpacking) { Entity e = em.create(); Entity f = em.create(); Entity g = em.create(); - std::vector<std::pair<boost::shared_ptr<Position>, boost::shared_ptr<Direction>>> position_directions; + std::vector<std::pair<shared_ptr<Position>, shared_ptr<Direction>>> position_directions; position_directions.push_back(std::make_pair( em.assign<Position>(e, 1.0f, 2.0f), em.assign<Direction>(e, 3.0f, 4.0f))); @@ -183,23 +183,23 @@ TEST_F(EntityManagerTest, TestUnpack) { auto p = em.assign<Position>(e); auto d = em.assign<Direction>(e); - Position *up; - Direction *ud; + shared_ptr<Position> up; + shared_ptr<Direction> ud; em.unpack<Position, Direction>(e, up, ud); - ASSERT_EQ(p.get(), up); - ASSERT_EQ(d.get(), ud); + ASSERT_EQ(p, up); + ASSERT_EQ(d, ud); } TEST_F(EntityManagerTest, TestUnpackNullMissing) { Entity e = em.create(); auto p = em.assign<Position>(e); - Position *up = reinterpret_cast<Position*>(0Xdeadbeef); - Direction *ud = reinterpret_cast<Direction*>(0Xdeadbeef); - ASSERT_EQ(reinterpret_cast<Direction*>(0xdeadbeef), ud); + struct NullDeleter {template<typename T> void operator()(T*) {} }; + shared_ptr<Position> up(reinterpret_cast<Position*>(0Xdeadbeef), NullDeleter()); + shared_ptr<Direction> ud(reinterpret_cast<Direction*>(0Xdeadbeef), NullDeleter()); em.unpack<Position, Direction>(e, up, ud); - ASSERT_EQ(p.get(), up); - ASSERT_EQ(nullptr, ud); + ASSERT_EQ(p, up); + ASSERT_EQ(shared_ptr<Direction>(), ud); } TEST_F(EntityManagerTest, TestComponentIdsDiffer) { diff --git a/entityx/System_test.cc b/entityx/System_test.cc index 43f5ea9..0c54dab 100644 --- a/entityx/System_test.cc +++ b/entityx/System_test.cc @@ -39,8 +39,8 @@ class MovementSystem : public System<MovementSystem> { void update(EntityManager &es, EventManager &events, double) override { EntityManager::View entities = es.entities_with_components<Position, Direction>(); - Position *position; - Direction *direction; + shared_ptr<Position> position; + shared_ptr<Direction> direction; for (auto entity : entities) { es.unpack<Position, Direction>(entity, position, direction); position->x += direction->x; @@ -102,8 +102,8 @@ TEST_F(SystemManagerTest, TestApplySystem) { world.sm().configure(); world.sm().update<MovementSystem>(0.0); - Position *position; - Direction *direction; + shared_ptr<Position> position; + shared_ptr<Direction> direction; for (auto entity : world.entities) { world.em().unpack<Position, Direction>(entity, position, direction); if (position && direction) { |