Some C++20 additions.

This commit is contained in:
Stephen Anthony 2024-05-09 19:26:20 -02:30
parent 2d57f9e028
commit 7a85faef55
5 changed files with 11 additions and 23 deletions

View File

@ -462,8 +462,8 @@ Int32 HighScoresManager::convert(Int32 val, uInt32 maxVal, bool isBCD,
//maxVal += zeroBased ? 0 : 1;
maxVal -= zeroBased ? 1 : 0;
const Int32 bits = isBCD
? ceil(log(maxVal) / log(10) * 4)
: ceil(log(maxVal) / log(2));
? ceil(log(maxVal) / std::numbers::ln10 * 4)
: ceil(log(maxVal) / std::numbers::ln2);
// limit to maxVal's bits
val %= 1 << bits;

View File

@ -60,26 +60,17 @@ class Variant
const string& toString() const { return data; }
const char* toCString() const { return data.c_str(); }
Int32 toInt() const {
istringstream ss(data);
Int32 parsed;
ss >> parsed;
return parsed;
try { return std::stoi(data); } catch(...) { return 0; }
}
float toFloat() const {
istringstream ss(data);
float parsed;
ss >> parsed;
return parsed;
try { return std::stof(data); } catch(...) { return 0.F; }
}
bool toBool() const { return data == "1" || data == "true"; }
Common::Size toSize() const { return Common::Size(data); }
Common::Point toPoint() const { return Common::Point(data); }
// Comparison
bool operator==(const Variant& v) const { return data == v.data; }
bool operator!=(const Variant& v) const { return data != v.data; }
bool operator<=>(const Variant& v) const = default;
friend ostream& operator<<(ostream& os, const Variant& v) {
return os << v.data;

View File

@ -38,7 +38,6 @@ QuadTari::QuadTari(Jack jack, const OSystem& osystem, const System& system,
myOSystem{osystem},
myProperties{properties}
{
Controller::Type firstType, secondType;
string first, second;
if(jack == Controller::Jack::Left)
@ -51,7 +50,7 @@ QuadTari::QuadTari(Jack jack, const OSystem& osystem, const System& system,
first = properties.get(PropType::Controller_Right1);
second = properties.get(PropType::Controller_Right2);
}
firstType = Controller::getType(first);
Controller::Type firstType = Controller::getType(first),
secondType = Controller::getType(second);
// Autodetect QuadTari controllers:

View File

@ -134,8 +134,6 @@ void QuadTariDialog::show(bool enableLeft, bool enableRight)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void QuadTariDialog::loadControllerProperties(const Properties& props)
{
string controller;
if(myLeftPortLabel->isEnabled())
{
defineController(props, PropType::Controller_Left1, Controller::Jack::Left,
@ -160,7 +158,7 @@ void QuadTariDialog::defineController(const Properties& props, PropType key,
ByteBuffer image;
size_t size = 0;
string controllerName = props.get(key);
const string& controllerName = props.get(key);
popupWidget->setSelected(controllerName, "AUTO");
// try to load the image for auto detection
@ -173,7 +171,7 @@ void QuadTariDialog::defineController(const Properties& props, PropType key,
&& (image = instance().openROM(node, md5, size)) != nullptr;
}
string label;
Controller::Type type = Controller::getType(popupWidget->getSelectedTag().toString());
const Controller::Type type = Controller::getType(popupWidget->getSelectedTag().toString());
if(type == Controller::Type::Unknown)
{

View File

@ -323,7 +323,7 @@ bool RomImageWidget::loadPng(const string& fileName)
break;
}
if(data.first == "Software"
&& data.second.toString().find("Stella") == 0)
&& data.second.toString().starts_with("Stella"))
myLabel = "Snapshot"; // default for Stella snapshots with missing "Title" meta data
}
return true;