mirror of https://github.com/stella-emu/stella.git
Wrap std::stoi inside BSPF::stringToInt, and handle its exceptions.
This commit is contained in:
parent
d0469ac9f4
commit
5273986e88
|
@ -145,6 +145,13 @@ namespace BSPF
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert string to integer, using default value on any error
|
||||||
|
inline int stringToInt(const string& s, const int defaultValue = 0)
|
||||||
|
{
|
||||||
|
try { return std::stoi(s); }
|
||||||
|
catch(...) { return defaultValue; }
|
||||||
|
}
|
||||||
|
|
||||||
// Compare two strings, ignoring case
|
// Compare two strings, ignoring case
|
||||||
inline int compareIgnoreCase(const string& s1, const string& s2)
|
inline int compareIgnoreCase(const string& s1, const string& s2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -110,7 +110,7 @@ Console::Console(OSystem& osystem, unique_ptr<Cartridge>& cart,
|
||||||
myCart->setStartBankFromPropsFunc([this]() {
|
myCart->setStartBankFromPropsFunc([this]() {
|
||||||
const string& startbank = myProperties.get(PropType::Cart_StartBank);
|
const string& startbank = myProperties.get(PropType::Cart_StartBank);
|
||||||
return (startbank == EmptyString || BSPF::equalsIgnoreCase(startbank, "AUTO"))
|
return (startbank == EmptyString || BSPF::equalsIgnoreCase(startbank, "AUTO"))
|
||||||
? -1 : stoi(startbank);
|
? -1 : BSPF::stringToInt(startbank);
|
||||||
});
|
});
|
||||||
|
|
||||||
// We can only initialize after all the devices/components have been created
|
// We can only initialize after all the devices/components have been created
|
||||||
|
@ -583,13 +583,7 @@ void Console::togglePhosphor()
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void Console::changePhosphor(int direction)
|
void Console::changePhosphor(int direction)
|
||||||
{
|
{
|
||||||
int blend = 0;
|
int blend = BSPF::stringToInt(myProperties.get(PropType::Display_PPBlend));
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
blend = stoi(myProperties.get(PropType::Display_PPBlend));
|
|
||||||
}
|
|
||||||
catch (...) {}
|
|
||||||
|
|
||||||
if(direction == +1) // increase blend
|
if(direction == +1) // increase blend
|
||||||
{
|
{
|
||||||
|
@ -795,7 +789,7 @@ void Console::changeScanlineAdjust(int direction)
|
||||||
void Console::setTIAProperties()
|
void Console::setTIAProperties()
|
||||||
{
|
{
|
||||||
Int32 vcenter = BSPF::clamp(
|
Int32 vcenter = BSPF::clamp(
|
||||||
static_cast<Int32>(stoi(myProperties.get(PropType::Display_VCenter))), TIAConstants::minVcenter, TIAConstants::maxVcenter
|
static_cast<Int32>(BSPF::stringToInt(myProperties.get(PropType::Display_VCenter))), TIAConstants::minVcenter, TIAConstants::maxVcenter
|
||||||
);
|
);
|
||||||
|
|
||||||
if(myDisplayFormat == "NTSC" || myDisplayFormat == "PAL60" ||
|
if(myDisplayFormat == "NTSC" || myDisplayFormat == "PAL60" ||
|
||||||
|
|
|
@ -1162,7 +1162,7 @@ void EventHandler::setComboMap()
|
||||||
{
|
{
|
||||||
string key;
|
string key;
|
||||||
buf >> key;
|
buf >> key;
|
||||||
if(stoi(key) == COMBO_SIZE)
|
if(BSPF::stringToInt(key) == COMBO_SIZE)
|
||||||
{
|
{
|
||||||
// Fill the combomap table with events for as long as they exist
|
// Fill the combomap table with events for as long as they exist
|
||||||
int combocount = 0;
|
int combocount = 0;
|
||||||
|
@ -1175,7 +1175,7 @@ void EventHandler::setComboMap()
|
||||||
int eventcount = 0;
|
int eventcount = 0;
|
||||||
while(buf2 >> key && eventcount < EVENTS_PER_COMBO)
|
while(buf2 >> key && eventcount < EVENTS_PER_COMBO)
|
||||||
{
|
{
|
||||||
myComboTable[combocount][eventcount] = Event::Type(stoi(key));
|
myComboTable[combocount][eventcount] = Event::Type(BSPF::stringToInt(key));
|
||||||
++eventcount;
|
++eventcount;
|
||||||
}
|
}
|
||||||
++combocount;
|
++combocount;
|
||||||
|
@ -1464,7 +1464,7 @@ void EventHandler::setComboListForEvent(Event::Type event, const StringList& eve
|
||||||
int combo = event - Event::Combo1;
|
int combo = event - Event::Combo1;
|
||||||
for(uInt32 i = 0; i < 8; ++i)
|
for(uInt32 i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
uInt32 idx = stoi(events[i]);
|
uInt32 idx = BSPF::stringToInt(events[i]);
|
||||||
if(idx < ourEmulActionList.size())
|
if(idx < ourEmulActionList.size())
|
||||||
myComboTable[combo][i] = EventHandler::ourEmulActionList[idx].event;
|
myComboTable[combo][i] = EventHandler::ourEmulActionList[idx].event;
|
||||||
else
|
else
|
||||||
|
|
|
@ -69,7 +69,7 @@ ProfilingRunner::ProfilingRunner(int argc, char* argv[])
|
||||||
|
|
||||||
if (splitPoint == string::npos) run.runtime = RUNTIME_DEFAULT;
|
if (splitPoint == string::npos) run.runtime = RUNTIME_DEFAULT;
|
||||||
else {
|
else {
|
||||||
int runtime = stoi(arg.substr(splitPoint+1, string::npos));
|
int runtime = BSPF::stringToInt(arg.substr(splitPoint+1, string::npos));
|
||||||
run.runtime = runtime > 0 ? runtime : RUNTIME_DEFAULT;
|
run.runtime = runtime > 0 ? runtime : RUNTIME_DEFAULT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ void Properties::set(PropType key, const string& value)
|
||||||
|
|
||||||
case PropType::Display_PPBlend:
|
case PropType::Display_PPBlend:
|
||||||
{
|
{
|
||||||
int blend = stoi(myProperties[pos]);
|
int blend = BSPF::stringToInt(myProperties[pos]);
|
||||||
if(blend < 0 || blend > 100)
|
if(blend < 0 || blend > 100)
|
||||||
myProperties[pos] = ourDefaultProperties[pos];
|
myProperties[pos] = ourDefaultProperties[pos];
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -91,11 +91,7 @@ void TIASurface::initialize(const Console& console,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
try
|
p_blend = BSPF::stringToInt(console.properties().get(PropType::Display_PPBlend));
|
||||||
{
|
|
||||||
p_blend = stoi(console.properties().get(PropType::Display_PPBlend));
|
|
||||||
}
|
|
||||||
catch (...) {}
|
|
||||||
enable = console.properties().get(PropType::Display_Phosphor) == "YES";
|
enable = console.properties().get(PropType::Display_Phosphor) == "YES";
|
||||||
}
|
}
|
||||||
enablePhosphor(enable, p_blend);
|
enablePhosphor(enable, p_blend);
|
||||||
|
|
|
@ -653,17 +653,10 @@ void GameInfoDialog::loadEmulationProperties(const Properties& props)
|
||||||
myPPBlend->setEnabled(!alwaysPhosphor && usePhosphor);
|
myPPBlend->setEnabled(!alwaysPhosphor && usePhosphor);
|
||||||
|
|
||||||
const string& blend = props.get(PropType::Display_PPBlend);
|
const string& blend = props.get(PropType::Display_PPBlend);
|
||||||
try
|
myPPBlend->setValue(BSPF::stringToInt(blend));
|
||||||
{
|
|
||||||
myPPBlend->setValue(stoi(blend));
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
myPPBlend->setValue(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set vertical center
|
// set vertical center
|
||||||
Int32 vcenter = stoi(props.get(PropType::Display_VCenter));
|
Int32 vcenter = BSPF::stringToInt(props.get(PropType::Display_VCenter));
|
||||||
myVCenter->setValueLabel(vcenter);
|
myVCenter->setValueLabel(vcenter);
|
||||||
myVCenter->setValue(vcenter);
|
myVCenter->setValue(vcenter);
|
||||||
myVCenter->setValueUnit(vcenter ? "px" : "");
|
myVCenter->setValueUnit(vcenter ? "px" : "");
|
||||||
|
@ -712,7 +705,7 @@ void GameInfoDialog::loadControllerProperties(const Properties& props)
|
||||||
myMouseY->setEnabled(!autoAxis);
|
myMouseY->setEnabled(!autoAxis);
|
||||||
if(m_axis >> m_range)
|
if(m_axis >> m_range)
|
||||||
{
|
{
|
||||||
myMouseRange->setValue(stoi(m_range));
|
myMouseRange->setValue(BSPF::stringToInt(m_range));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue