17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-06 05:48:35 +01:00

refactor(sonar): assorted small fixes

- empty() instead of size() comparisons (cpp:S1155)
- member initialisers in declaration order (cpp:S3229)
- no redundant c_str() when a std::string is accepted (cpp:S7121)
- contains() on associative containers (cpp:S6171)
- const reference instead of a copying range-for (cpp:S6032)
- starts_with() for prefix checks (cpp:S6178)
- no std::move on temporaries (cpp:S5274)
- has_value() on std::optional (cpp:S7172)
- bool literals for bool members (cpp:S5820)
- inline only on the definition (cpp:S3548)
- explicit base access specifier (cpp:S5965)
- explicit element access instead of dereferencing an array (cpp:S7116)
- rely on the C++20 rewritten operator!= (cpp:S6186)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jerrrrycho
2026-10-10 17:50:12 +02:00
parent 2e92076e21
commit b6186ced21
16 changed files with 28 additions and 29 deletions

View File

@@ -1882,9 +1882,9 @@ class TMoverParameters
double MED_Vmin = 0; // predkosc minimalna dla obliczen chwilowej sily hamowania EP w MED double MED_Vmin = 0; // predkosc minimalna dla obliczen chwilowej sily hamowania EP w MED
double MED_Vref = 0; // predkosc referencyjna dla obliczen dostepnej sily hamowania EP w MED double MED_Vref = 0; // predkosc referencyjna dla obliczen dostepnej sily hamowania EP w MED
double MED_amax{9.81}; // maksymalne opoznienie hamowania sluzbowego MED double MED_amax{9.81}; // maksymalne opoznienie hamowania sluzbowego MED
bool MED_EPVC = 0; // czy korekcja sily hamowania EP, gdy nie ma dostepnego ED bool MED_EPVC = false; // czy korekcja sily hamowania EP, gdy nie ma dostepnego ED
double MED_EPVC_Time = 7; // czas korekcji sily hamowania EP, gdy nie ma dostepnego ED double MED_EPVC_Time = 7; // czas korekcji sily hamowania EP, gdy nie ma dostepnego ED
bool MED_Ncor = 0; // czy korekcja sily hamowania z uwzglednieniem nacisku bool MED_Ncor = false; // czy korekcja sily hamowania z uwzglednieniem nacisku
double MED_MinBrakeReqED = 0; // minimalne zadanie sily hamowania uruchamiajace ED - ponizej tylko EP double MED_MinBrakeReqED = 0; // minimalne zadanie sily hamowania uruchamiajace ED - ponizej tylko EP
double MED_FrED_factor = 1; // mnoznik sily hamowania ED do korekty blendingu double MED_FrED_factor = 1; // mnoznik sily hamowania ED do korekty blendingu
double MED_ED_Delay1 = 0; // opoznienie wdrazania hamowania ED (pierwszy raz) double MED_ED_Delay1 = 0; // opoznienie wdrazania hamowania ED (pierwszy raz)

View File

@@ -256,7 +256,7 @@ void TSecuritySystem::load(std::string const &line, double Vmax)
double TableInterpolation(std::map<double, double> &Map, double Parameter) double TableInterpolation(std::map<double, double> &Map, double Parameter)
{ {
if (Map.size() == 0) if (Map.empty())
return 0.0; return 0.0;
if (Map.size() == 1) if (Map.size() == 1)
return Map.begin()->second; return Map.begin()->second;
@@ -7868,7 +7868,7 @@ double TMoverParameters::dizel_fillcheck(int mcp, double dt)
else else
dizel_nreg_min = dizel_nmin; dizel_nreg_min = dizel_nmin;
} }
if (dizel_vel2nmax_Table.size() > 0 && !hydro_TC_Lockup) if (!dizel_vel2nmax_Table.empty() && !hydro_TC_Lockup)
{ {
dizel_nreg_max = std::min(std::min(dizel_nreg_max, enrot) + dizel_nreg_acc * dt, TableInterpolation(dizel_vel2nmax_Table, Vel)); dizel_nreg_max = std::min(std::min(dizel_nreg_max, enrot) + dizel_nreg_acc * dt, TableInterpolation(dizel_vel2nmax_Table, Vel));
} }

View File

