diff --git a/src/Magnum/Resource.h b/src/Magnum/Resource.h index e5cbae549..4f6790d9c 100644 --- a/src/Magnum/Resource.h +++ b/src/Magnum/Resource.h @@ -5,6 +5,7 @@ Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Vladimír Vondruš + Copyright © 2019 Daniel Guzman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -150,6 +151,16 @@ class Resource { /** @brief Move assignment */ Resource& operator=(Resource&& other); + /** @brief Equality comparison */ + bool operator==(const Resource& other) const { + return manager == other.manager && _key == other._key; + } + + /** @brief Non-equality comparison */ + bool operator!=(const Resource& other) const { + return !operator==(other); + } + /** @brief Resource key */ ResourceKey key() const { return _key; } diff --git a/src/Magnum/Test/ResourceManagerTest.cpp b/src/Magnum/Test/ResourceManagerTest.cpp index 283018bf4..c325b4095 100644 --- a/src/Magnum/Test/ResourceManagerTest.cpp +++ b/src/Magnum/Test/ResourceManagerTest.cpp @@ -3,6 +3,7 @@ Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Vladimír Vondruš + Copyright © 2019 Daniel Guzman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -34,6 +35,7 @@ namespace Magnum { namespace Test { namespace { struct ResourceManagerTest: TestSuite::Tester { explicit ResourceManagerTest(); + void compare(); void state(); void stateFallback(); void stateDisallowed(); @@ -63,7 +65,8 @@ typedef Magnum::ResourceManager ResourceManager; size_t Data::count = 0; ResourceManagerTest::ResourceManagerTest() { - addTests({&ResourceManagerTest::state, + addTests({&ResourceManagerTest::compare, + &ResourceManagerTest::state, &ResourceManagerTest::stateFallback, &ResourceManagerTest::stateDisallowed, &ResourceManagerTest::basic, @@ -80,6 +83,23 @@ ResourceManagerTest::ResourceManagerTest() { &ResourceManagerTest::debugResourceState}); } +void ResourceManagerTest::compare() { + ResourceManager rm1; + + ResourceKey resKeyA("keyA"); + ResourceKey resKeyB("keyB"); + rm1.set(resKeyA, 1); + rm1.set(resKeyB, 0); + + Resource resA1 = rm1.get(resKeyA); + Resource resA2 = rm1.get(resKeyA); + Resource resB = rm1.get(resKeyB); + + CORRADE_VERIFY(resA1 == resA1); + CORRADE_VERIFY(resA1 == resA2); + CORRADE_VERIFY(resA1 != resB); +} + void ResourceManagerTest::state() { ResourceManager rm;