Browse Source

Added equal and not equal operators in Magnum::Resource

pull/349/head
Daniel Guzman 7 years ago committed by Vladimír Vondruš
parent
commit
909b05b8fa
  1. 11
      src/Magnum/Resource.h
  2. 22
      src/Magnum/Test/ResourceManagerTest.cpp

11
src/Magnum/Resource.h

@ -5,6 +5,7 @@
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
Vladimír Vondruš <mosra@centrum.cz>
Copyright © 2019 Daniel Guzman <daniel.guzman85@gmail.com>
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<T, U>& operator=(Resource<T, U>&& other);
/** @brief Equality comparison */
bool operator==(const Resource<T, U>& other) const {
return manager == other.manager && _key == other._key;
}
/** @brief Non-equality comparison */
bool operator!=(const Resource<T, U>& other) const {
return !operator==(other);
}
/** @brief Resource key */
ResourceKey key() const { return _key; }

22
src/Magnum/Test/ResourceManagerTest.cpp

@ -3,6 +3,7 @@
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
Vladimír Vondruš <mosra@centrum.cz>
Copyright © 2019 Daniel Guzman <daniel.guzman85@gmail.com>
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<Int, Data> 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<Int> resA1 = rm1.get<Int>(resKeyA);
Resource<Int> resA2 = rm1.get<Int>(resKeyA);
Resource<Int> resB = rm1.get<Int>(resKeyB);
CORRADE_VERIFY(resA1 == resA1);
CORRADE_VERIFY(resA1 == resA2);
CORRADE_VERIFY(resA1 != resB);
}
void ResourceManagerTest::state() {
ResourceManager rm;

Loading…
Cancel
Save