@@ -213,7 +213,7 @@ void gl::shader::parse_texture_entries(std::string &str)
{ {
std::string comp; std::string comp;
token_ss >> comp; token_ss >> comp;
if (components_mapping.find(comp) == components_mapping.end()) if (!components_mapping.contains(comp))
log_error("unknown components: " + comp); log_error("unknown components: " + comp);
else else
conf.components = components_mapping[comp]; conf.components = components_mapping[comp];
@@ -271,7 +271,7 @@ void gl::shader::parse_param_entries(std::string &str)
{ {
std::string tok; std::string tok;
token_ss >> tok; token_ss >> tok;
if (defaultparams_mapping.find(tok) == defaultparams_mapping.end()) if (!defaultparams_mapping.contains(tok))
log_error("unknown param default: " + tok); log_error("unknown param default: " + tok);
conf.defaultparam = defaultparams_mapping[tok]; conf.defaultparam = defaultparams_mapping[tok];
} }
@@ -337,7 +337,7 @@ void gl::program::init()
{ {
bind(); bind();
for (auto [texturename, textureentry] : texture_conf) for (auto const &[texturename, textureentry] : texture_conf)
{ {
shader::texture_entry const &e = textureentry; shader::texture_entry const &e = textureentry;
GLuint loc = glGetUniformLocation(*this, texturename.c_str()); GLuint loc = glGetUniformLocation(*this, texturename.c_str());

View File

@@ -6,7 +6,7 @@
namespace gl namespace gl
{ {
class vao : object, public bindable<vao> class vao : private object, public bindable<vao>
{ {
struct attrib_params { struct attrib_params {
// TBD: should be shared_ptr? (when buffer is destroyed by owner VAO could still potentially exist) // TBD: should be shared_ptr? (when buffer is destroyed by owner VAO could still potentially exist)

View File

@@ -174,7 +174,7 @@ drivermouse_input::recall_bindings() {
if (fs::path appPath = user_config_path("eu07_input-mouse.ini"); !appPath.empty() && fs::exists(appPath)) if (fs::path appPath = user_config_path("eu07_input-mouse.ini"); !appPath.empty() && fs::exists(appPath))
filePath = appPath.string(); filePath = appPath.string();
cParser bindingparser(filePath.c_str(), cParser::buffer_FILE); cParser bindingparser(filePath, cParser::buffer_FILE);
if (false == bindingparser.ok()) { if (false == bindingparser.ok()) {
return false; return false;

View File

@@ -157,7 +157,7 @@ gamepad_input::recall_bindings() {
filePath = appPath.string(); filePath = appPath.string();
// bindingparser tworzony zawsze, z wybran<61> <20>cie<69>k<EFBFBD> // bindingparser tworzony zawsze, z wybran<61> <20>cie<69>k<EFBFBD>
cParser bindingparser(filePath.c_str(), cParser::buffer_FILE); cParser bindingparser(filePath, cParser::buffer_FILE);
if( false == bindingparser.ok() ) { if( false == bindingparser.ok() ) {
return false; return false;

View File

@@ -136,7 +136,7 @@ keyboard_input::recall_bindings() {
// Fallback <20> plik w folderze symulatora // Fallback <20> plik w folderze symulatora
path = "eu07_input-keyboard.ini"; path = "eu07_input-keyboard.ini";
} }
cParser bindingparser(path.c_str(), cParser::buffer_FILE); cParser bindingparser(path, cParser::buffer_FILE);
bindingparser.skipComments = false; bindingparser.skipComments = false;
if( false == bindingparser.ok() ) { if( false == bindingparser.ok() ) {

View File

@@ -108,9 +108,9 @@ OnCommandGet(multiplayer::DaneRozkaz const *pRozkaz)
break; break;
case 5: // ustawienie parametrów case 5: // ustawienie parametrów
{ {
CommLog(Now() + " " + std::to_string(pRozkaz->iComm) + " params " + std::to_string(*pRozkaz->iPar) + " rcvd"); CommLog(Now() + " " + std::to_string(pRozkaz->iComm) + " params " + std::to_string(pRozkaz->iPar[0]) + " rcvd");
// sprawdzenie czasu // sprawdzenie czasu
if (*pRozkaz->iPar == 0 && *pRozkaz->iPar & 1) // ustawienie czasu if (pRozkaz->iPar[0] == 0 && pRozkaz->iPar[0] & 1) // ustawienie czasu
{ {
auto t = pRozkaz->fPar[1]; auto t = pRozkaz->fPar[1];
simulation::Time.data().wDay = static_cast<uint16_t>(std::floor(t)); // niby nie powinno być dnia, ale... simulation::Time.data().wDay = static_cast<uint16_t>(std::floor(t)); // niby nie powinno być dnia, ale...
@@ -120,7 +120,7 @@ OnCommandGet(multiplayer::DaneRozkaz const *pRozkaz)
simulation::Time.data().wMinute = static_cast<uint16_t>(std::floor(60 * 24 * t) - 60.0 * (24.0 * simulation::Time.data().wDay + simulation::Time.data().wHour)); simulation::Time.data().wMinute = static_cast<uint16_t>(std::floor(60 * 24 * t) - 60.0 * (24.0 * simulation::Time.data().wDay + simulation::Time.data().wHour));
simulation::Time.data().wSecond = static_cast<uint16_t>(std::floor( 60 * 60 * 24 * t ) - 60.0 * ( 60.0 * ( 24.0 * simulation::Time.data().wDay + simulation::Time.data().wHour ) + simulation::Time.data().wMinute )); simulation::Time.data().wSecond = static_cast<uint16_t>(std::floor( 60 * 60 * 24 * t ) - 60.0 * ( 60.0 * ( 24.0 * simulation::Time.data().wDay + simulation::Time.data().wHour ) + simulation::Time.data().wMinute ));
} }
if (*pRozkaz->iPar & 2) if (pRozkaz->iPar[0] & 2)
{ // ustawienie flag zapauzowania { // ustawienie flag zapauzowania
Global.iPause = static_cast<int>(pRozkaz->fPar[2]); // zakładamy, że wysyłający wie, co robi Global.iPause = static_cast<int>(pRozkaz->fPar[2]); // zakładamy, że wysyłający wie, co robi
} }

View File

@@ -47,7 +47,7 @@ void ui::vehicles_bank::parse_entry(const std::string &line)
if (line[0] == '!') if (line[0] == '!')
parse_category_entry(param); parse_category_entry(param);
else if (line[0] == '*' && line[1] == '*') else if (line.starts_with("**"))
parse_texture_rule(target.substr(2), param); parse_texture_rule(target.substr(2), param);
else if (line[0] == '*') else if (line[0] == '*')
parse_coupling_rule(target.substr(1), param); parse_coupling_rule(target.substr(1), param);
@@ -124,12 +124,12 @@ void ui::vehicles_bank::parse_texture_info(const std::string &target, const std:
set.meta = meta; set.meta = meta;
if (!mini.empty()) if (!mini.empty())
group_icons.try_emplace(mini, std::move(deferred_image("textures/mini/" + ToLower(mini) + ".bmp"))); group_icons.try_emplace(mini, deferred_image("textures/mini/" + ToLower(mini) + ".bmp"));
if (!miniplus.empty()) if (!miniplus.empty())
set.mini = std::move(deferred_image("textures/mini/" + ToLower(miniplus) + ".bmp")); set.mini = deferred_image("textures/mini/" + ToLower(miniplus) + ".bmp");
else if (!mini.empty()) else if (!mini.empty())
set.mini = std::move(deferred_image("textures/mini/" + ToLower(mini) + ".bmp")); set.mini = deferred_image("textures/mini/" + ToLower(mini) + ".bmp");
set.skin = ToLower(target); set.skin = ToLower(target);
erase_extension(set.skin); erase_extension(set.skin);

View File

@@ -111,7 +111,7 @@ void network::tcp::connection::write_message(const message &msg, std::ostream &s
void network::tcp::connection::send_messages(const std::vector<std::shared_ptr<message> > &messages) void network::tcp::connection::send_messages(const std::vector<std::shared_ptr<message> > &messages)
{ {
if (messages.size() == 0) if (messages.empty())
return; return;
std::ostringstream stream; std::ostringstream stream;
@@ -173,7 +173,7 @@ void network::tcp::server::handle_accept(std::shared_ptr<connection> conn, const
// ------------------ // ------------------
network::tcp::client::client(asio::io_context &io_ctxx, const std::string &hostarg, uint32_t portarg) network::tcp::client::client(asio::io_context &io_ctxx, const std::string &hostarg, uint32_t portarg)
: host(hostarg), port(portarg), io_ctx(io_ctxx) : io_ctx(io_ctxx), host(hostarg), port(portarg)
{ {
} }

View File

@@ -26,7 +26,6 @@ struct node_snapshot {
}; };
inline bool operator==( node_snapshot const &Left, node_snapshot const &Right ) { return Left.node == Right.node && Left.data == Right.data; } inline bool operator==( node_snapshot const &Left, node_snapshot const &Right ) { return Left.node == Right.node && Left.data == Right.data; }
inline bool operator!=( node_snapshot const &Left, node_snapshot const &Right ) { return !(Left == Right); }
class basic_editor { class basic_editor {

View File

@@ -245,7 +245,7 @@ public:
e[i + 2] = f; // zamiana Y i Z e[i + 2] = f; // zamiana Y i Z
} }
}; };
inline float4x4 &Rotation(float const angle, float3 const &axis); float4x4 &Rotation(float const angle, float3 const &axis);
inline bool IdentityIs() const inline bool IdentityIs() const
{ // sprawdzenie jednostkowości { // sprawdzenie jednostkowości
for (int i = 0; i < 16; ++i) for (int i = 0; i < 16; ++i)

View File

@@ -207,7 +207,7 @@ void Error(const std::string &asMessage, bool /*box*/)
{ {
// if (box) // if (box)
// MessageBox(NULL, asMessage.c_str(), string("EU07 " + Global.asRelease).c_str(), MB_OK); // MessageBox(NULL, asMessage.c_str(), string("EU07 " + Global.asRelease).c_str(), MB_OK);
ErrorLog(asMessage.c_str()); ErrorLog(asMessage);
} }
void Error(const char *&asMessage, bool /*box*/) void Error(const char *&asMessage, bool /*box*/)

View File

@@ -195,7 +195,7 @@ uart_input::recall_bindings() {
if (fs::path appPath = user_config_path("eu07_input-uart.ini"); !appPath.empty() && fs::exists(appPath)) if (fs::path appPath = user_config_path("eu07_input-uart.ini"); !appPath.empty() && fs::exists(appPath))
filePath = appPath.string(); filePath = appPath.string();
cParser bindingparser(filePath.c_str(), cParser::buffer_FILE); cParser bindingparser(filePath, cParser::buffer_FILE);
if (false == bindingparser.ok()) if (false == bindingparser.ok())
{ {
return false; return false;
@@ -282,7 +282,7 @@ void uart_input::poll()
} }
/* handle port change */ /* handle port change */
if(status->available_ports.size() > 0 && status->selected_port_index >= 0 && status->active_port_index != status->selected_port_index) { if(!status->available_ports.empty() && status->selected_port_index >= 0 && status->active_port_index != status->selected_port_index) {
status->port_name = status->available_ports[status->selected_port_index]; status->port_name = status->available_ports[status->selected_port_index];
status->active_port_index = status->selected_port_index; status->active_port_index = status->selected_port_index;
status->reset_stats(); status->reset_stats();

View File

@@ -79,7 +79,7 @@ std::string control_mapper::find(TSubModel const *Control) const
bool control_mapper::contains(std::string const &Control) const bool control_mapper::contains(std::string const &Control) const
{ {
return m_names.find(Control) != m_names.end(); return m_names.contains(Control);
} }
void TTrain::screen_entry::deserialize(cParser &Input) void TTrain::screen_entry::deserialize(cParser &Input)

View File

@@ -119,7 +119,7 @@ void trainingcard_panel::render_contents()
ImGui::EndPopup(); ImGui::EndPopup();
} }
if (start_time_wall) if (start_time_wall.has_value())
{ {
std::tm const tm = local_tm(*start_time_wall); std::tm const tm = local_tm(*start_time_wall);
std::string rep = "Czas rozpoczęcia: " + std::to_string(tm.tm_year + 1900) + "-" + std::to_string(tm.tm_mon + 1) + "-" + std::to_string(tm.tm_mday) + " " + std::to_string(tm.tm_hour) + std::string rep = "Czas rozpoczęcia: " + std::to_string(tm.tm_year + 1900) + "-" + std::to_string(tm.tm_mon + 1) + "-" + std::to_string(tm.tm_mday) + " " + std::to_string(tm.tm_hour) +
@@ -154,7 +154,7 @@ void trainingcard_panel::render_contents()
ImGui::TextUnformatted("Uwagi"); ImGui::TextUnformatted("Uwagi");
ImGui::InputTextMultiline("##remarks", &remarks[0], remarks.size(), ImVec2(-1.0f, 200.0f)); ImGui::InputTextMultiline("##remarks", &remarks[0], remarks.size(), ImVec2(-1.0f, 200.0f));
if (!start_time_wall) if (!start_time_wall.has_value())
{ {
if (ImGui::Button("Rozpocznij szkolenie")) if (ImGui::Button("Rozpocznij szkolenie"))
{ {
@@ -189,7 +189,7 @@ void trainingcard_panel::render_contents()
const std::string *trainingcard_panel::is_recording() const const std::string *trainingcard_panel::is_recording() const
{ {
if (!start_time_wall) if (!start_time_wall.has_value())
return nullptr; return nullptr;
return &recording_timestamp; return &recording_timestamp;