pcsx2: Simplify Game_Data member functions

There's no need to have a lot of overloads accepting wxChar*, char* cand
const wxString&. Keep only the const wxString& versions and remove the
rest. This fixes an infinite recursion warning on FreeBSD.

Also simplify sectionExists and getSection to avoid unnecessary
conversion to and from wxString.
This commit is contained in:
Jonathan Li 2018-08-26 01:00:41 +01:00
parent 76a75efef1
commit bde62436fa
2 changed files with 11 additions and 39 deletions

View File

@ -81,7 +81,7 @@ Game_Data* BaseGameDatabaseImpl::createNewGame( const wxString& id )
}
// Searches the current game's data to see if the given key exists
bool Game_Data::keyExists(const wxChar* key) const {
bool Game_Data::keyExists(const wxString& key) const {
for (auto it = kList.begin(); it != kList.end(); ++it) {
if (it->CompareKey(key)) {
return true;
@ -91,7 +91,7 @@ bool Game_Data::keyExists(const wxChar* key) const {
}
// Gets a string representation of the 'value' for the given key
wxString Game_Data::getString(const wxChar* key) const {
wxString Game_Data::getString(const wxString& key) const {
for (auto it = kList.begin(); it != kList.end(); ++it) {
if (it->CompareKey(key)) {
return it->value;

View File

@ -84,65 +84,37 @@ struct Game_Data
kList.clear();
}
bool keyExists(const wxChar* key) const;
wxString getString(const wxChar* key) const;
bool keyExists(const wxString& key) const;
wxString getString(const wxString& key) const;
void writeString(const wxString& key, const wxString& value);
bool IsOk() const {
return !id.IsEmpty();
}
bool sectionExists(const wxChar* key, const wxString& value) const {
return keyExists(wxsFormat(L"[%s%s%s]", key, value.IsEmpty() ? L"" : L" = ", WX_STR(value)));
bool sectionExists(const wxString& key, const wxString& value) const {
return keyExists("[" + key + (value.empty() ? "" : " = ") + value + "]");
}
wxString getSection(const wxChar* key, const wxString& value) const {
return getString(wxsFormat(L"[%s%s%s]", key, value.IsEmpty() ? L"" : L" = ", WX_STR(value)).wx_str());
wxString getSection(const wxString& key, const wxString& value) const {
return getString("[" + key + (value.empty() ? "" : " = ") + value + "]");
}
// Gets an integer representation of the 'value' for the given key
int getInt(const wxChar* key) const {
int getInt(const wxString& key) const {
unsigned long val;
getString(key).ToULong(&val);
return val;
}
// Gets a u8 representation of the 'value' for the given key
u8 getU8(const wxChar* key) const {
u8 getU8(const wxString& key) const {
return (u8)wxAtoi(getString(key));
}
// Gets a bool representation of the 'value' for the given key
bool getBool(const wxChar* key) const {
return !!wxAtoi(getString(key));
}
bool keyExists(const char* key) const {
return keyExists(fromUTF8(key).wx_str());
}
bool keyExists(const wxString& key) const {
return keyExists(key.wx_str());
}
wxString getString(const char* key) const {
return getString(fromUTF8(key).wx_str());
}
int getInt(const char* key) const {
return getInt(fromUTF8(key).wx_str());
}
u8 getU8(const char* key) const {
return getU8(fromUTF8(key).wx_str());
}
bool getBool(const char* key) const {
return getBool(fromUTF8(key).wx_str());
}
bool getBool(const wxString& key) const {
return getBool(key.wx_str());
return !!wxAtoi(getString(key));
}
};