17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 02:49:19 +02:00

refactor: sonar c++20 changes (#185)

This commit is contained in:
jerrrrycho
2026-09-28 21:08:15 +02:00
committed by GitHub
parent 4137f5504a
commit 176427f96b
18 changed files with 111 additions and 106 deletions

View File

@@ -18,6 +18,7 @@ http://mozilla.org/MPL/2.0/.
#include "simulation/simulationenvironment.h"
#include "vehicle/Driver.h"
#include "utilities/Logs.h"
#include "utilities/utilities.h"
#include "Console.h"
#include "scripting/PyInt.h"
#include "utilities/Timer.h"
@@ -26,15 +27,7 @@ http://mozilla.org/MPL/2.0/.
void global_settings::LoadIniFile(std::string asFileName)
{
// initialize season data in case the main config file doesn't
std::time_t timenow = std::time(nullptr);
std::tm tm{};
#ifdef _WIN32
localtime_s(&tm, &timenow);
#else
localtime_r(&timenow, &tm);
#endif
std::tm const tm = local_tm(std::time(nullptr));
fMoveLight = tm.tm_yday + 1; // numer bieżącego dnia w roku
simulation::Environment.compute_season(fMoveLight);
@@ -513,14 +506,7 @@ bool global_settings::ConfigParseSimulation(cParser& Parser, const std::string&
if (fMoveLight == 0.f)
{
std::time_t timenow = std::time(nullptr);
std::tm tm{};
#ifdef _WIN32
localtime_s(&tm, &timenow);
#else
localtime_r(&timenow, &tm);
#endif
std::tm const tm = local_tm(std::time(nullptr));
fMoveLight = tm.tm_yday + 1;
}

View File

@@ -31,7 +31,8 @@ std::string filename_date() {
#ifdef __unix__
timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
tm *tms = localtime(&ts.tv_sec);
std::tm const tm = local_tm(ts.tv_sec);
std::tm const *tms = &tm;
st.wYear = tms->tm_year;
st.wMonth = tms->tm_mon;
st.wDayOfWeek = tms->tm_wday;

View File

@@ -426,6 +426,28 @@ std::time_t last_modified(std::string const &Filename)
return 0;
}
std::tm local_tm(std::time_t Time)
{
std::tm tm{};
#ifdef _WIN32
localtime_s(&tm, &Time);
#else
localtime_r(&Time, &tm);
#endif
return tm;
}
std::tm utc_tm(std::time_t Time)
{
std::tm tm{};
#ifdef _WIN32
gmtime_s(&tm, &Time);
#else
gmtime_r(&Time, &tm);
#endif
return tm;
}
// potentially erases file extension from provided file name. returns: true if extension was removed, false otherwise
bool erase_extension(std::string &Filename)
{

View File

@@ -220,6 +220,10 @@ std::pair<std::string, std::string> FileExists(std::vector<std::string> const &N
// returns time of last modification for specified file
std::time_t last_modified(std::string const &Filename);
// thread-safe replacements for std::localtime and std::gmtime, which hand out a pointer to shared static storage
std::tm local_tm(std::time_t Time);
std::tm utc_tm(std::time_t Time);
// potentially erases file extension from provided file name. returns: true if extension was removed, false otherwise
bool erase_extension(std::string &Filename);