Qt/CheatSearchWidget: Add a checkbox to force parsing a value as hexadecimal.

This commit is contained in:
Admiral H. Curtiss
2021-10-28 02:00:38 +02:00
parent b3e17d2772
commit 6e814cbb8f
4 changed files with 49 additions and 15 deletions

View File

@ -340,22 +340,31 @@ void Cheats::CheatSearchSession<T>::SetFilterType(FilterType filter_type)
}
template <typename T>
static std::optional<T> ParseValue(const std::string& str)
static std::optional<T> ParseValue(const std::string& str, bool force_parse_as_hex)
{
if (str.empty())
return std::nullopt;
T tmp;
if (TryParse(str, &tmp))
return tmp;
if constexpr (std::is_integral_v<T>)
{
if (TryParse(str, &tmp, force_parse_as_hex ? 16 : 0))
return tmp;
}
else
{
if (TryParse(str, &tmp))
return tmp;
}
return std::nullopt;
}
template <typename T>
bool Cheats::CheatSearchSession<T>::SetValueFromString(const std::string& value_as_string)
bool Cheats::CheatSearchSession<T>::SetValueFromString(const std::string& value_as_string,
bool force_parse_as_hex)
{
m_value = ParseValue<T>(value_as_string);
m_value = ParseValue<T>(value_as_string, force_parse_as_hex);
return m_value.has_value();
}
@ -498,6 +507,18 @@ bool Cheats::CheatSearchSession<T>::GetAligned()
return m_aligned;
}
template <typename T>
bool Cheats::CheatSearchSession<T>::IsIntegerType() const
{
return std::is_integral_v<T>;
}
template <typename T>
bool Cheats::CheatSearchSession<T>::IsFloatingType() const
{
return std::is_floating_point_v<T>;
}
template <typename T>
size_t Cheats::CheatSearchSession<T>::GetResultCount() const
{

View File

@ -132,7 +132,7 @@ public:
virtual void SetFilterType(FilterType filter_type) = 0;
// Set the value of the CompareAgainstSpecificValue filter used by subsequent searches.
virtual bool SetValueFromString(const std::string& value_as_string) = 0;
virtual bool SetValueFromString(const std::string& value_as_string, bool force_parse_as_hex) = 0;
// Resets the search results, causing the next search to act as a new search.
virtual void ResetResults() = 0;
@ -146,6 +146,9 @@ public:
virtual DataType GetDataType() = 0;
virtual bool GetAligned() = 0;
virtual bool IsIntegerType() const = 0;
virtual bool IsFloatingType() const = 0;
virtual size_t GetResultCount() const = 0;
virtual size_t GetValidValueCount() const = 0;
virtual u32 GetResultAddress(size_t index) const = 0;
@ -178,7 +181,7 @@ public:
void SetCompareType(CompareType compare_type) override;
void SetFilterType(FilterType filter_type) override;
bool SetValueFromString(const std::string& value_as_string) override;
bool SetValueFromString(const std::string& value_as_string, bool force_parse_as_hex) override;
void ResetResults() override;
SearchErrorCode RunSearch() override;
@ -189,6 +192,9 @@ public:
DataType GetDataType() override;
bool GetAligned() override;
bool IsIntegerType() const override;
bool IsFloatingType() const override;
size_t GetResultCount() const override;
size_t GetValidValueCount() const override;
u32 GetResultAddress(size_t index) const override;