From 62a8329c33656e14e264067dcd7f340c1ffa2d66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 10 Aug 2020 14:31:31 +0200 Subject: [PATCH 1/4] Remove sstream from stringutil.h. See #13267 --- Core/Config.cpp | 1 + Core/Util/GameManager.cpp | 1 + GPU/Vulkan/PipelineManagerVulkan.cpp | 1 + Windows/MainWindowMenu.cpp | 1 + ext/native/base/stringutil.cpp | 29 ++++++++++++++++++++++++-- ext/native/base/stringutil.h | 31 +++++----------------------- ext/native/file/ini_file.cpp | 5 +++-- ext/native/file/ini_file.h | 8 +++++++ ext/native/i18n/i18n.h | 1 - ext/native/ui/ui_screen.cpp | 2 ++ 10 files changed, 49 insertions(+), 31 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index d28e9c2494..52d5e3a847 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "base/display.h" #include "base/NativeApp.h" diff --git a/Core/Util/GameManager.cpp b/Core/Util/GameManager.cpp index da0617dd43..462aa02dbf 100644 --- a/Core/Util/GameManager.cpp +++ b/Core/Util/GameManager.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "file/file_util.h" #ifdef SHARED_LIBZIP diff --git a/GPU/Vulkan/PipelineManagerVulkan.cpp b/GPU/Vulkan/PipelineManagerVulkan.cpp index e8898c144b..9986f1a523 100644 --- a/GPU/Vulkan/PipelineManagerVulkan.cpp +++ b/GPU/Vulkan/PipelineManagerVulkan.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "profiler/profiler.h" diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index 03296a8f28..1533e21d5d 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "CommonWindows.h" #include diff --git a/ext/native/base/stringutil.cpp b/ext/native/base/stringutil.cpp index 2861f844d3..3b42400c88 100644 --- a/ext/native/base/stringutil.cpp +++ b/ext/native/base/stringutil.cpp @@ -8,8 +8,8 @@ #define _GNU_SOURCE #include #endif -#include -#include +#include +#include #include #include #include @@ -240,6 +240,7 @@ bool TryParse(const std::string &str, uint32_t *const output) if (errno == ERANGE) return false; + // Range check if (ULONG_MAX > UINT_MAX) { #ifdef _MSC_VER #pragma warning (disable:4309) @@ -266,6 +267,30 @@ bool TryParse(const std::string &str, bool *const output) return true; } +template +bool TryParseImpl(const std::string &str, N *const output) { + std::istringstream iss(str); + N tmp = 0; + if (iss >> tmp) { + *output = tmp; + return true; + } else { + return false; + } +} + +bool TryParse(const std::string &str, int32_t *const output) { + return TryParseImpl(str, output); +} + +bool TryParse(const std::string &str, float *const output) { + return TryParseImpl(str, output); +} + +bool TryParse(const std::string &str, double *const output) { + return TryParseImpl(str, output); +} + void SplitString(const std::string& str, const char delim, std::vector& output) { size_t next = 0; diff --git a/ext/native/base/stringutil.h b/ext/native/base/stringutil.h index c16602946f..255b588322 100644 --- a/ext/native/base/stringutil.h +++ b/ext/native/base/stringutil.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include "base/basictypes.h" @@ -37,7 +36,7 @@ inline bool startsWith(const std::string &str, const std::string &what) { inline bool endsWith(const std::string &str, const std::string &what) { if (str.size() < what.size()) return false; - return str.substr(str.size() - what.size()) == what; + return str.substr(str.size() - what.size()) == what; } // Only use on strings where you're only concerned about ASCII. @@ -56,10 +55,9 @@ inline bool endsWithNoCase(const std::string &str, const std::string &what) { void DataToHexString(const uint8_t *data, size_t size, std::string *output); inline void StringToHexString(const std::string &data, std::string *output) { - DataToHexString((uint8_t *)(&data[0]), data.size(), output); + DataToHexString((uint8_t *)(&data[0]), data.size(), output); } - // highly unsafe and not recommended. unsigned int parseHex(const char* _szValue); @@ -74,21 +72,10 @@ std::string StripQuotes(const std::string &s); bool TryParse(const std::string &str, bool *const output); bool TryParse(const std::string &str, uint32_t *const output); +bool TryParse(const std::string &str, int32_t *const output); +bool TryParse(const std::string &str, float *const output); +bool TryParse(const std::string &str, double *const output); -template -static bool TryParse(const std::string &str, N *const output) -{ - std::istringstream iss(str); - - N tmp = 0; - if (iss >> tmp) - { - *output = tmp; - return true; - } - else - return false; -} void SplitString(const std::string& str, const char delim, std::vector& output); void GetQuotedStrings(const std::string& str, std::vector& output); @@ -98,14 +85,6 @@ std::string ReplaceAll(std::string input, const std::string& src, const std::str // Compare two strings, ignore the difference between the ignorestr1 and the ignorestr2 in str1 and str2. int strcmpIgnore(std::string str1, std::string str2, std::string ignorestr1, std::string ignorestr2); -template -static std::string ValueToString(const N value) -{ - std::stringstream string; - string << value; - return string.str(); -} - void StringTrimEndNonAlphaNum(char *str); void SkipSpace(const char **ptr); void StringUpper(char *str); diff --git a/ext/native/file/ini_file.cpp b/ext/native/file/ini_file.cpp index 99bdcd163a..79a9f3ff8f 100644 --- a/ext/native/file/ini_file.cpp +++ b/ext/native/file/ini_file.cpp @@ -2,8 +2,8 @@ // Taken from Dolphin but relicensed by me, Henrik Rydgard, under the MIT // license as I wrote the whole thing originally and it has barely changed. -#include -#include +#include +#include #ifndef _MSC_VER #include @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "base/logging.h" diff --git a/ext/native/file/ini_file.h b/ext/native/file/ini_file.h index ba63ab1ab5..1c8d1e3976 100644 --- a/ext/native/file/ini_file.h +++ b/ext/native/file/ini_file.h @@ -10,6 +10,14 @@ #include "base/stringutil.h" +template +inline std::string ValueToString(const N value) +{ + std::stringstream string; + string << value; + return string.str(); +} + class IniFile { public: diff --git a/ext/native/i18n/i18n.h b/ext/native/i18n/i18n.h index 75d8ddd776..cdffed3a29 100644 --- a/ext/native/i18n/i18n.h +++ b/ext/native/i18n/i18n.h @@ -9,7 +9,6 @@ // As usual, everything is UTF-8. Nothing else allowed. #include -#include #include #include #include diff --git a/ext/native/ui/ui_screen.cpp b/ext/native/ui/ui_screen.cpp index e2dba2cf60..3bfa8dcfe1 100644 --- a/ext/native/ui/ui_screen.cpp +++ b/ext/native/ui/ui_screen.cpp @@ -1,5 +1,7 @@ #include #include +#include + #include "base/display.h" #include "input/input_state.h" #include "input/keycodes.h" From d70dcaf53ab3af80cb651a0be2d421b08c907904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 10 Aug 2020 15:29:10 +0200 Subject: [PATCH 2/4] Buildfix --- ext/native/file/ini_file.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/native/file/ini_file.h b/ext/native/file/ini_file.h index 1c8d1e3976..62029c00e2 100644 --- a/ext/native/file/ini_file.h +++ b/ext/native/file/ini_file.h @@ -104,14 +104,14 @@ public: for(size_t i = 0; i < temp.size(); i++) { std::vector key_val; - SplitString(temp[i],'_',key_val); - if(key_val.size() < 2) + SplitString(temp[i], '_', key_val); + if (key_val.size() < 2) continue; U mapKey; V mapValue; - if(!TryParse(key_val[0],&mapKey)) + if (!TryParse(key_val[0], &mapKey)) continue; - if(!TryParse(key_val[1],&mapValue)) + if (!TryParse(key_val[1], &mapValue)) continue; values[mapKey] = mapValue; } From 72d5b29434f55d63617c62558ccc5ff3e86deb19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 10 Aug 2020 15:46:21 +0200 Subject: [PATCH 3/4] Can't avoid sstream in ini_file.h, it seems. --- ext/native/file/ini_file.h | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/native/file/ini_file.h b/ext/native/file/ini_file.h index 62029c00e2..98afb66248 100644 --- a/ext/native/file/ini_file.h +++ b/ext/native/file/ini_file.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "base/stringutil.h" From 5ec2da0f2dfe1b30de89221420546772d07be92a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 10 Aug 2020 15:53:52 +0200 Subject: [PATCH 4/4] Move Section out of IniFile so it can be forward declared. Unlocked further improvements to build speed. --- Common/ArmCPUDetect.cpp | 3 + Common/KeyMap.cpp | 4 +- Common/LogManager.cpp | 4 +- Common/LogManager.h | 4 +- Core/Config.cpp | 42 ++--- Core/Dialog/PSPSaveDialog.cpp | 1 + Core/FileSystems/DirectoryFileSystem.cpp | 2 + Core/SaveState.cpp | 1 + Core/Util/GameManager.cpp | 1 + GPU/Common/PostShader.cpp | 2 +- UI/CwCheatScreen.cpp | 1 + UI/PauseScreen.cpp | 2 + UI/RemoteISOScreen.cpp | 1 + UI/ReportScreen.cpp | 2 + UI/SavedataScreen.cpp | 1 + ext/native/file/ini_file.cpp | 44 ++--- ext/native/file/ini_file.h | 222 +++++++++++------------ ext/native/i18n/i18n.cpp | 8 +- ext/native/i18n/i18n.h | 10 +- ext/native/ui/ui_screen.cpp | 1 + 20 files changed, 186 insertions(+), 170 deletions(-) diff --git a/Common/ArmCPUDetect.cpp b/Common/ArmCPUDetect.cpp index da8d45f2f9..90aeaf8433 100644 --- a/Common/ArmCPUDetect.cpp +++ b/Common/ArmCPUDetect.cpp @@ -16,6 +16,9 @@ // http://code.google.com/p/dolphin-emu/ #include "ppsspp_config.h" + +#include + #if PPSSPP_ARCH(ARM) || PPSSPP_ARCH(ARM64) #include diff --git a/Common/KeyMap.cpp b/Common/KeyMap.cpp index b7091b537a..d67c06c056 100644 --- a/Common/KeyMap.cpp +++ b/Common/KeyMap.cpp @@ -916,7 +916,7 @@ void LoadFromIni(IniFile &file) { return; } - IniFile::Section *controls = file.GetOrCreateSection("ControlMapping"); + Section *controls = file.GetOrCreateSection("ControlMapping"); for (size_t i = 0; i < ARRAY_SIZE(psp_button_names); i++) { std::string value; controls->Get(psp_button_names[i].name, &value, ""); @@ -943,7 +943,7 @@ void LoadFromIni(IniFile &file) { } void SaveToIni(IniFile &file) { - IniFile::Section *controls = file.GetOrCreateSection("ControlMapping"); + Section *controls = file.GetOrCreateSection("ControlMapping"); for (size_t i = 0; i < ARRAY_SIZE(psp_button_names); i++) { std::vector keys; diff --git a/Common/LogManager.cpp b/Common/LogManager.cpp index 485a7b47da..c13a3d712f 100644 --- a/Common/LogManager.cpp +++ b/Common/LogManager.cpp @@ -185,14 +185,14 @@ void LogManager::ChangeFileLog(const char *filename) { } } -void LogManager::SaveConfig(IniFile::Section *section) { +void LogManager::SaveConfig(Section *section) { for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) { section->Set((std::string(log_[i].m_shortName) + "Enabled").c_str(), log_[i].enabled); section->Set((std::string(log_[i].m_shortName) + "Level").c_str(), (int)log_[i].level); } } -void LogManager::LoadConfig(IniFile::Section *section, bool debugDefaults) { +void LogManager::LoadConfig(Section *section, bool debugDefaults) { for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) { bool enabled = false; int level = 0; diff --git a/Common/LogManager.h b/Common/LogManager.h index 81a23d518d..a9d5a568e9 100644 --- a/Common/LogManager.h +++ b/Common/LogManager.h @@ -180,6 +180,6 @@ public: void ChangeFileLog(const char *filename); - void SaveConfig(IniFile::Section *section); - void LoadConfig(IniFile::Section *section, bool debugDefaults); + void SaveConfig(Section *section); + void LoadConfig(Section *section, bool debugDefaults); }; diff --git a/Core/Config.cpp b/Core/Config.cpp index 52d5e3a847..f7fd8e9af9 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -203,7 +203,7 @@ struct ConfigSetting { return type_ != TYPE_TERMINATOR; } - bool Get(IniFile::Section *section) { + bool Get(Section *section) { switch (type_) { case TYPE_BOOL: if (cb_.b) { @@ -256,7 +256,7 @@ struct ConfigSetting { } } - void Set(IniFile::Section *section) { + void Set(Section *section) { if (!save_) return; @@ -1108,9 +1108,9 @@ static ConfigSectionSettings sections[] = { {"Theme", themeSettings}, }; -static void IterateSettings(IniFile &iniFile, std::function func) { +static void IterateSettings(IniFile &iniFile, std::function func) { for (size_t i = 0; i < ARRAY_SIZE(sections); ++i) { - IniFile::Section *section = iniFile.GetOrCreateSection(sections[i].section); + Section *section = iniFile.GetOrCreateSection(sections[i].section); for (auto setting = sections[i].settings; setting->HasMore(); ++setting) { func(section, setting); } @@ -1147,8 +1147,8 @@ std::map> GetLangValuesMapping() { langCodeMapping["CHINESE_TRADITIONAL"] = PSP_SYSTEMPARAM_LANGUAGE_CHINESE_TRADITIONAL; langCodeMapping["CHINESE_SIMPLIFIED"] = PSP_SYSTEMPARAM_LANGUAGE_CHINESE_SIMPLIFIED; - IniFile::Section *langRegionNames = mapping.GetOrCreateSection("LangRegionNames"); - IniFile::Section *systemLanguage = mapping.GetOrCreateSection("SystemLanguage"); + Section *langRegionNames = mapping.GetOrCreateSection("LangRegionNames"); + Section *systemLanguage = mapping.GetOrCreateSection("SystemLanguage"); for (size_t i = 0; i < keys.size(); i++) { std::string langName; @@ -1187,7 +1187,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { // Continue anyway to initialize the config. } - IterateSettings(iniFile, [](IniFile::Section *section, ConfigSetting *setting) { + IterateSettings(iniFile, [](Section *section, ConfigSetting *setting) { setting->Get(section); }); @@ -1195,7 +1195,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { if (!File::Exists(currentDirectory)) currentDirectory = ""; - IniFile::Section *log = iniFile.GetOrCreateSection(logSectionName); + Section *log = iniFile.GetOrCreateSection(logSectionName); bool debugDefaults = false; #ifdef _DEBUG @@ -1203,7 +1203,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { #endif LogManager::GetInstance()->LoadConfig(log, debugDefaults); - IniFile::Section *recent = iniFile.GetOrCreateSection("Recent"); + Section *recent = iniFile.GetOrCreateSection("Recent"); recent->Get("MaxRecent", &iMaxRecent, 30); // Fix issue from switching from uint (hex in .ini) to int (dec) @@ -1249,7 +1249,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { } // Check for an old dpad setting - IniFile::Section *control = iniFile.GetOrCreateSection("Control"); + Section *control = iniFile.GetOrCreateSection("Control"); float f; control->Get("DPadRadius", &f, 0.0f); if (f > 0.0f) { @@ -1338,13 +1338,13 @@ void Config::Save(const char *saveReason) { // Need to do this somewhere... bFirstRun = false; - IterateSettings(iniFile, [&](IniFile::Section *section, ConfigSetting *setting) { + IterateSettings(iniFile, [&](Section *section, ConfigSetting *setting) { if (!bGameSpecific || !setting->perGame_) { setting->Set(section); } }); - IniFile::Section *recent = iniFile.GetOrCreateSection("Recent"); + Section *recent = iniFile.GetOrCreateSection("Recent"); recent->Set("MaxRecent", iMaxRecent); for (int i = 0; i < iMaxRecent; i++) { @@ -1357,7 +1357,7 @@ void Config::Save(const char *saveReason) { } } - IniFile::Section *pinnedPaths = iniFile.GetOrCreateSection("PinnedPaths"); + Section *pinnedPaths = iniFile.GetOrCreateSection("PinnedPaths"); pinnedPaths->Clear(); for (size_t i = 0; i < vPinnedPaths.size(); ++i) { char keyName[64]; @@ -1366,17 +1366,17 @@ void Config::Save(const char *saveReason) { } if (!bGameSpecific) { - IniFile::Section *postShaderSetting = iniFile.GetOrCreateSection("PostShaderSetting"); + Section *postShaderSetting = iniFile.GetOrCreateSection("PostShaderSetting"); postShaderSetting->Clear(); for (auto it = mPostShaderSetting.begin(), end = mPostShaderSetting.end(); it != end; ++it) { postShaderSetting->Set(it->first.c_str(), it->second); } } - IniFile::Section *control = iniFile.GetOrCreateSection("Control"); + Section *control = iniFile.GetOrCreateSection("Control"); control->Delete("DPadRadius"); - IniFile::Section *log = iniFile.GetOrCreateSection(logSectionName); + Section *log = iniFile.GetOrCreateSection(logSectionName); if (LogManager::GetInstance()) LogManager::GetInstance()->SaveConfig(log); @@ -1614,16 +1614,16 @@ bool Config::saveGameConfig(const std::string &pGameId, const std::string &title IniFile iniFile; - IniFile::Section *top = iniFile.GetOrCreateSection(""); + Section *top = iniFile.GetOrCreateSection(""); top->AddComment(StringFromFormat("Game config for %s - %s", pGameId.c_str(), title.c_str())); - IterateSettings(iniFile, [](IniFile::Section *section, ConfigSetting *setting) { + IterateSettings(iniFile, [](Section *section, ConfigSetting *setting) { if (setting->perGame_) { setting->Set(section); } }); - IniFile::Section *postShaderSetting = iniFile.GetOrCreateSection("PostShaderSetting"); + Section *postShaderSetting = iniFile.GetOrCreateSection("PostShaderSetting"); postShaderSetting->Clear(); for (auto it = mPostShaderSetting.begin(), end = mPostShaderSetting.end(); it != end; ++it) { postShaderSetting->Set(it->first.c_str(), it->second); @@ -1653,7 +1653,7 @@ bool Config::loadGameConfig(const std::string &pGameId, const std::string &title mPostShaderSetting[it.first] = std::stof(it.second); } - IterateSettings(iniFile, [](IniFile::Section *section, ConfigSetting *setting) { + IterateSettings(iniFile, [](Section *section, ConfigSetting *setting) { if (setting->perGame_) { setting->Get(section); } @@ -1671,7 +1671,7 @@ void Config::unloadGameConfig() { iniFile.Load(iniFilename_); // Reload game specific settings back to standard. - IterateSettings(iniFile, [](IniFile::Section *section, ConfigSetting *setting) { + IterateSettings(iniFile, [](Section *section, ConfigSetting *setting) { if (setting->perGame_) { setting->Get(section); } diff --git a/Core/Dialog/PSPSaveDialog.cpp b/Core/Dialog/PSPSaveDialog.cpp index 80b4f7c6e1..1e58737c2a 100755 --- a/Core/Dialog/PSPSaveDialog.cpp +++ b/Core/Dialog/PSPSaveDialog.cpp @@ -21,6 +21,7 @@ #include +#include "base/stringutil.h" #include "i18n/i18n.h" #include "thread/threadutil.h" diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index 7edb316eef..ece079445e 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -19,6 +19,8 @@ #include #include + +#include "base/stringutil.h" #include "file/free.h" #include "file/zip_read.h" #include "i18n/i18n.h" diff --git a/Core/SaveState.cpp b/Core/SaveState.cpp index 19a78cc6ac..42ec9b289b 100644 --- a/Core/SaveState.cpp +++ b/Core/SaveState.cpp @@ -21,6 +21,7 @@ #include #include "base/timeutil.h" +#include "base/stringutil.h" #include "i18n/i18n.h" #include "thread/threadutil.h" #include "util/text/parsers.h" diff --git a/Core/Util/GameManager.cpp b/Core/Util/GameManager.cpp index 462aa02dbf..448a63f177 100644 --- a/Core/Util/GameManager.cpp +++ b/Core/Util/GameManager.cpp @@ -30,6 +30,7 @@ #include "ext/libzip/zip.h" #endif #include "util/text/utf8.h" +#include "file/ini_file.h" #include "Common/Log.h" #include "Common/FileUtil.h" diff --git a/GPU/Common/PostShader.cpp b/GPU/Common/PostShader.cpp index 5c24d48ee3..57eaf1f50d 100644 --- a/GPU/Common/PostShader.cpp +++ b/GPU/Common/PostShader.cpp @@ -103,7 +103,7 @@ void LoadPostShaderInfo(const std::vector &directories) { // Alright, let's loop through the sections and see if any is a shader. for (size_t i = 0; i < ini.Sections().size(); i++) { - IniFile::Section §ion = ini.Sections()[i]; + Section §ion = ini.Sections()[i]; std::string shaderType; section.Get("Type", &shaderType, "render"); diff --git a/UI/CwCheatScreen.cpp b/UI/CwCheatScreen.cpp index c36056b273..dad1ac5861 100644 --- a/UI/CwCheatScreen.cpp +++ b/UI/CwCheatScreen.cpp @@ -15,6 +15,7 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include "base/stringutil.h" #include "ext/cityhash/city.h" #include "i18n/i18n.h" #include "ui/ui.h" diff --git a/UI/PauseScreen.cpp b/UI/PauseScreen.cpp index 59769a01c7..4e388dd2a2 100644 --- a/UI/PauseScreen.cpp +++ b/UI/PauseScreen.cpp @@ -17,6 +17,8 @@ #include #include + +#include "base/stringutil.h" #include "i18n/i18n.h" #include "gfx_es2/draw_buffer.h" #include "ui/view.h" diff --git a/UI/RemoteISOScreen.cpp b/UI/RemoteISOScreen.cpp index 9f0930f77d..8029c39671 100644 --- a/UI/RemoteISOScreen.cpp +++ b/UI/RemoteISOScreen.cpp @@ -25,6 +25,7 @@ #include #endif +#include "base/stringutil.h" #include "base/timeutil.h" #include "file/path.h" // TODO: For text align flags, probably shouldn't be in gfx_es2/... diff --git a/UI/ReportScreen.cpp b/UI/ReportScreen.cpp index 96ba662c6f..f214ba9dfd 100644 --- a/UI/ReportScreen.cpp +++ b/UI/ReportScreen.cpp @@ -16,7 +16,9 @@ // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #include + #include "base/display.h" +#include "base/stringutil.h" // TODO: For text align flags, probably shouldn't be in gfx_es2/... #include "gfx_es2/draw_buffer.h" #include "i18n/i18n.h" diff --git a/UI/SavedataScreen.cpp b/UI/SavedataScreen.cpp index 5ec73aa9ca..3771796629 100644 --- a/UI/SavedataScreen.cpp +++ b/UI/SavedataScreen.cpp @@ -20,6 +20,7 @@ #include "base/colorutil.h" #include "base/timeutil.h" +#include "base/stringutil.h" #include "gfx_es2/draw_buffer.h" #include "i18n/i18n.h" #include "math/curves.h" diff --git a/ext/native/file/ini_file.cpp b/ext/native/file/ini_file.cpp index 79a9f3ff8f..048116aeba 100644 --- a/ext/native/file/ini_file.cpp +++ b/ext/native/file/ini_file.cpp @@ -149,11 +149,11 @@ static std::string EscapeComments(const std::string &value) { return result; } -void IniFile::Section::Clear() { +void Section::Clear() { lines.clear(); } -std::string* IniFile::Section::GetLine(const char* key, std::string* valueOut, std::string* commentOut) +std::string* Section::GetLine(const char* key, std::string* valueOut, std::string* commentOut) { for (std::vector::iterator iter = lines.begin(); iter != lines.end(); ++iter) { @@ -166,7 +166,7 @@ std::string* IniFile::Section::GetLine(const char* key, std::string* valueOut, s return 0; } -void IniFile::Section::Set(const char* key, const char* newValue) +void Section::Set(const char* key, const char* newValue) { std::string value, commented; std::string* line = GetLine(key, &value, &commented); @@ -182,7 +182,7 @@ void IniFile::Section::Set(const char* key, const char* newValue) } } -void IniFile::Section::Set(const char* key, const std::string& newValue, const std::string& defaultValue) +void Section::Set(const char* key, const std::string& newValue, const std::string& defaultValue) { if (newValue != defaultValue) Set(key, newValue); @@ -190,7 +190,7 @@ void IniFile::Section::Set(const char* key, const std::string& newValue, const s Delete(key); } -bool IniFile::Section::Get(const char* key, std::string* value, const char* defaultValue) +bool Section::Get(const char* key, std::string* value, const char* defaultValue) { const std::string* line = GetLine(key, value, 0); if (!line) @@ -204,7 +204,7 @@ bool IniFile::Section::Get(const char* key, std::string* value, const char* defa return true; } -void IniFile::Section::Set(const char* key, const float newValue, const float defaultValue) +void Section::Set(const char* key, const float newValue, const float defaultValue) { if (newValue != defaultValue) Set(key, newValue); @@ -212,7 +212,7 @@ void IniFile::Section::Set(const char* key, const float newValue, const float de Delete(key); } -void IniFile::Section::Set(const char* key, int newValue, int defaultValue) +void Section::Set(const char* key, int newValue, int defaultValue) { if (newValue != defaultValue) Set(key, newValue); @@ -220,7 +220,7 @@ void IniFile::Section::Set(const char* key, int newValue, int defaultValue) Delete(key); } -void IniFile::Section::Set(const char* key, bool newValue, bool defaultValue) +void Section::Set(const char* key, bool newValue, bool defaultValue) { if (newValue != defaultValue) Set(key, newValue); @@ -228,7 +228,7 @@ void IniFile::Section::Set(const char* key, bool newValue, bool defaultValue) Delete(key); } -void IniFile::Section::Set(const char* key, const std::vector& newValues) +void Section::Set(const char* key, const std::vector& newValues) { std::string temp; // Join the strings with , @@ -243,11 +243,11 @@ void IniFile::Section::Set(const char* key, const std::vector& newV Set(key, temp.c_str()); } -void IniFile::Section::AddComment(const std::string &comment) { +void Section::AddComment(const std::string &comment) { lines.push_back("# " + comment); } -bool IniFile::Section::Get(const char* key, std::vector& values) +bool Section::Get(const char* key, std::vector& values) { std::string temp; bool retval = Get(key, &temp, 0); @@ -275,7 +275,7 @@ bool IniFile::Section::Get(const char* key, std::vector& values) return true; } -bool IniFile::Section::Get(const char* key, int* value, int defaultValue) +bool Section::Get(const char* key, int* value, int defaultValue) { std::string temp; bool retval = Get(key, &temp, 0); @@ -285,7 +285,7 @@ bool IniFile::Section::Get(const char* key, int* value, int defaultValue) return false; } -bool IniFile::Section::Get(const char* key, uint32_t* value, uint32_t defaultValue) +bool Section::Get(const char* key, uint32_t* value, uint32_t defaultValue) { std::string temp; bool retval = Get(key, &temp, 0); @@ -295,7 +295,7 @@ bool IniFile::Section::Get(const char* key, uint32_t* value, uint32_t defaultVal return false; } -bool IniFile::Section::Get(const char* key, bool* value, bool defaultValue) +bool Section::Get(const char* key, bool* value, bool defaultValue) { std::string temp; bool retval = Get(key, &temp, 0); @@ -305,7 +305,7 @@ bool IniFile::Section::Get(const char* key, bool* value, bool defaultValue) return false; } -bool IniFile::Section::Get(const char* key, float* value, float defaultValue) +bool Section::Get(const char* key, float* value, float defaultValue) { std::string temp; bool retval = Get(key, &temp, 0); @@ -315,7 +315,7 @@ bool IniFile::Section::Get(const char* key, float* value, float defaultValue) return false; } -bool IniFile::Section::Get(const char* key, double* value, double defaultValue) +bool Section::Get(const char* key, double* value, double defaultValue) { std::string temp; bool retval = Get(key, &temp, 0); @@ -325,7 +325,7 @@ bool IniFile::Section::Get(const char* key, double* value, double defaultValue) return false; } -bool IniFile::Section::Exists(const char *key) const +bool Section::Exists(const char *key) const { for (std::vector::const_iterator iter = lines.begin(); iter != lines.end(); ++iter) { @@ -337,7 +337,7 @@ bool IniFile::Section::Exists(const char *key) const return false; } -std::map IniFile::Section::ToMap() const +std::map Section::ToMap() const { std::map outMap; for (std::vector::const_iterator iter = lines.begin(); iter != lines.end(); ++iter) @@ -351,7 +351,7 @@ std::map IniFile::Section::ToMap() const } -bool IniFile::Section::Delete(const char *key) +bool Section::Delete(const char *key) { std::string* line = GetLine(key, 0, 0); for (std::vector::iterator liter = lines.begin(); liter != lines.end(); ++liter) @@ -367,7 +367,7 @@ bool IniFile::Section::Delete(const char *key) // IniFile -const IniFile::Section* IniFile::GetSection(const char* sectionName) const +const Section* IniFile::GetSection(const char* sectionName) const { for (std::vector
::const_iterator iter = sections.begin(); iter != sections.end(); ++iter) if (!strcasecmp(iter->name().c_str(), sectionName)) @@ -375,7 +375,7 @@ const IniFile::Section* IniFile::GetSection(const char* sectionName) const return 0; } -IniFile::Section* IniFile::GetSection(const char* sectionName) +Section* IniFile::GetSection(const char* sectionName) { for (std::vector
::iterator iter = sections.begin(); iter != sections.end(); ++iter) if (!strcasecmp(iter->name().c_str(), sectionName)) @@ -383,7 +383,7 @@ IniFile::Section* IniFile::GetSection(const char* sectionName) return 0; } -IniFile::Section* IniFile::GetOrCreateSection(const char* sectionName) +Section* IniFile::GetOrCreateSection(const char* sectionName) { Section* section = GetSection(sectionName); if (!section) diff --git a/ext/native/file/ini_file.h b/ext/native/file/ini_file.h index 98afb66248..83e02d4144 100644 --- a/ext/native/file/ini_file.h +++ b/ext/native/file/ini_file.h @@ -19,120 +19,120 @@ inline std::string ValueToString(const N value) return string.str(); } +class Section +{ + friend class IniFile; + +public: + Section() {} + Section(const std::string& name) : name_(name) {} + + bool Exists(const char *key) const; + bool Delete(const char *key); + + void Clear(); + + std::map ToMap() const; + + std::string* GetLine(const char* key, std::string* valueOut, std::string* commentOut); + void Set(const char* key, const char* newValue); + void Set(const char* key, const std::string& newValue, const std::string& defaultValue); + + void Set(const std::string &key, const std::string &value) { + Set(key.c_str(), value.c_str()); + } + bool Get(const char* key, std::string* value, const char* defaultValue); + + void Set(const char* key, uint32_t newValue) { + Set(key, StringFromFormat("0x%08x", newValue).c_str()); + } + void Set(const char* key, float newValue) { + Set(key, StringFromFormat("%f", newValue).c_str()); + } + void Set(const char* key, const float newValue, const float defaultValue); + void Set(const char* key, double newValue) { + Set(key, StringFromFormat("%f", newValue).c_str()); + } + + void Set(const char* key, int newValue, int defaultValue); + void Set(const char* key, int newValue) { + Set(key, StringFromInt(newValue).c_str()); + } + + void Set(const char* key, bool newValue, bool defaultValue); + void Set(const char* key, bool newValue) { + Set(key, StringFromBool(newValue).c_str()); + } + void Set(const char* key, const std::vector& newValues); + + template + void Set(const char* key, const std::map& newValues) + { + std::vector temp; + for (typename std::map::const_iterator it = newValues.begin(); it != newValues.end(); it++) + { + temp.push_back(ValueToString(it->first) + "_" + ValueToString(it->second)); + } + Set(key, temp); + } + + // Declare without a body to make it fail to compile. This is to prevent accidentally + // setting a pointer as a bool. The failure is in the linker unfortunately, but that's better + // than accidentally succeeding in a bad way. + template + void Set(const char *key, T *ptr); + + void AddComment(const std::string &comment); + + bool Get(const char* key, int* value, int defaultValue = 0); + bool Get(const char* key, uint32_t* value, uint32_t defaultValue = 0); + bool Get(const char* key, bool* value, bool defaultValue = false); + bool Get(const char* key, float* value, float defaultValue = false); + bool Get(const char* key, double* value, double defaultValue = false); + bool Get(const char* key, std::vector& values); + template + bool Get(const char* key, std::map& values) + { + std::vector temp; + if (!Get(key, temp)) + { + return false; + } + values.clear(); + for (size_t i = 0; i < temp.size(); i++) + { + std::vector key_val; + SplitString(temp[i], '_', key_val); + if (key_val.size() < 2) + continue; + U mapKey; + V mapValue; + if (!TryParse(key_val[0], &mapKey)) + continue; + if (!TryParse(key_val[1], &mapValue)) + continue; + values[mapKey] = mapValue; + } + return true; + } + + bool operator < (const Section& other) const { + return name_ < other.name_; + } + + const std::string &name() const { + return name_; + } + +protected: + std::vector lines; + std::string name_; + std::string comment; +}; + class IniFile { public: - class Section - { - friend class IniFile; - - public: - Section() {} - Section(const std::string& name) : name_(name) {} - - bool Exists(const char *key) const; - bool Delete(const char *key); - - void Clear(); - - std::map ToMap() const; - - std::string* GetLine(const char* key, std::string* valueOut, std::string* commentOut); - void Set(const char* key, const char* newValue); - void Set(const char* key, const std::string& newValue, const std::string& defaultValue); - - void Set(const std::string &key, const std::string &value) { - Set(key.c_str(), value.c_str()); - } - bool Get(const char* key, std::string* value, const char* defaultValue); - - void Set(const char* key, uint32_t newValue) { - Set(key, StringFromFormat("0x%08x", newValue).c_str()); - } - void Set(const char* key, float newValue) { - Set(key, StringFromFormat("%f", newValue).c_str()); - } - void Set(const char* key, const float newValue, const float defaultValue); - void Set(const char* key, double newValue) { - Set(key, StringFromFormat("%f", newValue).c_str()); - } - - void Set(const char* key, int newValue, int defaultValue); - void Set(const char* key, int newValue) { - Set(key, StringFromInt(newValue).c_str()); - } - - void Set(const char* key, bool newValue, bool defaultValue); - void Set(const char* key, bool newValue) { - Set(key, StringFromBool(newValue).c_str()); - } - void Set(const char* key, const std::vector& newValues); - - template - void Set(const char* key, const std::map& newValues) - { - std::vector temp; - for(typename std::map::const_iterator it = newValues.begin(); it != newValues.end(); it++) - { - temp.push_back(ValueToString(it->first)+"_"+ValueToString(it->second)); - } - Set(key,temp); - } - - // Declare without a body to make it fail to compile. This is to prevent accidentally - // setting a pointer as a bool. The failure is in the linker unfortunately, but that's better - // than accidentally succeeding in a bad way. - template - void Set(const char *key, T *ptr); - - void AddComment(const std::string &comment); - - bool Get(const char* key, int* value, int defaultValue = 0); - bool Get(const char* key, uint32_t* value, uint32_t defaultValue = 0); - bool Get(const char* key, bool* value, bool defaultValue = false); - bool Get(const char* key, float* value, float defaultValue = false); - bool Get(const char* key, double* value, double defaultValue = false); - bool Get(const char* key, std::vector& values); - template - bool Get(const char* key, std::map& values) - { - std::vector temp; - if(!Get(key,temp)) - { - return false; - } - values.clear(); - for(size_t i = 0; i < temp.size(); i++) - { - std::vector key_val; - SplitString(temp[i], '_', key_val); - if (key_val.size() < 2) - continue; - U mapKey; - V mapValue; - if (!TryParse(key_val[0], &mapKey)) - continue; - if (!TryParse(key_val[1], &mapValue)) - continue; - values[mapKey] = mapValue; - } - return true; - } - - bool operator < (const Section& other) const { - return name_ < other.name_; - } - - const std::string &name() const { - return name_; - } - - protected: - std::vector lines; - std::string name_; - std::string comment; - }; - bool Load(const char* filename); bool Load(const std::string &filename) { return Load(filename.c_str()); } bool Load(std::istream &istream); diff --git a/ext/native/i18n/i18n.cpp b/ext/native/i18n/i18n.cpp index eb823dc2b9..a77111361d 100644 --- a/ext/native/i18n/i18n.cpp +++ b/ext/native/i18n/i18n.cpp @@ -95,7 +95,7 @@ bool I18NRepo::LoadIni(const std::string &languageID, const std::string &overrid Clear(); - const std::vector §ions = ini.Sections(); + const std::vector
§ions = ini.Sections(); std::lock_guard guard(catsLock_); for (auto iter = sections.begin(); iter != sections.end(); ++iter) { @@ -108,7 +108,7 @@ bool I18NRepo::LoadIni(const std::string &languageID, const std::string &overrid return true; } -I18NCategory *I18NRepo::LoadSection(const IniFile::Section *section, const char *name) { +I18NCategory *I18NRepo::LoadSection(const Section *section, const char *name) { I18NCategory *cat = new I18NCategory(this, name); std::map sectionMap = section->ToMap(); cat->SetMap(sectionMap); @@ -123,13 +123,13 @@ void I18NRepo::SaveIni(const std::string &languageID) { std::lock_guard guard(catsLock_); for (auto iter = cats_.begin(); iter != cats_.end(); ++iter) { std::string categoryName = iter->first; - IniFile::Section *section = ini.GetOrCreateSection(categoryName.c_str()); + Section *section = ini.GetOrCreateSection(categoryName.c_str()); SaveSection(ini, section, iter->second); } ini.Save(GetIniPath(languageID)); } -void I18NRepo::SaveSection(IniFile &ini, IniFile::Section *section, std::shared_ptr cat) { +void I18NRepo::SaveSection(IniFile &ini, Section *section, std::shared_ptr cat) { const std::map &missed = cat->Missed(); for (auto iter = missed.begin(); iter != missed.end(); ++iter) { diff --git a/ext/native/i18n/i18n.h b/ext/native/i18n/i18n.h index cdffed3a29..fcf281b3b7 100644 --- a/ext/native/i18n/i18n.h +++ b/ext/native/i18n/i18n.h @@ -13,11 +13,13 @@ #include #include -#include "file/ini_file.h" +#include "Common/Common.h" // Reasonably thread safe. class I18NRepo; +class IniFile; +class Section; struct I18NEntry { I18NEntry(const std::string &t) : text(t), readFlag(false) {} @@ -63,8 +65,6 @@ private: // Noone else can create these. friend class I18NRepo; - - DISALLOW_COPY_AND_ASSIGN(I18NCategory); }; class I18NRepo { @@ -88,8 +88,8 @@ public: private: std::string GetIniPath(const std::string &languageID) const; void Clear(); - I18NCategory *LoadSection(const IniFile::Section *section, const char *name); - void SaveSection(IniFile &ini, IniFile::Section *section, std::shared_ptr cat); + I18NCategory *LoadSection(const Section *section, const char *name); + void SaveSection(IniFile &ini, Section *section, std::shared_ptr cat); mutable std::mutex catsLock_; std::map> cats_; diff --git a/ext/native/ui/ui_screen.cpp b/ext/native/ui/ui_screen.cpp index 3bfa8dcfe1..9d36ee627b 100644 --- a/ext/native/ui/ui_screen.cpp +++ b/ext/native/ui/ui_screen.cpp @@ -3,6 +3,7 @@ #include #include "base/display.h" +#include "base/stringutil.h" #include "input/input_state.h" #include "input/keycodes.h" #include "math/curves.h"