diff --git a/src/emucore/Bankswitch.cxx b/src/emucore/Bankswitch.cxx index d5677d7da..50e592875 100644 --- a/src/emucore/Bankswitch.cxx +++ b/src/emucore/Bankswitch.cxx @@ -20,13 +20,12 @@ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string Bankswitch::typeToName(Bankswitch::Type type) { - return BSList[static_cast(type)].name; + return string{BSList[static_cast(type)].name}; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Bankswitch::Type Bankswitch::nameToType(string_view n) // FIXME: name +Bankswitch::Type Bankswitch::nameToType(string_view name) { - string name{n}; const auto it = ourNameToTypes.find(name); if(it != ourNameToTypes.end()) return it->second; @@ -37,17 +36,17 @@ Bankswitch::Type Bankswitch::nameToType(string_view n) // FIXME: name // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - string Bankswitch::typeToDesc(Bankswitch::Type type) { - return BSList[static_cast(type)].desc; + return string{BSList[static_cast(type)].desc}; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Bankswitch::Type Bankswitch::typeFromExtension(const FSNode& file) { - const string& name = file.getPath(); - const string::size_type idx = name.find_last_of('.'); - if(idx != string::npos) + const string_view name = file.getPath(); + const auto idx = name.find_last_of('.'); + if(idx != string_view::npos) { - const auto it = ourExtensions.find(name.c_str() + idx + 1); + const auto it = ourExtensions.find(name.substr(idx + 1)); if(it != ourExtensions.end()) return it->second; } @@ -56,12 +55,12 @@ Bankswitch::Type Bankswitch::typeFromExtension(const FSNode& file) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Bankswitch::isValidRomName(const string& name, string& ext) +bool Bankswitch::isValidRomName(string_view name, string& ext) { - const string::size_type idx = name.find_last_of('.'); - if(idx != string::npos) + const auto idx = name.find_last_of('.'); + if(idx != string_view::npos) { - const char* const e = name.c_str() + idx + 1; + const auto e = name.substr(idx + 1); const auto it = ourExtensions.find(e); if(it != ourExtensions.end()) { @@ -73,27 +72,7 @@ bool Bankswitch::isValidRomName(const string& name, string& ext) } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Bankswitch::isValidRomName(const FSNode& name, string& ext) -{ - return isValidRomName(name.getPath(), ext); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Bankswitch::isValidRomName(const FSNode& name) -{ - string ext; // extension not used - return isValidRomName(name.getPath(), ext); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Bankswitch::isValidRomName(const string& name) -{ - string ext; // extension not used - return isValidRomName(name, ext); -} - -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -constexpr std::array(Bankswitch::Type::NumSchemes)> +constexpr std::array(Bankswitch::Type::NumSchemes)> Bankswitch::BSList = {{ { "AUTO" , "Auto-detect" }, { "0840" , "0840 (8K EconoBanking)" }, @@ -154,8 +133,8 @@ Bankswitch::BSList = {{ #endif }}; -#if defined(GUI_SUPPORT) -const std::array(Bankswitch::Type::NumSchemes)> +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +const std::array(Bankswitch::Type::NumSchemes)> Bankswitch::Sizes = {{ { Bankswitch::any_KB, Bankswitch::any_KB }, // _AUTO { 8_KB, 8_KB }, // _0840 @@ -215,7 +194,6 @@ Bankswitch::Sizes = {{ { Bankswitch::any_KB, Bankswitch::any_KB } #endif }}; -#endif // GUI_SUPPORT // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Bankswitch::ExtensionMap Bankswitch::ourExtensions = { diff --git a/src/emucore/Bankswitch.hxx b/src/emucore/Bankswitch.hxx index 8f14502de..53ffb6f38 100644 --- a/src/emucore/Bankswitch.hxx +++ b/src/emucore/Bankswitch.hxx @@ -52,23 +52,23 @@ class Bankswitch NumMulti = _128IN1 - _2IN1 + 1, }; -#ifdef GUI_SUPPORT struct SizesType { size_t minSize{0}; size_t maxSize{0}; }; static constexpr size_t any_KB = 0; - static const std::array(Type::NumSchemes)> Sizes; -#endif + static const std::array(Type::NumSchemes)> Sizes; // Info about the various bankswitch schemes, useful for displaying // in GUI dropdown boxes, etc struct Description { - const char* const name{nullptr}; - const char* const desc{nullptr}; + string_view name; + string_view desc; }; - static const std::array(Type::NumSchemes)> BSList; + static const std::array(Type::NumSchemes)> BSList; public: // Convert BSType enum to string @@ -90,14 +90,22 @@ class Bankswitch @param name Filename of potential ROM file @param ext The extension extracted from the given file */ - static bool isValidRomName(const string& name, string& ext); + static bool isValidRomName(string_view name, string& ext); /** Convenience functions for different parameter types. */ - static bool isValidRomName(const FSNode& name, string& ext); - static bool isValidRomName(const FSNode& name); - static bool isValidRomName(const string& name); + static inline bool isValidRomName(const FSNode& name, string& ext) { + return isValidRomName(name.getPath(), ext); + } + static inline bool isValidRomName(const FSNode& name) { + string ext; // extension not used + return isValidRomName(name.getPath(), ext); + } + static inline bool isValidRomName(string_view name) { + string ext; // extension not used + return isValidRomName(name, ext); + } // Output operator friend ostream& operator<<(ostream& os, const Bankswitch::Type& t) { @@ -106,14 +114,16 @@ class Bankswitch private: struct TypeComparator { - bool operator() (const string& a, const string& b) const { + bool operator() (string_view a, string_view b) const { return BSPF::compareIgnoreCase(a, b) < 0; } }; - using ExtensionMap = const std::map; + using ExtensionMap = const std::map; static ExtensionMap ourExtensions; - using NameToTypeMap = const std::map; + using NameToTypeMap = const std::map; static NameToTypeMap ourNameToTypes; private: