From 693a817d5ea3a5db33244bf1bd89901120c659c9 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sat, 10 Oct 2026 17:05:09 +0200 Subject: [PATCH] refactor(sonar): make read-only local references and pointers const (cpp:S5350) --- McZapkie/Mover.cpp | 12 ++++++------ application/driveruipanels.cpp | 2 +- gl/buffer.cpp | 2 +- gl/shader.cpp | 2 +- input/drivermouseinput.cpp | 2 +- input/gamepadinput.cpp | 2 +- input/messaging.cpp | 4 ++-- launcher/deferred_image.h | 2 +- rendering/openglgeometrybank.h | 2 +- scripting/PyInt.cpp | 4 ++-- scripting/pythonscreenviewer.cpp | 12 ++++++------ vehicle/Train.cpp | 20 ++++++++++---------- widgets/perfgraphs.cpp | 2 +- widgets/time.cpp | 2 +- widgets/vehiclelist.cpp | 4 ++-- world/MemCell.cpp | 2 +- 16 files changed, 38 insertions(+), 38 deletions(-) diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 259e23d5..2290a3aa 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -1187,10 +1187,10 @@ void TMoverParameters::CollisionDetect(int const End, double const dt) return; } // shouldn't normally happen but, eh - auto &thiscoupler{Couplers[End]}; + auto const &thiscoupler{Couplers[End]}; auto *othervehicle{Neighbours[End].vehicle->MoverParameters}; auto const otherend{Neighbours[End].vehicle_end}; - auto &othercoupler{othervehicle->Couplers[otherend]}; + auto const &othercoupler{othervehicle->Couplers[otherend]}; auto velocity{V}; auto othervehiclevelocity{othervehicle->V}; @@ -1830,7 +1830,7 @@ void TMoverParameters::PowerCouplersCheck(double const /*Deltatime*/, coupling c for (auto side = 0; side < 2; ++side) { - auto &thiscoupler{Couplers[side]}; + auto const &thiscoupler{Couplers[side]}; // NOTE: in the loop we actually update the state of the coupler on the opposite end of the vehicle auto &oppositecoupler{Couplers[side == end::front ? end::rear : end::front]}; @@ -2275,7 +2275,7 @@ void TMoverParameters::PantographsCheck(double const /*Timestep*/) using enum start_t; { - auto &valve{PantsValve}; + auto const &valve{PantsValve}; auto const lowvoltagepower{valve.solenoid ? Power24vIsAvailable || Power110vIsAvailable : true}; auto const autostart{valve.start_type == automatic || valve.start_type == manualwithautofallback}; auto const manualcontrol{valve.start_type == manual || valve.start_type == manualwithautofallback}; @@ -6211,7 +6211,7 @@ double TMoverParameters::TractionForce(double dt) if (true == Mains && !SecuritySystem.is_engine_blocked()) { double ActiveInverters = 0.0; - for (auto &inv : Inverters) + for (auto const &inv : Inverters) { if (inv.IsActive) ActiveInverters += 1.0; @@ -8946,7 +8946,7 @@ double TMoverParameters::GetTrainsetVoltage(int const Coupling) const { continue; } - auto *connectedpowercoupling = (Coupling & (coupling::highvoltage | coupling::heating)) != 0 ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_high : + auto const *connectedpowercoupling = (Coupling & (coupling::highvoltage | coupling::heating)) != 0 ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_high : (Coupling & coupling::power110v) != 0 ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_110v : (Coupling & coupling::power24v) != 0 ? &thiscoupler.Connected->Couplers[thiscoupler.ConnectedNr].power_24v : nullptr; diff --git a/application/driveruipanels.cpp b/application/driveruipanels.cpp index 4d8e5152..17f8d126 100644 --- a/application/driveruipanels.cpp +++ b/application/driveruipanels.cpp @@ -1259,7 +1259,7 @@ debug_panel::update_section_scantable( std::vector &Output ) const { #ifdef WITH_UART void debug_panel::update_section_uart( std::vector &Output ) const { - uart_status *status = &UartStatus; + uart_status const *status = &UartStatus; Output.emplace_back( ("Port: " + status->port_name).c_str(), diff --git a/gl/buffer.cpp b/gl/buffer.cpp index 6a0ab032..36e84452 100644 --- a/gl/buffer.cpp +++ b/gl/buffer.cpp @@ -87,7 +87,7 @@ void gl::buffer::download(targets target, void *data, int offset, GLsizeiptr siz } else { - void *glbuf = glMapBufferRange(glenum_target(target), offset, size, GL_MAP_READ_BIT); + void const *glbuf = glMapBufferRange(glenum_target(target), offset, size, GL_MAP_READ_BIT); memcpy(data, glbuf, size); glUnmapBuffer(glenum_target(target)); } diff --git a/gl/shader.cpp b/gl/shader.cpp index 1ca66dfe..d276b6c6 100644 --- a/gl/shader.cpp +++ b/gl/shader.cpp @@ -339,7 +339,7 @@ void gl::program::init() for (auto [texturename, textureentry] : texture_conf) { - shader::texture_entry &e = textureentry; + shader::texture_entry const &e = textureentry; GLuint loc = glGetUniformLocation(*this, texturename.c_str()); glUniform1i(loc, static_cast(e.id)); } diff --git a/input/drivermouseinput.cpp b/input/drivermouseinput.cpp index 13e444ad..f7f65776 100644 --- a/input/drivermouseinput.cpp +++ b/input/drivermouseinput.cpp @@ -210,7 +210,7 @@ drivermouse_input::recall_bindings() { } // TODO: binding targets for mouse buttons - for( auto &bindingtarget : bindingtargets ) { + for( auto const &bindingtarget : bindingtargets ) { // grab command(s) associated with the input pin auto const bindingcommandname{ entryparser.getToken() }; if( true == bindingcommandname.empty() ) { diff --git a/input/gamepadinput.cpp b/input/gamepadinput.cpp index 784f714c..87e4d0f1 100644 --- a/input/gamepadinput.cpp +++ b/input/gamepadinput.cpp @@ -126,7 +126,7 @@ gamepad_input::poll() { void gamepad_input::bind( std::vector< std::reference_wrapper > &Targets, cParser &Input, std::unordered_map const &Translator, std::string const Point ) const { - for( auto &bindingtarget : Targets ) { + for( auto const &bindingtarget : Targets ) { // grab command(s) associated with the input pin auto const bindingcommandname{ Input.getToken() }; if( true == bindingcommandname.empty() ) { diff --git a/input/messaging.cpp b/input/messaging.cpp index 7680f8b2..32a33707 100644 --- a/input/messaging.cpp +++ b/input/messaging.cpp @@ -62,7 +62,7 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz) std::string( pRozkaz->cString + 1, (unsigned)pRozkaz->cString[0] ) + " rcvd" ); if( Global.iMultiplayer ) { - auto *foundevent = simulation::Events.FindEvent( std::string( pRozkaz->cString + 1, (unsigned)pRozkaz->cString[0] ) ); + auto const *foundevent = simulation::Events.FindEvent( std::string( pRozkaz->cString + 1, (unsigned)pRozkaz->cString[0] ) ); if (foundevent != nullptr && (typeid(*foundevent) == typeid(multi_event) || typeid(*foundevent) == typeid(lights_event) || foundevent->m_sibling != nullptr)) { @@ -136,7 +136,7 @@ OnCommandGet(multiplayer::DaneRozkaz *pRozkaz) + " rcvd" ); if (pRozkaz->cString[0]) { // jeśli długość nazwy jest niezerowa szukamy pierwszego pojazdu o takiej nazwie i odsyłamy parametry ramką #7 - auto *vehicle = pRozkaz->cString[1] == '*' ? simulation::Train->Dynamic() : simulation::Vehicles.find(std::string{pRozkaz->cString + 1, (unsigned)pRozkaz->cString[0]}); + auto const *vehicle = pRozkaz->cString[1] == '*' ? simulation::Train->Dynamic() : simulation::Vehicles.find(std::string{pRozkaz->cString + 1, (unsigned)pRozkaz->cString[0]}); if( vehicle != nullptr ) { WyslijNamiary( vehicle ); // wysłanie informacji o pojeździe } diff --git a/launcher/deferred_image.h b/launcher/deferred_image.h index 6ad2802a..58850fb0 100644 --- a/launcher/deferred_image.h +++ b/launcher/deferred_image.h @@ -42,7 +42,7 @@ public: glm::ivec2 size() const { if (image != null_handle) { - auto &tex = GfxRenderer->Texture(image); + auto const &tex = GfxRenderer->Texture(image); return glm::ivec2(tex.get_width(), tex.get_height()); } return glm::ivec2(); diff --git a/rendering/openglgeometrybank.h b/rendering/openglgeometrybank.h index d636a353..7d260a82 100644 --- a/rendering/openglgeometrybank.h +++ b/rendering/openglgeometrybank.h @@ -87,7 +87,7 @@ public: opengl_dlgeometrybank() = default; // destructor: ~opengl_dlgeometrybank() { - for( auto &chunkrecord : m_chunkrecords ) { + for( auto const &chunkrecord : m_chunkrecords ) { ::glDeleteLists( chunkrecord.list, 1 ); } } private: diff --git a/scripting/PyInt.cpp b/scripting/PyInt.cpp index b40e71b9..c4952e71 100644 --- a/scripting/PyInt.cpp +++ b/scripting/PyInt.cpp @@ -363,7 +363,7 @@ void python_taskqueue::exit() // which the previous code did not do (cancel() is a no-op stub). { std::scoped_lock lock(m_tasks.mutex); - for (auto &task : m_tasks.data) + for (auto const &task : m_tasks.data) { task->cancel(); } @@ -609,7 +609,7 @@ void python_taskqueue::update() { std::scoped_lock lock(m_uploadtasks.mutex); - for (auto &task : m_uploadtasks.data) + for (auto const &task : m_uploadtasks.data) task->upload(); m_uploadtasks.data.clear(); diff --git a/scripting/pythonscreenviewer.cpp b/scripting/pythonscreenviewer.cpp index d4a2843e..06fd6899 100644 --- a/scripting/pythonscreenviewer.cpp +++ b/scripting/pythonscreenviewer.cpp @@ -79,7 +79,7 @@ python_screen_viewer::~python_screen_viewer() void python_screen_viewer::threadfunc() { - for (auto &window : m_windows) { + for (auto const &window : m_windows) { glfwMakeContextCurrent(window->window); glfwSwapInterval(Global.python_vsync ? 1 : 0); @@ -115,7 +115,7 @@ void python_screen_viewer::threadfunc() { auto start_time = std::chrono::high_resolution_clock::now(); - for (auto &window : m_windows) { + for (auto const &window : m_windows) { unsigned char *image = nullptr; int format; @@ -190,7 +190,7 @@ void python_screen_viewer::threadfunc() void python_screen_viewer::notify_window_fb_size(GLFWwindow *window, int w, int h) const { - for (auto &conf : m_windows) { + for (auto const &conf : m_windows) { if (conf->window == window) { conf->fb_size.x = w; conf->fb_size.y = h; @@ -201,7 +201,7 @@ void python_screen_viewer::notify_window_fb_size(GLFWwindow *window, int w, int void python_screen_viewer::notify_window_size(GLFWwindow *window, int w, int h) const { - for (auto &conf : m_windows) { + for (auto const &conf : m_windows) { if (conf->window == window) { conf->window_size.x = w; conf->window_size.y = h; @@ -212,7 +212,7 @@ void python_screen_viewer::notify_window_size(GLFWwindow *window, int w, int h) void python_screen_viewer::notify_cursor_pos(GLFWwindow *window, double x, double y) const { - for (auto &conf : m_windows) { + for (auto const &conf : m_windows) { if (conf->window == window) { conf->cursor_pos.x = static_cast(x); conf->cursor_pos.y = static_cast(y); @@ -226,7 +226,7 @@ void python_screen_viewer::notify_click(GLFWwindow *window, int button, int acti if (button != GLFW_MOUSE_BUTTON_LEFT || action != GLFW_PRESS) return; - for (auto &conf : m_windows) { + for (auto const &conf : m_windows) { if (conf->window == window) { auto pos = glm::vec2(conf->cursor_pos) / glm::vec2(conf->window_size); pos.y = 1.0f - pos.y; diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index d358184c..0122da6f 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -2116,7 +2116,7 @@ void TTrain::OnCommand_trainbrakeoperationtoggle(TTrain *Train, command_data con if (Command.action == GLFW_PRESS) { - auto *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)}; + auto const *vehicle{Train->find_nearest_consist_vehicle(Command.freefly, Command.location)}; if (vehicle == nullptr) { return; @@ -3464,7 +3464,7 @@ void TTrain::update_pantograph_valves() using enum operation_t; auto const &presets{mvOccupied->PantsPreset.first}; - auto &selection{mvOccupied->PantsPreset.second[cab_to_end()]}; + auto const &selection{mvOccupied->PantsPreset.second[cab_to_end()]}; auto const preset{presets[selection] - '0'}; auto const swapends{cab_to_end() != end::front}; @@ -8743,7 +8743,7 @@ bool TTrain::Update(double const Deltatime) // youBy - prad w drugim czlonie: galaz lub calosc { - TDynamicObject *tmp{nullptr}; + TDynamicObject const *tmp{nullptr}; if (DynamicObject->NextConnected() && TestFlag(mvControlled->Couplers[end::rear].CouplingFlag, coupling::control) && mvOccupied->CabOccupied == 1) tmp = DynamicObject->NextConnected(); if (DynamicObject->PrevConnected() && TestFlag(mvControlled->Couplers[end::front].CouplingFlag, coupling::control) && mvOccupied->CabOccupied == -1) @@ -9169,7 +9169,7 @@ bool TTrain::Update(double const Deltatime) } { // yB - wskazniki drugiego czlonu - TDynamicObject *tmp{nullptr}; //=mvControlled->mvSecond; //Ra 2014-07: trzeba to jeszcze wyjąć z kabiny... + TDynamicObject const *tmp{nullptr}; //=mvControlled->mvSecond; //Ra 2014-07: trzeba to jeszcze wyjąć z kabiny... // Ra 2014-07: no nie ma potrzeby szukać tego w każdej klatce if (TestFlag(mvControlled->Couplers[1].CouplingFlag, coupling::control) && mvOccupied->CabOccupied > 0) tmp = DynamicObject->NextConnected(); @@ -10120,7 +10120,7 @@ void TTrain::update_sounds_radio() } // adjust audibility of remaining messages based on current radio conditions auto const radioenabled{true == mvOccupied->Radio && (mvOccupied->Power24vIsAvailable || mvOccupied->Power110vIsAvailable)}; - for (auto &[messagechannel, messagesound] : m_radiomessages) + for (auto const &[messagechannel, messagesound] : m_radiomessages) { auto const volume{true == radioenabled && Dynamic()->Mechanik != nullptr && messagechannel == RadioChannel() ? m_radiovolume : 0.0}; messagesound->gain(static_cast(volume)); @@ -10347,7 +10347,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName) dsbReverserKey, dsbNastawnikJazdy, dsbNastawnikBocz, dsbSwitch, dsbPneumaticSwitch, rsHiss, rsHissU, rsHissE, rsHissX, rsHissT, rsSBHiss, rsSBHissU, rsFadeSound, rsRunningNoise, rsResonanceNoise, rsWindSound, rsHuntingNoise, dsbHasler, dsbBuzzer, dsbBuzzerShp, dsbSlipAlarm, m_distancecounterclear, m_rainsound, m_radiostop}; - for (auto &sound : sounds) + for (auto const &sound : sounds) { if (sound.get()) { @@ -10355,7 +10355,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName) } } m_radiosound.offset(nullvector); - for (auto &[soundsource, soundoffset] : CabSoundLocations) + for (auto const &[soundsource, soundoffset] : CabSoundLocations) { if (soundsource.get() && soundsource.get()->offset() == nullvector) { @@ -10650,7 +10650,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName) {m_rainsound, caboffset}, {m_radiostop, m_radiosound.offset()}, }; - for (auto &[soundsource, soundoffset] : soundlocations) + for (auto const &[soundsource, soundoffset] : soundlocations) { if (soundsource.get() && soundsource.get()->offset() == nullvector) { @@ -10658,7 +10658,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName) } } // second pass, in case some items received no positioning due to missing submodels etc - for (auto &[soundsource, soundoffset] : soundlocations) + for (auto const &[soundsource, soundoffset] : soundlocations) { if (soundsource.get() && soundsource.get()->offset() == nullvector) { @@ -11464,7 +11464,7 @@ void TTrain::set_cab_controls(int const Cab) bool kier = DynamicObject->DirectionGet() * mvOccupied->CabOccupied > 0; int flag = DynamicObject->MoverParameters->InverterControlCouplerFlag; int itemstart = 0; - for ([[maybe_unused]] auto &item : ggInverterToggleButtons) // for each button + for ([[maybe_unused]] auto const &item : ggInverterToggleButtons) // for each button { int itemindex = itemstart; itemstart++; diff --git a/widgets/perfgraphs.cpp b/widgets/perfgraphs.cpp index e717f647..041a2513 100644 --- a/widgets/perfgraphs.cpp +++ b/widgets/perfgraphs.cpp @@ -19,7 +19,7 @@ void perfgraph_panel::render_contents() { ImGui::EndCombo(); } - Timer::stopwatch *stopwatch = nullptr; + Timer::stopwatch const *stopwatch = nullptr; if (current_timer == gfx_total) stopwatch = &Timer::subsystem.gfx_total; diff --git a/widgets/time.cpp b/widgets/time.cpp index 0d4dec35..6cf89b62 100644 --- a/widgets/time.cpp +++ b/widgets/time.cpp @@ -27,7 +27,7 @@ void ui::time_panel::render_contents() void ui::time_panel::open() { - auto &data = simulation::Time.data(); + auto const &data = simulation::Time.data(); time = (float)data.wHour + (float)data.wMinute / 60.0f; yearday = simulation::Time.year_day(); diff --git a/widgets/vehiclelist.cpp b/widgets/vehiclelist.cpp index 92f9edf1..45293fa1 100644 --- a/widgets/vehiclelist.cpp +++ b/widgets/vehiclelist.cpp @@ -12,7 +12,7 @@ ui::vehiclelist_panel::vehiclelist_panel(ui_layer &parent) void ui::vehiclelist_panel::render_contents() { if (m_first_show && Global.gui_trainingdefault) { - for (TDynamicObject *vehicle : simulation::Vehicles.sequence()) + for (TDynamicObject const *vehicle : simulation::Vehicles.sequence()) { if (!vehicle->Mechanik || vehicle->name() != ToLower(Global.local_start_vehicle)) continue; @@ -26,7 +26,7 @@ void ui::vehiclelist_panel::render_contents() return; } - for (TDynamicObject *vehicle : simulation::Vehicles.sequence()) + for (TDynamicObject const *vehicle : simulation::Vehicles.sequence()) { if (!vehicle->Mechanik) continue; diff --git a/world/MemCell.cpp b/world/MemCell.cpp index b6a79183..614df1a9 100644 --- a/world/MemCell.cpp +++ b/world/MemCell.cpp @@ -280,7 +280,7 @@ memory_table::InitCells() const { void memory_table::log_all() const { - for( auto *cell : m_items ) { + for( auto const *cell : m_items ) { cell->LogValues(); } }