Skip to content

Commit

Permalink
Fixes from clang-tidy-19 that didn't make it for the last release.
Browse files Browse the repository at this point in the history
  • Loading branch information
sa666666 committed Oct 6, 2024
1 parent 18db75d commit 2d184b6
Show file tree
Hide file tree
Showing 37 changed files with 186 additions and 247 deletions.
3 changes: 1 addition & 2 deletions src/common/HighScoresManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,7 @@ string HighScoresManager::formattedScore(Int32 score, Int32 width) const

if(scoreBCD(jprops))
{
if(width > digits)
digits = width;
digits = std::max(width, digits);
buf << std::setw(digits) << std::setfill(' ') << score;
}
else {
Expand Down
41 changes: 20 additions & 21 deletions src/common/JoyMap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -188,27 +188,26 @@ json JoyMap::saveMapping(EventMode mode) const
using MapType = std::pair<JoyMapping, Event::Type>;
std::vector<MapType> sortedMap(myMap.begin(), myMap.end());

std::sort(sortedMap.begin(), sortedMap.end(),
[](const MapType& a, const MapType& b)
{
// Event::Type first
if(a.first.button != b.first.button)
return a.first.button < b.first.button;
std::ranges::sort(sortedMap, [](const MapType& a, const MapType& b)
{
// Event::Type first
if(a.first.button != b.first.button)
return a.first.button < b.first.button;

if(a.first.axis != b.first.axis)
return a.first.axis < b.first.axis;
if(a.first.axis != b.first.axis)
return a.first.axis < b.first.axis;

if(a.first.adir != b.first.adir)
return a.first.adir < b.first.adir;
if(a.first.adir != b.first.adir)
return a.first.adir < b.first.adir;

if(a.first.hat != b.first.hat)
return a.first.hat < b.first.hat;
if(a.first.hat != b.first.hat)
return a.first.hat < b.first.hat;

if(a.first.hdir != b.first.hdir)
return a.first.hdir < b.first.hdir;
if(a.first.hdir != b.first.hdir)
return a.first.hdir < b.first.hdir;

return a.second < b.second;
}
return a.second < b.second;
}
);

json eventMappings = json::array();
Expand Down Expand Up @@ -285,17 +284,17 @@ int JoyMap::loadMapping(const json& eventMappings, EventMode mode)
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
json JoyMap::convertLegacyMapping(string list)
json JoyMap::convertLegacyMapping(string lst)
{
json eventMappings = json::array();

// Since istringstream swallows whitespace, we have to make the
// delimiters be spaces
std::replace(list.begin(), list.end(), '|', ' ');
std::replace(list.begin(), list.end(), ':', ' ');
std::replace(list.begin(), list.end(), ',', ' ');
std::ranges::replace(lst, '|', ' ');
std::ranges::replace(lst, ':', ' ');
std::ranges::replace(lst, ',', ' ');

istringstream buf(list);
istringstream buf(lst);
int event = 0, button = 0, axis = 0, adir = 0, hat = 0, hdir = 0;

while(buf >> event && buf >> button
Expand Down
2 changes: 1 addition & 1 deletion src/common/JoyMap.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class JoyMap
nlohmann::json saveMapping(EventMode mode) const;
int loadMapping(const nlohmann::json& eventMappings, EventMode mode);

static nlohmann::json convertLegacyMapping(string list);
static nlohmann::json convertLegacyMapping(string lst);

/** Erase all mappings for given mode */
void eraseMode(EventMode mode);
Expand Down
13 changes: 6 additions & 7 deletions src/common/KeyMap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ json KeyMap::saveMapping(EventMode mode) const
using MapType = std::pair<Mapping, Event::Type>;
std::vector<MapType> sortedMap(myMap.begin(), myMap.end());

std::sort(sortedMap.begin(), sortedMap.end(),
[](const MapType& a, const MapType& b)
std::ranges::sort(sortedMap, [](const MapType& a, const MapType& b)
{
// Event::Type first
if(a.first.key != b.first.key)
Expand Down Expand Up @@ -290,11 +289,11 @@ json KeyMap::convertLegacyMapping(string_view lm)

// Since istringstream swallows whitespace, we have to make the
// delimiters be spaces
string list{lm};
std::replace(list.begin(), list.end(), '|', ' ');
std::replace(list.begin(), list.end(), ':', ' ');
std::replace(list.begin(), list.end(), ',', ' ');
istringstream buf(list);
string lst{lm};
std::ranges::replace(lst, '|', ' ');
std::ranges::replace(lst, ':', ' ');
std::ranges::replace(lst, ',', ' ');
istringstream buf(lst);
int event = 0, key = 0, mod = 0;

while(buf >> event && buf >> key && buf >> mod)
Expand Down
6 changes: 3 additions & 3 deletions src/common/PaletteHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@ void PaletteHandler::generateCustomPalette(ConsoleTiming timing) const
float G = Y + dotProduct(IQ[chroma], IQG);
float B = Y + dotProduct(IQ[chroma], IQB);

if(R < 0) R = 0;
if(G < 0) G = 0;
if(B < 0) B = 0;
R = std::max(R, 0.F);
G = std::max(G, 0.F);
B = std::max(B, 0.F);

R = powf(R, 0.9F);
G = powf(G, 0.9F);
Expand Down
16 changes: 8 additions & 8 deletions src/common/PhysicalJoystick.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,26 @@ json PhysicalJoystick::convertLegacyMapping(string_view mapping, string_view nam
{
istringstream buf(string{mapping}); // TODO: fixed in C++23
json convertedMapping = json::object();
string map;
string lmap;

// Skip joystick name
getline(buf, map, MODE_DELIM);
getline(buf, lmap, MODE_DELIM);

while (getline(buf, map, MODE_DELIM))
while (getline(buf, lmap, MODE_DELIM))
{
int mode{0};

// Get event mode
std::replace(map.begin(), map.end(), '|', ' ');
istringstream modeBuf(map);
std::ranges::replace(lmap, '|', ' ');
istringstream modeBuf(lmap);
modeBuf >> mode;

// Remove leading "<mode>|" string
map.erase(0, 2);
lmap.erase(0, 2);

const json mappingForMode = JoyMap::convertLegacyMapping(map);
const json lmappingForMode = JoyMap::convertLegacyMapping(lmap);

convertedMapping[jsonName(static_cast<EventMode>(mode))] = mappingForMode;
convertedMapping[jsonName(static_cast<EventMode>(mode))] = lmappingForMode;
}

convertedMapping["name"] = name;
Expand Down
4 changes: 2 additions & 2 deletions src/common/SoundSDL2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ void SoundSDL2::WavHandlerSDL2::processWav(uInt8* stream, uInt32 len)
const int newFreq =
std::round(static_cast<double>(mySpec.freq) * origLen / len);

if(len > myRemaining)
if(len > myRemaining) // NOLINT(readability-use-std-min-max)
len = myRemaining;

SDL_AudioCVT cvt;
Expand All @@ -505,7 +505,7 @@ void SoundSDL2::WavHandlerSDL2::processWav(uInt8* stream, uInt32 len)
}
else
{
if(len > myRemaining)
if(len > myRemaining) // NOLINT(readability-use-std-min-max)
len = myRemaining;

// Mix volume adjusted WAV data into silent buffer
Expand Down
2 changes: 1 addition & 1 deletion src/common/Version.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#ifndef VERSION_HXX
#define VERSION_HXX

#define STELLA_VERSION "7.0"
#define STELLA_VERSION "7.1_pre"
#define STELLA_BUILD "8005"

#endif
3 changes: 1 addition & 2 deletions src/common/ZipHandler.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ void ZipHandler::ZipFile::readEcd()
uInt64 read_length = 0;

// Max out the buf length at the size of the file
if(buflen > myLength)
buflen = myLength;
buflen = std::min(buflen, myLength);

// Allocate buffer
const ByteBuffer buffer = make_unique<uInt8[]>(buflen + 1);
Expand Down
9 changes: 5 additions & 4 deletions src/common/bspf.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ using uInt64 = uint64_t;
#include <cstdio>
#include <ctime>
#include <numbers>
#include <ranges>
#include <utility>
#include <vector>
#include <optional>
Expand Down Expand Up @@ -189,12 +190,12 @@ namespace BSPF
// Convert string to given case
inline const string& toUpperCase(string& s)
{
transform(s.begin(), s.end(), s.begin(), ::toupper);
std::ranges::transform(s, s.begin(), ::toupper);
return s;
}
inline const string& toLowerCase(string& s)
{
transform(s.begin(), s.end(), s.begin(), ::tolower);
std::ranges::transform(s, s.begin(), ::tolower);
return s;
}

Expand Down Expand Up @@ -426,9 +427,9 @@ namespace BSPF
const auto currtime = std::time(nullptr);
std::tm tm_snapshot{};
#if (defined BSPF_WINDOWS || defined __WIN32__) && (!defined __GNUG__ || defined __MINGW32__)
localtime_s(&tm_snapshot, &currtime);
std::ignore = localtime_s(&tm_snapshot, &currtime);
#else
localtime_r(&currtime, &tm_snapshot);
std::ignore = localtime_r(&currtime, &tm_snapshot);
#endif
return tm_snapshot;
}
Expand Down
66 changes: 28 additions & 38 deletions src/common/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,15 @@
#include "CheatManager.hxx"
#endif

namespace {

/**
Parse the commandline arguments and store into the appropriate hashmap.
Keys without a corresponding value are assumed to be boolean, and set to true.
Some keys are used only by the main function; these are placed in localOpts.
The rest are needed globally, and are placed in globalOpts.
*/
void parseCommandLine(int ac, const char* const av[],
Settings::Options& globalOpts, Settings::Options& localOpts);

/**
Checks the commandline for special settings that are used by various ports
to use a specific 'base directory'.
This needs to be done separately, before either an OSystem or Settings
object can be created, since they both depend on each other, and a
variable basedir implies a different location for the settings file.
This function will call OSystem::overrideBaseDir() when either of the
applicable arguments are found, and then remove them from the argument
list.
*/
void checkForCustomBaseDir(Settings::Options& options);

/**
Checks whether the commandline contains an argument corresponding to
starting a profile session.
*/
bool isProfilingRun(int ac, char* av[]);

/**
In Windows, attach console to allow command line output (e.g. for -help).
This is needed since by default Windows doesn't set up stdout/stderr
correctly.
*/
void attachConsole();
void freeConsole();


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void parseCommandLine(int ac, const char* const av[],
Settings::Options& globalOpts, Settings::Options& localOpts)
{
Expand Down Expand Up @@ -136,7 +105,18 @@ void parseCommandLine(int ac, const char* const av[],
#endif
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
Checks the commandline for special settings that are used by various ports
to use a specific 'base directory'.
This needs to be done separately, before either an OSystem or Settings
object can be created, since they both depend on each other, and a
variable basedir implies a different location for the settings file.
This function will call OSystem::overrideBaseDir() when either of the
applicable arguments are found, and then remove them from the argument
list.
*/
void checkForCustomBaseDir(Settings::Options& options)
{
// If both of these are activated, the 'base in app dir' takes precedence
Expand All @@ -150,14 +130,22 @@ void checkForCustomBaseDir(Settings::Options& options)
}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool isProfilingRun(int ac, char* av[]) {
/**
Checks whether the commandline contains an argument corresponding to
starting a profile session.
*/
bool isProfilingRun(int ac, char* av[])
{
if (ac <= 1) return false;

return string(av[1]) == "-profile";
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
In Windows, attach console to allow command line output (e.g. for -help).
This is needed since by default Windows doesn't set up stdout/stderr
correctly.
*/
void attachConsole()
{
#if defined(BSPF_WINDOWS)
Expand All @@ -183,7 +171,6 @@ void attachConsole()
#endif
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void freeConsole()
{
#if defined(BSPF_WINDOWS)
Expand All @@ -192,6 +179,9 @@ void freeConsole()
#endif
}

} // namespace


// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#if defined(BSPF_MACOS)
int stellaMain(int ac, char* av[])
Expand Down
6 changes: 4 additions & 2 deletions src/common/repository/KeyValueRepositoryFile.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
template<typename T>
class KeyValueRepositoryFile : public KeyValueRepository {
public:
explicit KeyValueRepositoryFile(const FSNode& node);

KVRMap load() override;

bool save(const KVRMap& values) override;

private:
explicit KeyValueRepositoryFile(const FSNode& node);
friend T;

protected:

const FSNode& myNode; // NOLINT: we want a reference here
Expand Down
6 changes: 4 additions & 2 deletions src/common/tv_filters/NTSCFilter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

#include "NTSCFilter.hxx"

constexpr float scaleFrom100(float x) { return (x / 50.F) - 1.F; }
constexpr uInt32 scaleTo100(float x) { return static_cast<uInt32>(50.0001F * (x + 1.F)); }
namespace {
constexpr float scaleFrom100(float x) { return (x / 50.F) - 1.F; }
constexpr uInt32 scaleTo100(float x) { return static_cast<uInt32>(50.0001F * (x + 1.F)); }
} // namespace

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
string NTSCFilter::setPreset(Preset preset)
Expand Down
Loading

0 comments on commit 2d184b6

Please sign in to comment.