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

refactor(sonar): use std::ranges algorithms and std::erase(_if) (cpp:S6197)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jerrrrycho
2026-10-10 16:24:06 +02:00
parent 22c7c33a63
commit 51337cb1b7
9 changed files with 25 additions and 38 deletions

View File

@@ -11377,7 +11377,7 @@ void TMoverParameters::LoadFIZ_Switches(std::string const &Input)
{ {
auto &presets{PantsPreset.first}; auto &presets{PantsPreset.first};
extract_value(presets, "PantographPresets", Input, "0|1|3|2"); extract_value(presets, "PantographPresets", Input, "0|1|3|2");
presets.erase(std::remove(std::begin(presets), std::end(presets), '|'), std::end(presets)); std::erase(presets, '|');
} }
} }

View File

@@ -52,9 +52,8 @@ sound_source::deserialize( cParser &Input, sound_type const Legacytype, int cons
if( false == m_soundchunks.empty() ) { if( false == m_soundchunks.empty() ) {
// arrange loaded sound chunks in requested order // arrange loaded sound chunks in requested order
std::sort( std::ranges::sort(
std::begin( m_soundchunks ), std::end( m_soundchunks ), m_soundchunks, []( soundchunk_pair const &Left, soundchunk_pair const &Right ) {
[]( soundchunk_pair const &Left, soundchunk_pair const &Right ) {
return Left.second.threshold < Right.second.threshold; } ); return Left.second.threshold < Right.second.threshold; } );
// calculate and cache full range points for each chunk, including crossfade sections: // calculate and cache full range points for each chunk, including crossfade sections:
// on the far end the crossfade section extends to the threshold point of the next chunk... // on the far end the crossfade section extends to the threshold point of the next chunk...

View File

@@ -172,10 +172,10 @@ std::shared_ptr<ui::skin_meta> ui::vehicles_bank::parse_meta(const std::string &
ToLower("n:" + meta->name + ":i:" + meta->short_id + ":d:" + meta->location + ToLower("n:" + meta->name + ":i:" + meta->short_id + ":d:" + meta->location +
":r:" + meta->rev_date + ":c:" + meta->rev_company + ":t:" + meta->texture_author + ":p:" + meta->photo_author); ":r:" + meta->rev_date + ":c:" + meta->rev_company + ":t:" + meta->texture_author + ":p:" + meta->photo_author);
std::replace(std::begin(meta->location), std::end(meta->location), '_', ' '); std::ranges::replace(meta->location, '_', ' ');
std::replace(std::begin(meta->rev_company), std::end(meta->rev_company), '_', ' '); std::ranges::replace(meta->rev_company, '_', ' ');
std::replace(std::begin(meta->texture_author), std::end(meta->texture_author), '_', ' '); std::ranges::replace(meta->texture_author, '_', ' ');
std::replace(std::begin(meta->photo_author), std::end(meta->photo_author), '_', ' '); std::ranges::replace(meta->photo_author, '_', ' ');
if (!meta->rev_date.empty() && meta->rev_date != "?") { if (!meta->rev_date.empty() && meta->rev_date != "?") {
std::istringstream stream(meta->rev_date); std::istringstream stream(meta->rev_date);

View File

@@ -29,12 +29,7 @@ light_array::insert( TDynamicObject const *Owner ) {
void void
light_array::remove( TDynamicObject const *Owner ) { light_array::remove( TDynamicObject const *Owner ) {
data.erase( std::erase_if( data, [=]( light_record const &light ){ return light.owner == Owner; } );
std::remove_if(
data.begin(),
data.end(),
[=]( light_record const &light ){ return light.owner == Owner; } ),
data.end() );
} }
// updates records in the collection // updates records in the collection

View File

@@ -254,10 +254,8 @@ smoke_source::update( double const Timedelta, bool const Onlydespawn ) {
// if we still have pending requests after filling entire container replace older particles // if we still have pending requests after filling entire container replace older particles
if( m_spawncount >= 1.f ) { if( m_spawncount >= 1.f ) {
// sort all particles from most to least transparent, oldest to youngest if it's a tie // sort all particles from most to least transparent, oldest to youngest if it's a tie
std::sort( std::ranges::sort(
std::begin( m_particles ), m_particles, []( smoke_particle const &Left, smoke_particle const &Right ) {
std::end( m_particles ),
[]( smoke_particle const &Left, smoke_particle const &Right ) {
return ( Left.opacity != Right.opacity ? return ( Left.opacity != Right.opacity ?
Left.opacity < Right.opacity : Left.opacity < Right.opacity :
Left.age > Right.age ); } ); Left.age > Right.age ); } );

View File

@@ -50,9 +50,8 @@ basic_editor::translate( scene::basic_node *Node, glm::dvec3 const &Location, bo
// TODO: contextual switch between group and item translation // TODO: contextual switch between group and item translation
// TODO: translation of affected/relevant events // TODO: translation of affected/relevant events
auto &nodegroup { scene::Groups.group( Node->group() ).nodes }; auto &nodegroup { scene::Groups.group( Node->group() ).nodes };
std::for_each( std::ranges::for_each(
std::begin( nodegroup ), std::end( nodegroup ), nodegroup, [&]( auto *node ) {
[&]( auto *node ) {
translate_node( node, node->location() + translation ); } ); translate_node( node, node->location() + translation ); } );
} }
} }
@@ -72,9 +71,8 @@ basic_editor::translate( scene::basic_node *Node, float const Offset ) {
// TODO: contextual switch between group and item translation // TODO: contextual switch between group and item translation
// TODO: translation of affected/relevant events // TODO: translation of affected/relevant events
auto &nodegroup { scene::Groups.group( Node->group() ).nodes }; auto &nodegroup { scene::Groups.group( Node->group() ).nodes };
std::for_each( std::ranges::for_each(
std::begin( nodegroup ), std::end( nodegroup ), nodegroup, [&]( auto *node ) {
[&]( auto *node ) {
translate_node( node, offset ); } ); translate_node( node, offset ); } );
} }
} }
@@ -161,9 +159,8 @@ basic_editor::rotate( scene::basic_node *Node, glm::vec3 const &Angle, float con
// TODO: translation of affected/relevant events // TODO: translation of affected/relevant events
auto const &rotationcenter { Node->location() }; auto const &rotationcenter { Node->location() };
auto const &nodegroup { scene::Groups.group( Node->group() ).nodes }; auto const &nodegroup { scene::Groups.group( Node->group() ).nodes };
std::for_each( std::ranges::for_each(
std::begin( nodegroup ), std::end( nodegroup ), nodegroup, [&]( auto *node ) {
[&]( auto *node ) {
rotate_node( node, rotation ); rotate_node( node, rotation );
if( node != Node ) { if( node != Node ) {
translate_node( translate_node(

View File

@@ -46,11 +46,10 @@ world_environment::compute_season( int const Yearday ) {
{ 341, "autumn:" }, { 341, "autumn:" },
{ 366, "winter:" } }; { 366, "winter:" } };
auto const lookup = auto const lookup =
std::lower_bound( std::ranges::lower_bound(
std::begin( seasonsequence ), std::end( seasonsequence ), seasonsequence,
std::clamp( Yearday, 1, seasonsequence.back().first ), std::clamp( Yearday, 1, seasonsequence.back().first ),
[]( dayseasonpair const &Left, const int Right ) { {}, &dayseasonpair::first );
return Left.first < Right; } );
Global.Season = lookup->second; Global.Season = lookup->second;
// season can affect the weather so if it changes, re-calculate weather as well // season can affect the weather so if it changes, re-calculate weather as well

View File

@@ -297,7 +297,7 @@ std::string ToLower(std::string const &text)
{ {
auto lowercase{text}; auto lowercase{text};
std::transform(std::begin(text), std::end(text), std::begin(lowercase), [](unsigned char c) { return std::tolower(c); }); std::ranges::transform(text, std::begin(lowercase), [](unsigned char c) { return std::tolower(c); });
return lowercase; return lowercase;
} }
@@ -305,7 +305,7 @@ std::string ToUpper(std::string const &text)
{ {
auto uppercase{text}; auto uppercase{text};
std::transform(std::begin(text), std::end(text), std::begin(uppercase), [](unsigned char c) { return std::toupper(c); }); std::ranges::transform(text, std::begin(uppercase), [](unsigned char c) { return std::toupper(c); });
return uppercase; return uppercase;
} }
@@ -607,7 +607,7 @@ std::string deserialize_random_set(cParser &Input, char const *Break)
{ {
auto token{Input.getToken<std::string>(true, Break)}; auto token{Input.getToken<std::string>(true, Break)};
std::replace(token.begin(), token.end(), '\\', '/'); std::ranges::replace(token, '\\', '/');
if (token != "[") if (token != "[")
{ {
// simple case, single token // simple case, single token
@@ -622,7 +622,7 @@ std::string deserialize_random_set(cParser &Input, char const *Break)
} }
if (false == tokens.empty()) if (false == tokens.empty())
{ {
std::shuffle(std::begin(tokens), std::end(tokens), Global.random_engine); std::ranges::shuffle(tokens, Global.random_engine);
return tokens.front(); return tokens.front();
} }
else else

View File

@@ -10122,8 +10122,7 @@ void TTrain::update_sounds_radio()
if (false == m_radiomessages.empty()) if (false == m_radiomessages.empty())
{ {
// erase completed radio messages from the list // erase completed radio messages from the list
m_radiomessages.erase(std::remove_if(std::begin(m_radiomessages), std::end(m_radiomessages), [](auto const &source) { return false == source.second->is_playing(); }), std::erase_if(m_radiomessages, [](auto const &source) { return false == source.second->is_playing(); });
std::end(m_radiomessages));
} }
// adjust audibility of remaining messages based on current radio conditions // adjust audibility of remaining messages based on current radio conditions
auto const radioenabled{true == mvOccupied->Radio && (mvOccupied->Power24vIsAvailable || mvOccupied->Power110vIsAvailable)}; auto const radioenabled{true == mvOccupied->Radio && (mvOccupied->Power24vIsAvailable || mvOccupied->Power110vIsAvailable)};
@@ -10472,7 +10471,7 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
// model kabiny // model kabiny
parser.getTokens(); parser.getTokens();
parser >> token; parser >> token;
std::replace(token.begin(), token.end(), '\\', '/'); std::ranges::replace(token, '\\', '/');
if (token != "none") if (token != "none")
{ {
// bieżąca sciezka do tekstur to dynamic/... // bieżąca sciezka do tekstur to dynamic/...