mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-18 14:59:19 +02:00
refactor(sonar): use std::ranges algorithms and std::erase(_if) (cpp:S6197)
This commit is contained in:
@@ -11377,7 +11377,7 @@ void TMoverParameters::LoadFIZ_Switches(std::string const &Input)
|
||||
{
|
||||
auto &presets{PantsPreset.first};
|
||||
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, '|');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,9 +52,8 @@ sound_source::deserialize( cParser &Input, sound_type const Legacytype, int cons
|
||||
|
||||
if( false == m_soundchunks.empty() ) {
|
||||
// arrange loaded sound chunks in requested order
|
||||
std::sort(
|
||||
std::begin( m_soundchunks ), std::end( m_soundchunks ),
|
||||
[]( soundchunk_pair const &Left, soundchunk_pair const &Right ) {
|
||||
std::ranges::sort(
|
||||
m_soundchunks, []( soundchunk_pair const &Left, soundchunk_pair const &Right ) {
|
||||
return Left.second.threshold < Right.second.threshold; } );
|
||||
// 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...
|
||||
|
||||
@@ -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 +
|
||||
":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::replace(std::begin(meta->rev_company), std::end(meta->rev_company), '_', ' ');
|
||||
std::replace(std::begin(meta->texture_author), std::end(meta->texture_author), '_', ' ');
|
||||
std::replace(std::begin(meta->photo_author), std::end(meta->photo_author), '_', ' ');
|
||||
std::ranges::replace(meta->location, '_', ' ');
|
||||
std::ranges::replace(meta->rev_company, '_', ' ');
|
||||
std::ranges::replace(meta->texture_author, '_', ' ');
|
||||
std::ranges::replace(meta->photo_author, '_', ' ');
|
||||
|
||||
if (!meta->rev_date.empty() && meta->rev_date != "?") {
|
||||
std::istringstream stream(meta->rev_date);
|
||||
|
||||
@@ -29,12 +29,7 @@ light_array::insert( TDynamicObject const *Owner ) {
|
||||
void
|
||||
light_array::remove( TDynamicObject const *Owner ) {
|
||||
|
||||
data.erase(
|
||||
std::remove_if(
|
||||
data.begin(),
|
||||
data.end(),
|
||||
[=]( light_record const &light ){ return light.owner == Owner; } ),
|
||||
data.end() );
|
||||
std::erase_if( data, [=]( light_record const &light ){ return light.owner == Owner; } );
|
||||
}
|
||||
|
||||
// updates records in the collection
|
||||
|
||||
@@ -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( m_spawncount >= 1.f ) {
|
||||
// sort all particles from most to least transparent, oldest to youngest if it's a tie
|
||||
std::sort(
|
||||
std::begin( m_particles ),
|
||||
std::end( m_particles ),
|
||||
[]( smoke_particle const &Left, smoke_particle const &Right ) {
|
||||
std::ranges::sort(
|
||||
m_particles, []( smoke_particle const &Left, smoke_particle const &Right ) {
|
||||
return ( Left.opacity != Right.opacity ?
|
||||
Left.opacity < Right.opacity :
|
||||
Left.age > Right.age ); } );
|
||||
|
||||
@@ -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: translation of affected/relevant events
|
||||
auto &nodegroup { scene::Groups.group( Node->group() ).nodes };
|
||||
std::for_each(
|
||||
std::begin( nodegroup ), std::end( nodegroup ),
|
||||
[&]( auto *node ) {
|
||||
std::ranges::for_each(
|
||||
nodegroup, [&]( auto *node ) {
|
||||
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: translation of affected/relevant events
|
||||
auto &nodegroup { scene::Groups.group( Node->group() ).nodes };
|
||||
std::for_each(
|
||||
std::begin( nodegroup ), std::end( nodegroup ),
|
||||
[&]( auto *node ) {
|
||||
std::ranges::for_each(
|
||||
nodegroup, [&]( auto *node ) {
|
||||
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
|
||||
auto const &rotationcenter { Node->location() };
|
||||
auto const &nodegroup { scene::Groups.group( Node->group() ).nodes };
|
||||
std::for_each(
|
||||
std::begin( nodegroup ), std::end( nodegroup ),
|
||||
[&]( auto *node ) {
|
||||
std::ranges::for_each(
|
||||
nodegroup, [&]( auto *node ) {
|
||||
rotate_node( node, rotation );
|
||||
if( node != Node ) {
|
||||
translate_node(
|
||||
|
||||
@@ -46,11 +46,10 @@ world_environment::compute_season( int const Yearday ) {
|
||||
{ 341, "autumn:" },
|
||||
{ 366, "winter:" } };
|
||||
auto const lookup =
|
||||
std::lower_bound(
|
||||
std::begin( seasonsequence ), std::end( seasonsequence ),
|
||||
std::ranges::lower_bound(
|
||||
seasonsequence,
|
||||
std::clamp( Yearday, 1, seasonsequence.back().first ),
|
||||
[]( dayseasonpair const &Left, const int Right ) {
|
||||
return Left.first < Right; } );
|
||||
{}, &dayseasonpair::first );
|
||||
|
||||
Global.Season = lookup->second;
|
||||
// season can affect the weather so if it changes, re-calculate weather as well
|
||||
|
||||
@@ -297,7 +297,7 @@ std::string ToLower(std::string const &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;
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ std::string ToUpper(std::string const &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;
|
||||
}
|
||||
|
||||
@@ -607,7 +607,7 @@ std::string deserialize_random_set(cParser &Input, char const *Break)
|
||||
{
|
||||
|
||||
auto token{Input.getToken<std::string>(true, Break)};
|
||||
std::replace(token.begin(), token.end(), '\\', '/');
|
||||
std::ranges::replace(token, '\\', '/');
|
||||
if (token != "[")
|
||||
{
|
||||
// simple case, single token
|
||||
@@ -622,7 +622,7 @@ std::string deserialize_random_set(cParser &Input, char const *Break)
|
||||
}
|
||||
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();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -10122,8 +10122,7 @@ void TTrain::update_sounds_radio()
|
||||
if (false == m_radiomessages.empty())
|
||||
{
|
||||
// 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::end(m_radiomessages));
|
||||
std::erase_if(m_radiomessages, [](auto const &source) { return false == source.second->is_playing(); });
|
||||
}
|
||||
// adjust audibility of remaining messages based on current radio conditions
|
||||
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
|
||||
parser.getTokens();
|
||||
parser >> token;
|
||||
std::replace(token.begin(), token.end(), '\\', '/');
|
||||
std::ranges::replace(token, '\\', '/');
|
||||
if (token != "none")
|
||||
{
|
||||
// bieżąca sciezka do tekstur to dynamic/...
|
||||
|
||||
Reference in New Issue
Block a user