diff options
author | Alec Thomas <alec@swapoff.org> | 2014-08-08 07:56:55 +1000 |
---|---|---|
committer | Alec Thomas <alec@swapoff.org> | 2014-08-08 07:56:55 +1000 |
commit | 955f9422d8646e1f6b1c22bdc0a40f59a34ae0a8 (patch) | |
tree | 2de63305d11d0e1f0aeeca4e5589c2365d58afce | |
parent | aed41e4311e6e0080ef55b673500c0facfee90c2 (diff) | |
parent | 578a0a5214806c18a981a990539bcf0b71156f11 (diff) |
Merge pull request #46 from scrpi/master
Added operator< overload for Entity class. Allowing use of Entity obects...
-rw-r--r-- | entityx/Entity.h | 4 | ||||
-rw-r--r--[-rwxr-xr-x] | entityx/Entity_test.cc | 28 |
2 files changed, 32 insertions, 0 deletions
diff --git a/entityx/Entity.h b/entityx/Entity.h index 7312e25..e30f87e 100644 --- a/entityx/Entity.h +++ b/entityx/Entity.h @@ -102,6 +102,10 @@ public: return !(other == *this); } + bool operator < (const Entity &other) const { + return other.id_ < id_; + } + /** * Is this Entity handle valid? * diff --git a/entityx/Entity_test.cc b/entityx/Entity_test.cc index ee1ccac..9140773 100755..100644 --- a/entityx/Entity_test.cc +++ b/entityx/Entity_test.cc @@ -15,6 +15,8 @@ #include <string> #include <utility> #include <vector> +#include <set> +#include <map> #include "entityx/3rdparty/catch.hpp" #include "entityx/Entity.h" @@ -23,6 +25,9 @@ using namespace entityx; using std::ostream; using std::vector; +using std::set; +using std::map; +using std::pair; using std::string; template <typename T> @@ -491,3 +496,26 @@ TEST_CASE_METHOD(EntityManagerFixture, "TestDeleteEntityWithNoComponents") { Entity b = em.create(); b.destroy(); } + +TEST_CASE_METHOD(EntityManagerFixture, "TestEntityInStdSet") { + Entity a = em.create(); + Entity b = em.create(); + Entity c = em.create(); + set<Entity> entitySet; + REQUIRE(entitySet.insert(a).second); + REQUIRE(entitySet.insert(b).second); + REQUIRE(entitySet.insert(c).second); +} + +TEST_CASE_METHOD(EntityManagerFixture, "TestEntityInStdMap") { + Entity a = em.create(); + Entity b = em.create(); + Entity c = em.create(); + map<Entity, int> entityMap; + REQUIRE(entityMap.insert(pair<Entity, int>(a, 1)).second); + REQUIRE(entityMap.insert(pair<Entity, int>(b, 2)).second); + REQUIRE(entityMap.insert(pair<Entity, int>(c, 3)).second); + REQUIRE(entityMap[a] == 1); + REQUIRE(entityMap[b] == 2); + REQUIRE(entityMap[c] == 3); +} |