Skip to content

Commit

Permalink
CheatSearchTab: Use an enum for filter masks rather than ints
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbott99 committed Dec 26, 2015
1 parent 1b69743 commit ce81541
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions Source/Core/DolphinWX/Cheats/CheatSearchTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,33 @@ void CheatSearchTab::UpdateCheatSearchResultItem(long index)
m_lview_search_results->SetItem(index, 3, buf);
}

enum ComparisonMask
{
EQUAL = 0x1,
GREATER_THAN = 0x2,
LESS_THAN = 0x4
};

inline ComparisonMask operator | (ComparisonMask comp1, ComparisonMask comp2)
{
return static_cast<ComparisonMask>( static_cast<int>(comp1) |
static_cast<int>(comp2) );
}

inline ComparisonMask operator & (ComparisonMask comp1, ComparisonMask comp2)
{
return static_cast<ComparisonMask>( static_cast<int>(comp1) &
static_cast<int>(comp2) );
}

void CheatSearchTab::FilterCheatSearchResults(u32 value)
{
// Determine the selected filter
// 1 : equal
// 2 : greater-than
// 4 : less-than
// 6 : not equal
static const int filters[] = { 6, 1, 2, 4 };
int filter_mask = filters[m_search_type->GetSelection()];
static const ComparisonMask filters[] = { EQUAL | GREATER_THAN | LESS_THAN, // Unknown
GREATER_THAN | LESS_THAN, // Not Equal
EQUAL,
GREATER_THAN,
LESS_THAN };
ComparisonMask filter_mask = filters[m_search_type->GetSelection()];

std::vector<CheatSearchResult> filtered_results;
filtered_results.reserve(m_search_results.size());
Expand All @@ -268,14 +286,15 @@ void CheatSearchTab::FilterCheatSearchResults(u32 value)
{
// with big endian, can just use memcmp for ><= comparison
int cmp_result = std::memcmp(&Memory::m_pRAM[result.address], &value, m_search_type_size);
ComparisonMask cmp_mask;
if (cmp_result < 0)
cmp_result = 4;
cmp_mask = LESS_THAN;
else if (cmp_result)
cmp_result = 2;
cmp_mask = GREATER_THAN;
else
cmp_result = 1;
cmp_mask = EQUAL;

if (cmp_result & filter_mask)
if (cmp_mask & filter_mask)
{
std::memcpy(&result.old_value, &Memory::m_pRAM[result.address], m_search_type_size);
filtered_results.push_back(result);
Expand Down

0 comments on commit ce81541

Please sign in to comment.