GeckoCode: Provide operator== and operator!= overloads

Same thing but allows both GeckoCode and Code to be utilized directly
without predicates for equality/inequality in stardard algorithms

The size check for std::vectors is unnecessary, as this is built into std::vector's operator==
This commit is contained in:
Lioncash
2016-10-03 01:52:33 -04:00
parent fba6801851
commit e8cd5a3979
3 changed files with 30 additions and 14 deletions

View File

@ -5,6 +5,7 @@
#include <algorithm>
#include <iterator>
#include <mutex>
#include <tuple>
#include <vector>
#include "Common/ChunkFile.h"
@ -20,6 +21,26 @@ namespace Gecko
{
static constexpr u32 CODE_SIZE = 8;
bool operator==(const GeckoCode& lhs, const GeckoCode& rhs)
{
return lhs.codes == rhs.codes;
}
bool operator!=(const GeckoCode& lhs, const GeckoCode& rhs)
{
return !operator==(lhs, rhs);
}
bool operator==(const GeckoCode::Code& lhs, const GeckoCode::Code& rhs)
{
return std::tie(lhs.address, lhs.data) == std::tie(rhs.address, rhs.data);
}
bool operator!=(const GeckoCode::Code& lhs, const GeckoCode::Code& rhs)
{
return !operator==(lhs, rhs);
}
// return true if a code exists
bool GeckoCode::Exist(u32 address, u32 data) const
{
@ -28,16 +49,6 @@ bool GeckoCode::Exist(u32 address, u32 data) const
}) != codes.end();
}
// return true if the code is identical
bool GeckoCode::Compare(const GeckoCode& compare) const
{
return codes.size() == compare.codes.size() &&
std::equal(codes.begin(), codes.end(), compare.codes.begin(),
[](const Code& a, const Code& b) {
return a.address == b.address && a.data == b.data;
});
}
enum class Installation
{
Uninstalled,