From 0299ab7660f8bc22d1019a3b3627b28c2d4f78fb Mon Sep 17 00:00:00 2001 From: Sacha Date: Wed, 9 Jul 2014 06:33:57 +1000 Subject: [PATCH 1/3] wxRemoval: Ini.cpp --- rpcs3/Ini.cpp | 120 ++++++++++++++------------------------------------ 1 file changed, 33 insertions(+), 87 deletions(-) diff --git a/rpcs3/Ini.cpp b/rpcs3/Ini.cpp index 6dbfa06ec4..cf85609394 100644 --- a/rpcs3/Ini.cpp +++ b/rpcs3/Ini.cpp @@ -5,6 +5,7 @@ #include #include +#include #define DEF_CONFIG_NAME "./rpcs3.ini" @@ -27,28 +28,18 @@ void saveIniFile() } std::pair rDefaultSize = { -1, -1 }; +std::pair rDefaultPosition = { -1, -1 }; Inis Ini; -static bool StringToBool(const wxString& str) +static bool StringToBool(const std::string& str) { - if ( - !str.CmpNoCase("enable") || - !str.CmpNoCase("e") || - !str.CmpNoCase("1") || - !str.CmpNoCase("true") || - !str.CmpNoCase("t")) - { - return true; - } - - return false; + return std::regex_match(str.begin(), str.end(), + std::regex("1|e|t|enable|true", std::regex_constants::icase)); } -static wxString BoolToString(const bool b) +static inline std::string BoolToString(const bool b) { - if (b) return "true"; - - return "false"; + return b ? "true" : "false"; } //takes a string of format "[number]x[number]" and returns a pair of ints @@ -56,37 +47,21 @@ static wxString BoolToString(const bool b) static std::pair StringToSize(const std::string& str) { std::pair ret; + std::sregex_token_iterator first(str.begin(), str.end(), std::regex("x"), -1), last; + std::vector vec(first, last); + if (vec.size() < 2) + return rDefaultSize; - std::string s[2] = { "", "" }; - - for (uint i = 0, a = 0; i= 2) return rDefaultSize; - continue; - } - - s[a] += str.substr(i, 1); + try { + ret.first = std::stoi(vec.at(0)); + ret.second = std::stoi(vec.at(1)); } - - if (s[0].empty() || s[1].empty()) - { + catch (const std::invalid_argument& e) { return rDefaultSize; } - try{ - ret.first = std::stoi(s[0]); - ret.first = std::stoi(s[1]); - } - catch (const std::invalid_argument &e) - { - return rDefaultSize; - } if (ret.first < 0 || ret.second < 0) - { return rDefaultSize; - } return ret; } @@ -96,35 +71,19 @@ static std::string SizeToString(const std::pair& size) return fmt::Format("%dx%d", size.first, size.second); } -static wxPoint StringToPosition(const wxString& str) +static std::pair StringToPosition(const std::string& str) { - wxPoint ret; + std::pair ret; + std::sregex_token_iterator first(str.begin(), str.end(), std::regex("x"), -1), last; + std::vector vec(first, last); + if (vec.size() < 2) + return rDefaultPosition; - wxString s[2] = { wxEmptyString, wxEmptyString }; + ret.first = std::strtol(vec.at(0).c_str(), nullptr, 10); + ret.second = std::strtol(vec.at(1).c_str(), nullptr, 10); - for (uint i = 0, a = 0; i= 2) return wxDefaultPosition; - continue; - } - - s[a] += str(i, 1); - } - - if (s[0].IsEmpty() || s[1].IsEmpty()) - { - return wxDefaultPosition; - } - - s[0].ToLong((long*)&ret.x); - s[1].ToLong((long*)&ret.y); - - if (ret.x <= 0 || ret.y <= 0) - { - return wxDefaultPosition; - } + if (ret.first <= 0 || ret.second <= 0) + return rDefaultPosition; return ret; } @@ -133,29 +92,16 @@ static WindowInfo StringToWindowInfo(const std::string& str) { WindowInfo ret = WindowInfo(rDefaultSize, rDefaultSize); - std::string s[4] = { "", "", "", "" }; - - for (uint i = 0, a = 0; i= 4) return WindowInfo::GetDefault(); - continue; - } - - s[a] += str.substr(i, 1); - } - - if (s[0].empty() || s[1].empty() || s[2].empty() || s[3].empty()) - { + std::sregex_token_iterator first(str.begin(), str.end(), std::regex("x|:"), -1), last; + std::vector vec(first, last); + if (vec.size() < 4) return WindowInfo::GetDefault(); - } try{ - ret.size.first = std::stoi(s[0]); - ret.size.second = std::stoi(s[1]); - ret.position.first = std::stoi(s[2]); - ret.position.second = std::stoi(s[3]); + ret.size.first = std::stoi(vec.at(0)); + ret.size.second = std::stoi(vec.at(1)); + ret.position.first = std::stoi(vec.at(2)); + ret.position.second = std::stoi(vec.at(3)); } catch (const std::invalid_argument &e) { @@ -246,4 +192,4 @@ WindowInfo Ini::Load(const std::string& section, const std::string& key, const W { return StringToWindowInfo(m_Config->GetValue(section.c_str(), key.c_str(), WindowInfoToString(def_value).c_str())); saveIniFile(); -} \ No newline at end of file +} From 711f9eadc5c15d40243a8f83fc7aaf4ef5407f12 Mon Sep 17 00:00:00 2001 From: Sacha Date: Thu, 10 Jul 2014 05:16:17 +1000 Subject: [PATCH 2/3] Revert some changes until GCC 4.9 is available. --- .travis.yml | 7 +++++-- rpcs3/Ini.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index bdf0fec902..4866b49c1d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,9 @@ branches: only: - master +git: + submodules: false + before_install: - echo "yes" | sudo apt-key adv --fetch-keys http://repos.codelite.org/CodeLite.asc - echo "yes" | sudo apt-add-repository 'deb http://repos.codelite.org/wx3.0/ubuntu/ precise universe' @@ -25,11 +28,11 @@ before_install: sudo ./cmake-2.8.12.1-Linux-i386.sh --skip-license --prefix=/usr; before_script: - - git submodule update --init --recursive + - git submodule update --init asmjit ffmpeg - mkdir build - cd build - cmake .. script: - - make + - make -j 4 diff --git a/rpcs3/Ini.cpp b/rpcs3/Ini.cpp index cf85609394..ac0086f543 100644 --- a/rpcs3/Ini.cpp +++ b/rpcs3/Ini.cpp @@ -47,14 +47,33 @@ static inline std::string BoolToString(const bool b) static std::pair StringToSize(const std::string& str) { std::pair ret; + +#if 1 + std::string s[2] = { "", "" }; + + for (uint i = 0, a = 0; i= 2) return rDefaultSize; + continue; + } + + s[a] += str.substr(i, 1); + } + + if (s[0].empty() || s[1].empty()) +#else + // Requires GCC 4.9 or new stdlib for Clang std::sregex_token_iterator first(str.begin(), str.end(), std::regex("x"), -1), last; - std::vector vec(first, last); + std::vector s(first, last); if (vec.size() < 2) +#endif return rDefaultSize; try { - ret.first = std::stoi(vec.at(0)); - ret.second = std::stoi(vec.at(1)); + ret.first = std::stoi(s[0]); + ret.second = std::stoi(s[1]); } catch (const std::invalid_argument& e) { return rDefaultSize; @@ -71,7 +90,8 @@ static std::string SizeToString(const std::pair& size) return fmt::Format("%dx%d", size.first, size.second); } -static std::pair StringToPosition(const std::string& str) +// Unused? +/*static std::pair StringToPosition(const std::string& str) { std::pair ret; std::sregex_token_iterator first(str.begin(), str.end(), std::regex("x"), -1), last; @@ -86,22 +106,40 @@ static std::pair StringToPosition(const std::string& str) return rDefaultPosition; return ret; -} +}*/ static WindowInfo StringToWindowInfo(const std::string& str) { WindowInfo ret = WindowInfo(rDefaultSize, rDefaultSize); +#if 1 + std::string s[4] = { "", "", "", "" }; + + for (uint i = 0, a = 0; i= 4) return WindowInfo::GetDefault(); + continue; + } + + s[a] += str.substr(i, 1); + } + + if (s[0].empty() || s[1].empty() || s[2].empty() || s[3].empty()) +#else + // Requires GCC 4.9 or new stdlib for Clang std::sregex_token_iterator first(str.begin(), str.end(), std::regex("x|:"), -1), last; - std::vector vec(first, last); + std::vector s(first, last); if (vec.size() < 4) +#endif return WindowInfo::GetDefault(); try{ - ret.size.first = std::stoi(vec.at(0)); - ret.size.second = std::stoi(vec.at(1)); - ret.position.first = std::stoi(vec.at(2)); - ret.position.second = std::stoi(vec.at(3)); + ret.size.first = std::stoi(s[0]); + ret.size.second = std::stoi(s[1]); + ret.position.first = std::stoi(s[2]); + ret.position.second = std::stoi(s[3]); } catch (const std::invalid_argument &e) { From 80dbe1a67f4c663b64475cdbe3fe0e57699aa4e0 Mon Sep 17 00:00:00 2001 From: Sacha Date: Thu, 10 Jul 2014 06:49:24 +1000 Subject: [PATCH 3/3] Use an alternative to sregex. --- rpcs3/Ini.cpp | 118 ++++++++++++-------------------------------------- 1 file changed, 27 insertions(+), 91 deletions(-) diff --git a/rpcs3/Ini.cpp b/rpcs3/Ini.cpp index ac0086f543..008be9c59d 100644 --- a/rpcs3/Ini.cpp +++ b/rpcs3/Ini.cpp @@ -27,8 +27,6 @@ void saveIniFile() getIniFile()->SaveFile(DEF_CONFIG_NAME); } -std::pair rDefaultSize = { -1, -1 }; -std::pair rDefaultPosition = { -1, -1 }; Inis Ini; static bool StringToBool(const std::string& str) @@ -46,43 +44,23 @@ static inline std::string BoolToString(const bool b) //example input would be "123x456" and the returned value would be {123,456} static std::pair StringToSize(const std::string& str) { - std::pair ret; - -#if 1 - std::string s[2] = { "", "" }; - - for (uint i = 0, a = 0; i= 2) return rDefaultSize; - continue; + std::size_t start = 0, found; + std::vector vec; + for (int i = 0; i < 2 && (found = str.find_first_of('x', start)); i++) { + try { + vec.push_back(std::stoi(str.substr(start, found == std::string::npos ? found : found - start))); } - - s[a] += str.substr(i, 1); + catch (const std::invalid_argument& e) { + return std::make_pair(-1, -1); + } + if (found == std::string::npos) + break; + start = found + 1; } + if (vec.size() < 2 || vec[0] < 0 || vec[1] < 0) + return std::make_pair(-1, -1); - if (s[0].empty() || s[1].empty()) -#else - // Requires GCC 4.9 or new stdlib for Clang - std::sregex_token_iterator first(str.begin(), str.end(), std::regex("x"), -1), last; - std::vector s(first, last); - if (vec.size() < 2) -#endif - return rDefaultSize; - - try { - ret.first = std::stoi(s[0]); - ret.second = std::stoi(s[1]); - } - catch (const std::invalid_argument& e) { - return rDefaultSize; - } - - if (ret.first < 0 || ret.second < 0) - return rDefaultSize; - - return ret; + return std::make_pair(vec[0], vec[1]); } static std::string SizeToString(const std::pair& size) @@ -90,67 +68,25 @@ static std::string SizeToString(const std::pair& size) return fmt::Format("%dx%d", size.first, size.second); } -// Unused? -/*static std::pair StringToPosition(const std::string& str) -{ - std::pair ret; - std::sregex_token_iterator first(str.begin(), str.end(), std::regex("x"), -1), last; - std::vector vec(first, last); - if (vec.size() < 2) - return rDefaultPosition; - - ret.first = std::strtol(vec.at(0).c_str(), nullptr, 10); - ret.second = std::strtol(vec.at(1).c_str(), nullptr, 10); - - if (ret.first <= 0 || ret.second <= 0) - return rDefaultPosition; - - return ret; -}*/ - static WindowInfo StringToWindowInfo(const std::string& str) { - WindowInfo ret = WindowInfo(rDefaultSize, rDefaultSize); - -#if 1 - std::string s[4] = { "", "", "", "" }; - - for (uint i = 0, a = 0; i= 4) return WindowInfo::GetDefault(); - continue; + std::size_t start = 0, found; + std::vector vec; + for (int i = 0; i < 4 && (found = str.find_first_of("x:", start)); i++) { + try { + vec.push_back(std::stoi(str.substr(start, found == std::string::npos ? found : found - start))); } - - s[a] += str.substr(i, 1); + catch (const std::invalid_argument& e) { + return WindowInfo::GetDefault(); + } + if (found == std::string::npos) + break; + start = found + 1; } - - if (s[0].empty() || s[1].empty() || s[2].empty() || s[3].empty()) -#else - // Requires GCC 4.9 or new stdlib for Clang - std::sregex_token_iterator first(str.begin(), str.end(), std::regex("x|:"), -1), last; - std::vector s(first, last); - if (vec.size() < 4) -#endif + if (vec.size() < 4 || vec[0] <= 0 || vec[1] <= 0 || vec[2] < 0 || vec[3] < 0) return WindowInfo::GetDefault(); - try{ - ret.size.first = std::stoi(s[0]); - ret.size.second = std::stoi(s[1]); - ret.position.first = std::stoi(s[2]); - ret.position.second = std::stoi(s[3]); - } - catch (const std::invalid_argument &e) - { - return WindowInfo::GetDefault(); - } - if (ret.size.first <= 0 || ret.size.second <= 0) - { - return WindowInfo::GetDefault(); - } - - return ret; + return WindowInfo(std::make_pair(vec[0], vec[1]), std::make_pair(vec[2], vec[3])); } static std::string WindowInfoToString(const WindowInfo& wind)