Skip to content

Commit

Permalink
Some C++20 additions.
Browse files Browse the repository at this point in the history
  • Loading branch information
sa666666 committed May 9, 2024
1 parent 2d57f9e commit 7a85fae
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/common/HighScoresManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 4 additions & 13 deletions src/common/Variant.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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"; }
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;
Expand Down
5 changes: 2 additions & 3 deletions src/emucore/QuadTari.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -51,8 +50,8 @@ 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);
secondType = Controller::getType(second);
Controller::Type firstType = Controller::getType(first),
secondType = Controller::getType(second);

// Autodetect QuadTari controllers:
// This will detect the same controller for 1st and 2nd controller
Expand Down
6 changes: 2 additions & 4 deletions src/gui/QuadTariDialog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/gui/RomImageWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7a85fae

Please sign in to comment.