Make all Bankswitch types detectable with specific ROM filename extensions.

Use a map instead of linear search in Bankswitch class.
This commit is contained in:
Stephen Anthony 2018-08-31 22:04:31 -02:30
parent 09b3d980f3
commit dce16d6f7c
2 changed files with 111 additions and 47 deletions

View File

@ -26,11 +26,11 @@ string Bankswitch::typeToName(Bankswitch::Type type)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Bankswitch::Type Bankswitch::nameToType(const string& name) Bankswitch::Type Bankswitch::nameToType(const string& name)
{ {
for(int i = 0; i < int(Bankswitch::Type::NumSchemes); ++i) auto it = ourNameToTypes.find(name);
if(BSPF::equalsIgnoreCase(BSList[i].name, name)) if(it != ourNameToTypes.end())
return Bankswitch::Type(i); return it->second;
return Bankswitch::Type::_AUTO; return Bankswitch::Type::_AUTO;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -141,46 +141,108 @@ Bankswitch::ExtensionMap Bankswitch::ourExtensions = {
{ "zip", Bankswitch::Type::_AUTO }, { "zip", Bankswitch::Type::_AUTO },
{ "cu", Bankswitch::Type::_AUTO }, { "cu", Bankswitch::Type::_AUTO },
// Types from UnoCart and HarmonyCart // All bankswitch types (tose that UnoCart and HarmonyCart support have the same name)
{ "084", Bankswitch::Type::_0840 }, { "084", Bankswitch::Type::_0840 },
{ "2K", Bankswitch::Type::_2K }, { "2N1", Bankswitch::Type::_2IN1 },
{ "3E", Bankswitch::Type::_3E }, { "4N1", Bankswitch::Type::_4IN1 },
{ "3EP", Bankswitch::Type::_3EP }, { "8N1", Bankswitch::Type::_8IN1 },
{ "3F", Bankswitch::Type::_3F }, { "16N", Bankswitch::Type::_16IN1 },
{ "4A5", Bankswitch::Type::_4A50 }, { "32N", Bankswitch::Type::_32IN1 },
{ "4K", Bankswitch::Type::_4K }, { "64N", Bankswitch::Type::_64IN1 },
{ "4KS", Bankswitch::Type::_4KSC }, { "128", Bankswitch::Type::_128IN1 },
{ "AR", Bankswitch::Type::_AR }, { "2K", Bankswitch::Type::_2K },
{ "BF", Bankswitch::Type::_BF }, { "3E", Bankswitch::Type::_3E },
{ "BFS", Bankswitch::Type::_BFSC }, { "3EP", Bankswitch::Type::_3EP },
{ "BUS", Bankswitch::Type::_BUS }, { "3F", Bankswitch::Type::_3F },
{ "CDF", Bankswitch::Type::_CDF }, { "4A5", Bankswitch::Type::_4A50 },
{ "CM", Bankswitch::Type::_CM }, { "4K", Bankswitch::Type::_4K },
{ "CTY", Bankswitch::Type::_CTY }, { "4KS", Bankswitch::Type::_4KSC },
{ "CV", Bankswitch::Type::_CV }, { "AR", Bankswitch::Type::_AR },
{ "CVP", Bankswitch::Type::_CVP }, { "BF", Bankswitch::Type::_BF },
{ "DAS", Bankswitch::Type::_DASH }, { "BFS", Bankswitch::Type::_BFSC },
{ "DF", Bankswitch::Type::_DF }, { "BUS", Bankswitch::Type::_BUS },
{ "DFS", Bankswitch::Type::_DFSC }, { "CDF", Bankswitch::Type::_CDF },
{ "DPC", Bankswitch::Type::_DPC }, { "CM", Bankswitch::Type::_CM },
{ "DPP", Bankswitch::Type::_DPCP }, { "CTY", Bankswitch::Type::_CTY },
{ "E0", Bankswitch::Type::_E0 }, { "CV", Bankswitch::Type::_CV },
{ "E7", Bankswitch::Type::_E7 }, { "CVP", Bankswitch::Type::_CVP },
{ "E78", Bankswitch::Type::_E78K }, { "DAS", Bankswitch::Type::_DASH },
{ "EF", Bankswitch::Type::_EF }, { "DF", Bankswitch::Type::_DF },
{ "EFS", Bankswitch::Type::_EFSC }, { "DFS", Bankswitch::Type::_DFSC },
{ "F0", Bankswitch::Type::_F0 }, { "DPC", Bankswitch::Type::_DPC },
{ "F4", Bankswitch::Type::_F4 }, { "DPP", Bankswitch::Type::_DPCP },
{ "F4S", Bankswitch::Type::_F4SC }, { "E0", Bankswitch::Type::_E0 },
{ "F6", Bankswitch::Type::_F6 }, { "E7", Bankswitch::Type::_E7 },
{ "F6S", Bankswitch::Type::_F6SC }, { "E78", Bankswitch::Type::_E78K },
{ "F8", Bankswitch::Type::_F8 }, { "EF", Bankswitch::Type::_EF },
{ "F8S", Bankswitch::Type::_F8SC }, { "EFS", Bankswitch::Type::_EFSC },
{ "FA", Bankswitch::Type::_FA }, { "F0", Bankswitch::Type::_F0 },
{ "FA2", Bankswitch::Type::_FA2 }, { "F4", Bankswitch::Type::_F4 },
{ "FE", Bankswitch::Type::_FE }, { "F4S", Bankswitch::Type::_F4SC },
{ "MDM", Bankswitch::Type::_MDM }, { "F6", Bankswitch::Type::_F6 },
{ "SB", Bankswitch::Type::_SB }, { "F6S", Bankswitch::Type::_F6SC },
{ "UA", Bankswitch::Type::_UA }, { "F8", Bankswitch::Type::_F8 },
{ "WD", Bankswitch::Type::_WD } { "F8S", Bankswitch::Type::_F8SC },
{ "FA", Bankswitch::Type::_FA },
{ "FA2", Bankswitch::Type::_FA2 },
{ "FE", Bankswitch::Type::_FE },
{ "MDM", Bankswitch::Type::_MDM },
{ "SB", Bankswitch::Type::_SB },
{ "UA", Bankswitch::Type::_UA },
{ "WD", Bankswitch::Type::_WD },
{ "X07", Bankswitch::Type::_X07 }
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Bankswitch::NameToTypeMap Bankswitch::ourNameToTypes = {
{ "AUTO", Bankswitch::Type::_AUTO },
{ "0840", Bankswitch::Type::_0840 },
{ "2IN1", Bankswitch::Type::_2IN1 },
{ "4IN1", Bankswitch::Type::_4IN1 },
{ "8IN1", Bankswitch::Type::_8IN1 },
{ "16IN1", Bankswitch::Type::_16IN1 },
{ "32IN1", Bankswitch::Type::_32IN1 },
{ "64IN1", Bankswitch::Type::_64IN1 },
{ "128IN1", Bankswitch::Type::_128IN1 },
{ "2K", Bankswitch::Type::_2K },
{ "3E", Bankswitch::Type::_3E },
{ "3E+", Bankswitch::Type::_3EP },
{ "3F", Bankswitch::Type::_3F },
{ "4A50", Bankswitch::Type::_4A50 },
{ "4K", Bankswitch::Type::_4K },
{ "4KSC", Bankswitch::Type::_4KSC },
{ "AR", Bankswitch::Type::_AR },
{ "BF", Bankswitch::Type::_BF },
{ "BFSC", Bankswitch::Type::_BFSC },
{ "BUS", Bankswitch::Type::_BUS },
{ "CDF", Bankswitch::Type::_CDF },
{ "CM", Bankswitch::Type::_CM },
{ "CTY", Bankswitch::Type::_CTY },
{ "CV", Bankswitch::Type::_CV },
{ "CV+", Bankswitch::Type::_CVP },
{ "DASH", Bankswitch::Type::_DASH },
{ "DF", Bankswitch::Type::_DF },
{ "DFSC", Bankswitch::Type::_DFSC },
{ "DPC", Bankswitch::Type::_DPC },
{ "DPC+", Bankswitch::Type::_DPCP },
{ "E0", Bankswitch::Type::_E0 },
{ "E7", Bankswitch::Type::_E7 },
{ "E78K", Bankswitch::Type::_E78K },
{ "EF", Bankswitch::Type::_EF },
{ "EFSC", Bankswitch::Type::_EFSC },
{ "F0", Bankswitch::Type::_F0 },
{ "F4", Bankswitch::Type::_F4 },
{ "F4SC", Bankswitch::Type::_F4SC },
{ "F6", Bankswitch::Type::_F6 },
{ "F6SC", Bankswitch::Type::_F6SC },
{ "F8", Bankswitch::Type::_F8 },
{ "F8SC", Bankswitch::Type::_F8SC },
{ "FA", Bankswitch::Type::_FA },
{ "FA2", Bankswitch::Type::_FA2 },
{ "FE", Bankswitch::Type::_FE },
{ "MDM", Bankswitch::Type::_MDM },
{ "SB", Bankswitch::Type::_SB },
{ "UA", Bankswitch::Type::_UA },
{ "WD", Bankswitch::Type::_WD },
{ "X07", Bankswitch::Type::_X07 }
}; };

View File

@ -91,9 +91,11 @@ class Bankswitch
} }
}; };
using ExtensionMap = std::map<string, Bankswitch::Type, TypeComparator>; using ExtensionMap = std::map<string, Bankswitch::Type, TypeComparator>;
static ExtensionMap ourExtensions; static ExtensionMap ourExtensions;
using NameToTypeMap = std::map<string, Bankswitch::Type, TypeComparator>;
static NameToTypeMap ourNameToTypes;
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported
Bankswitch() = delete; Bankswitch() = delete;