From a233b96c2a82d316caaf1244675068ec80e5886d Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Tue, 11 Jan 2022 21:57:00 +0100 Subject: [PATCH] Removed some unnecessary typedefs and replaced the remaining ones with the more modern 'using' keyword. Also harmonized the names of some user defined types and made some other minor cleanup. --- es-app/src/CollectionSystemsManager.cpp | 8 ++++---- es-app/src/FileData.h | 2 +- es-app/src/Gamelist.cpp | 2 +- es-app/src/SystemData.cpp | 4 ++-- es-app/src/SystemScreensaver.cpp | 2 +- es-app/src/guis/GuiGamelistOptions.h | 4 ++-- es-app/src/guis/GuiMenu.cpp | 5 ++--- es-app/src/guis/GuiScraperMenu.h | 2 +- es-app/src/scrapers/Scraper.h | 10 +++++----- es-core/src/HelpPrompt.h | 2 +- es-core/src/InputConfig.cpp | 6 ++---- es-core/src/ThemeData.cpp | 4 ++-- es-core/src/components/AnimatedImageComponent.h | 2 +- es-core/src/resources/TextureResource.h | 2 +- es-core/src/utils/CImgUtil.h | 1 + es-core/src/utils/FileSystemUtil.cpp | 12 ++++++------ es-core/src/utils/FileSystemUtil.h | 7 ++++--- es-core/src/utils/StringUtil.cpp | 15 ++++----------- es-core/src/utils/StringUtil.h | 2 ++ es-core/src/utils/TimeUtil.h | 1 + 20 files changed, 44 insertions(+), 49 deletions(-) diff --git a/es-app/src/CollectionSystemsManager.cpp b/es-app/src/CollectionSystemsManager.cpp index 8757dd436..680344524 100644 --- a/es-app/src/CollectionSystemsManager.cpp +++ b/es-app/src/CollectionSystemsManager.cpp @@ -1366,9 +1366,9 @@ std::vector CollectionSystemsManager::getSystemsFromTheme() std::string themePath = set->second.path; if (Utils::FileSystem::exists(themePath)) { - Utils::FileSystem::stringList dirContent = Utils::FileSystem::getDirContent(themePath); + Utils::FileSystem::StringList dirContent = Utils::FileSystem::getDirContent(themePath); - for (Utils::FileSystem::stringList::const_iterator it = dirContent.cbegin(); + for (Utils::FileSystem::StringList::const_iterator it = dirContent.cbegin(); it != dirContent.cend(); ++it) { if (Utils::FileSystem::isDirectory(*it)) { // ... here you have a directory. @@ -1390,8 +1390,8 @@ std::vector CollectionSystemsManager::getCollectionsFromConfigFolde std::string configPath = getCollectionsFolder(); if (Utils::FileSystem::exists(configPath)) { - Utils::FileSystem::stringList dirContent = Utils::FileSystem::getDirContent(configPath); - for (Utils::FileSystem::stringList::const_iterator it = dirContent.cbegin(); + Utils::FileSystem::StringList dirContent = Utils::FileSystem::getDirContent(configPath); + for (Utils::FileSystem::StringList::const_iterator it = dirContent.cbegin(); it != dirContent.cend(); ++it) { if (Utils::FileSystem::isRegularFile(*it)) { // It's a file. diff --git a/es-app/src/FileData.h b/es-app/src/FileData.h index 1133a067a..c66d4db7b 100644 --- a/es-app/src/FileData.h +++ b/es-app/src/FileData.h @@ -108,7 +108,7 @@ public: void launchGame(Window* window); const std::string findEmulatorPath(std::string& command); - typedef bool ComparisonFunction(const FileData* a, const FileData* b); + using ComparisonFunction = bool(const FileData* a, const FileData* b); struct SortType { ComparisonFunction* comparisonFunction; std::string description; diff --git a/es-app/src/Gamelist.cpp b/es-app/src/Gamelist.cpp index 55838ed94..315c612b6 100644 --- a/es-app/src/Gamelist.cpp +++ b/es-app/src/Gamelist.cpp @@ -30,7 +30,7 @@ FileData* findOrCreateFile(SystemData* system, const std::string& path, FileType return nullptr; } - Utils::FileSystem::stringList pathList = Utils::FileSystem::getPathList(relative); + Utils::FileSystem::StringList pathList = Utils::FileSystem::getPathList(relative); auto path_it = pathList.begin(); FileData* treeNode = root; bool found = false; diff --git a/es-app/src/SystemData.cpp b/es-app/src/SystemData.cpp index 1f5780e23..f2aed2aa2 100644 --- a/es-app/src/SystemData.cpp +++ b/es-app/src/SystemData.cpp @@ -265,13 +265,13 @@ bool SystemData::populateFolder(FileData* folder) std::string extension; bool isGame; bool showHiddenFiles = Settings::getInstance()->getBool("ShowHiddenFiles"); - Utils::FileSystem::stringList dirContent = Utils::FileSystem::getDirContent(folderPath); + Utils::FileSystem::StringList dirContent = Utils::FileSystem::getDirContent(folderPath); // If system directory exists but contains no games, return as error. if (dirContent.size() == 0) return false; - for (Utils::FileSystem::stringList::const_iterator it = dirContent.cbegin(); + for (Utils::FileSystem::StringList::const_iterator it = dirContent.cbegin(); it != dirContent.cend(); ++it) { filePath = *it; diff --git a/es-app/src/SystemScreensaver.cpp b/es-app/src/SystemScreensaver.cpp index 255ee802c..cf1e1fba1 100644 --- a/es-app/src/SystemScreensaver.cpp +++ b/es-app/src/SystemScreensaver.cpp @@ -465,7 +465,7 @@ void SystemScreensaver::generateCustomImageList() if (imageDir != "" && Utils::FileSystem::isDirectory(imageDir)) { std::string imageFilter = ".jpg, .JPG, .png, .PNG"; - Utils::FileSystem::stringList dirContent = Utils::FileSystem::getDirContent( + Utils::FileSystem::StringList dirContent = Utils::FileSystem::getDirContent( imageDir, Settings::getInstance()->getBool("ScreensaverSlideshowRecurse")); for (auto it = dirContent.begin(); it != dirContent.end(); ++it) { diff --git a/es-app/src/guis/GuiGamelistOptions.h b/es-app/src/guis/GuiGamelistOptions.h index 3226ae38d..bb81cd19b 100644 --- a/es-app/src/guis/GuiGamelistOptions.h +++ b/es-app/src/guis/GuiGamelistOptions.h @@ -43,10 +43,10 @@ private: MenuComponent mMenu; - typedef OptionListComponent LetterList; + using LetterList = OptionListComponent; std::shared_ptr mJumpToLetterList; - typedef OptionListComponent SortList; + using SortList = OptionListComponent; std::shared_ptr mListSort; SystemData* mSystem; diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index 93f58e181..8f7060432 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -296,10 +296,9 @@ void GuiMenu::openUIOptions() }); // Default gamelist sort order. - typedef OptionListComponent SortList; std::string sortOrder; - auto default_sort_order = - std::make_shared(mWindow, getHelpStyle(), "DEFAULT SORT ORDER", false); + auto default_sort_order = std::make_shared>( + mWindow, getHelpStyle(), "DEFAULT SORT ORDER", false); // Exclude the System sort options. unsigned int numSortTypes = static_cast(FileSorts::SortTypes.size() - 2); for (unsigned int i = 0; i < numSortTypes; ++i) { diff --git a/es-app/src/guis/GuiScraperMenu.h b/es-app/src/guis/GuiScraperMenu.h index 2f950d47a..f54444857 100644 --- a/es-app/src/guis/GuiScraperMenu.h +++ b/es-app/src/guis/GuiScraperMenu.h @@ -20,7 +20,7 @@ class SwitchComponent; class SystemData; template class OptionListComponent; -typedef std::function GameFilterFunc; +using GameFilterFunc = std::function; class GuiScraperMenu : public GuiComponent { diff --git a/es-app/src/scrapers/Scraper.h b/es-app/src/scrapers/Scraper.h index 5877084e4..fbe1cb8b5 100644 --- a/es-app/src/scrapers/Scraper.h +++ b/es-app/src/scrapers/Scraper.h @@ -151,10 +151,10 @@ std::vector getScraperList(); // Returns true if the scraper configured in the settings is still valid. bool isValidConfiguredScraper(); -typedef void (*generate_scraper_requests_func)( - const ScraperSearchParams& params, - std::queue>& requests, - std::vector& results); +using generate_scraper_requests_func = + void (*)(const ScraperSearchParams& params, + std::queue>& requests, + std::vector& results); // ------------------------------------------------------------------------- @@ -175,7 +175,7 @@ public: private: ScraperSearchResult mResult; - typedef std::pair, std::function> ResolvePair; + using ResolvePair = std::pair, std::function>; std::vector mFuncs; }; diff --git a/es-core/src/HelpPrompt.h b/es-core/src/HelpPrompt.h index 5e312498a..d7f3c60b2 100644 --- a/es-core/src/HelpPrompt.h +++ b/es-core/src/HelpPrompt.h @@ -11,6 +11,6 @@ #include -typedef std::pair HelpPrompt; +using HelpPrompt = std::pair; #endif // ES_CORE_HELP_PROMPT_H diff --git a/es-core/src/InputConfig.cpp b/es-core/src/InputConfig.cpp index 2322e8136..4c9af0765 100644 --- a/es-core/src/InputConfig.cpp +++ b/es-core/src/InputConfig.cpp @@ -120,8 +120,7 @@ std::vector InputConfig::getMappedTo(Input input) { std::vector maps; - typedef std::map::const_iterator it_type; - for (it_type it = mNameMap.cbegin(); it != mNameMap.cend(); ++it) { + for (auto it = mNameMap.cbegin(); it != mNameMap.cend(); ++it) { Input chk = it->second; if (!chk.configured) @@ -204,8 +203,7 @@ void InputConfig::writeToXML(pugi::xml_node& parent) cfg.append_attribute("deviceGUID") = mDeviceGUID.c_str(); - typedef std::map::const_iterator it_type; - for (it_type it = mNameMap.cbegin(); it != mNameMap.cend(); ++it) { + for (auto it = mNameMap.cbegin(); it != mNameMap.cend(); ++it) { if (!it->second.configured) continue; diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 6dd152a28..888723599 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -702,9 +702,9 @@ std::map ThemeData::getThemeSets() if (!Utils::FileSystem::isDirectory(paths[i])) continue; - Utils::FileSystem::stringList dirContent = Utils::FileSystem::getDirContent(paths[i]); + Utils::FileSystem::StringList dirContent = Utils::FileSystem::getDirContent(paths[i]); - for (Utils::FileSystem::stringList::const_iterator it = dirContent.cbegin(); + for (Utils::FileSystem::StringList::const_iterator it = dirContent.cbegin(); it != dirContent.cend(); ++it) { if (Utils::FileSystem::isDirectory(*it)) { ThemeSet set = {*it}; diff --git a/es-core/src/components/AnimatedImageComponent.h b/es-core/src/components/AnimatedImageComponent.h index 7294de6bb..5f878a9d7 100644 --- a/es-core/src/components/AnimatedImageComponent.h +++ b/es-core/src/components/AnimatedImageComponent.h @@ -39,7 +39,7 @@ public: void onSizeChanged() override; private: - typedef std::pair, int> ImageFrame; + using ImageFrame = std::pair, int>; std::vector mFrames; diff --git a/es-core/src/resources/TextureResource.h b/es-core/src/resources/TextureResource.h index 1777117b3..8ac505a70 100644 --- a/es-core/src/resources/TextureResource.h +++ b/es-core/src/resources/TextureResource.h @@ -85,7 +85,7 @@ private: glm::vec2 mSourceSize; bool mForceLoad; - typedef std::pair TextureKeyType; + using TextureKeyType = std::pair; // Map of textures, used to prevent duplicate textures. static std::map> sTextureMap; // Set of all textures, used for memory management. diff --git a/es-core/src/utils/CImgUtil.h b/es-core/src/utils/CImgUtil.h index a5afca199..203773461 100644 --- a/es-core/src/utils/CImgUtil.h +++ b/es-core/src/utils/CImgUtil.h @@ -33,6 +33,7 @@ namespace Utils unsigned int shadowDistance, float transparency, unsigned int iterations); + } // namespace CImg } // namespace Utils diff --git a/es-core/src/utils/FileSystemUtil.cpp b/es-core/src/utils/FileSystemUtil.cpp index ad7443486..708949cbc 100644 --- a/es-core/src/utils/FileSystemUtil.cpp +++ b/es-core/src/utils/FileSystemUtil.cpp @@ -63,10 +63,10 @@ namespace Utils static std::string homePath = ""; static std::string exePath = ""; - stringList getDirContent(const std::string& path, const bool recursive) + StringList getDirContent(const std::string& path, const bool recursive) { std::string genericPath = getGenericPath(path); - stringList contentList; + StringList contentList; // Only parse the directory, if it's a directory. if (isDirectory(genericPath)) { @@ -121,9 +121,9 @@ namespace Utils return contentList; } - stringList getPathList(const std::string& path) + StringList getPathList(const std::string& path) { - stringList pathList; + StringList pathList; std::string genericPath = getGenericPath(path); size_t start = 0; size_t end = 0; @@ -337,12 +337,12 @@ namespace Utils // Cleanup path. bool scan = true; while (scan) { - stringList pathList = getPathList(canonicalPath); + StringList pathList = getPathList(canonicalPath); canonicalPath.clear(); scan = false; - for (stringList::const_iterator it = pathList.cbegin(); it != pathList.cend(); + for (StringList::const_iterator it = pathList.cbegin(); it != pathList.cend(); ++it) { // Ignore empty. if ((*it).empty()) diff --git a/es-core/src/utils/FileSystemUtil.h b/es-core/src/utils/FileSystemUtil.h index b8f07e31f..cd34d4bb2 100644 --- a/es-core/src/utils/FileSystemUtil.h +++ b/es-core/src/utils/FileSystemUtil.h @@ -18,10 +18,10 @@ namespace Utils { namespace FileSystem { - typedef std::list stringList; + using StringList = std::list; - stringList getDirContent(const std::string& path, const bool recursive = false); - stringList getPathList(const std::string& path); + StringList getDirContent(const std::string& path, const bool recursive = false); + StringList getPathList(const std::string& path); void setHomePath(const std::string& path); std::string getHomePath(); std::string getCWDPath(); @@ -66,6 +66,7 @@ namespace Utils bool isDirectory(const std::string& path); bool isSymlink(const std::string& path); bool isHidden(const std::string& path); + } // namespace FileSystem } // namespace Utils diff --git a/es-core/src/utils/StringUtil.cpp b/es-core/src/utils/StringUtil.cpp index 2049b55fe..59566a8eb 100644 --- a/es-core/src/utils/StringUtil.cpp +++ b/es-core/src/utils/StringUtil.cpp @@ -14,7 +14,6 @@ #include "utils/StringUtil.h" #include -#include #include namespace Utils @@ -470,8 +469,7 @@ namespace Utils if (charIndex != nullptr) { wchar_t lowerChar = *(unicodeLowercase + (charIndex - unicodeUppercase)); // Convert back to string format. - typedef std::codecvt_utf8 convert_type; - std::wstring_convert byteConverter; + std::wstring_convert, wchar_t> byteConverter; stringLower += byteConverter.to_bytes(lowerChar); } @@ -523,8 +521,7 @@ namespace Utils if (charIndex != nullptr) { wchar_t upperChar = *(unicodeUppercase + (charIndex - unicodeLowercase)); // Convert back to string format. - typedef std::codecvt_utf8 convert_type; - std::wstring_convert byteConverter; + std::wstring_convert, wchar_t> byteConverter; stringUpper += byteConverter.to_bytes(upperChar); } @@ -596,17 +593,13 @@ namespace Utils std::wstring stringToWideString(const std::string& stringArg) { - typedef std::codecvt_utf8 convert_type; - std::wstring_convert stringConverter; - + std::wstring_convert, wchar_t> stringConverter; return stringConverter.from_bytes(stringArg); } std::string wideStringToString(const std::wstring& stringArg) { - typedef std::codecvt_utf8 convert_type; - std::wstring_convert stringConverter; - + std::wstring_convert, wchar_t> stringConverter; return stringConverter.to_bytes(stringArg); } diff --git a/es-core/src/utils/StringUtil.h b/es-core/src/utils/StringUtil.h index 28e9c9060..ae64019b9 100644 --- a/es-core/src/utils/StringUtil.h +++ b/es-core/src/utils/StringUtil.h @@ -10,6 +10,7 @@ #ifndef ES_CORE_UTILS_STRING_UTIL_H #define ES_CORE_UTILS_STRING_UTIL_H +#include #include #include @@ -44,6 +45,7 @@ namespace Utils const std::string& delimiter, bool caseInsensitive = false); std::string scramble(const std::string& input, const std::string& key); + } // namespace String } // namespace Utils diff --git a/es-core/src/utils/TimeUtil.h b/es-core/src/utils/TimeUtil.h index dfd8f344e..644bdf49f 100644 --- a/es-core/src/utils/TimeUtil.h +++ b/es-core/src/utils/TimeUtil.h @@ -71,6 +71,7 @@ namespace Utils std::string timeToString(const time_t& time, const std::string& format = "%Y%m%dT%H%M%S"); int daysInMonth(const int year, const int month); int daysInYear(const int year); + } // namespace Time } // namespace Utils