17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-03 21:12:07 +01:00

refactor(sonar): reduce enum qualification with using enum (cpp:S6177)

Applied only where no unqualified name in the block could be captured by
the introduced enumerators.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jerrrrycho
2026-10-10 16:49:01 +02:00
parent a47c2a6ea0
commit 8afb232f2a
14 changed files with 887 additions and 846 deletions

View File

@@ -2173,11 +2173,12 @@ void TMoverParameters::WaterHeaterCheck(double const /*Timestep*/)
// fuel pump status update
void TMoverParameters::FuelPumpCheck(double const /*Timestep*/)
{
using enum start_t;
FuelPump.is_active = true == (Power24vIsAvailable || Power110vIsAvailable) && false == FuelPump.is_disabled &&
(FuelPump.is_active || (FuelPump.start_type == start_t::manual ? FuelPump.is_enabled :
FuelPump.start_type == start_t::automatic ? dizel_startup || Mains :
FuelPump.start_type == start_t::manualwithautofallback ? FuelPump.is_enabled || dizel_startup || Mains :
(FuelPump.is_active || (FuelPump.start_type == manual ? FuelPump.is_enabled :
FuelPump.start_type == automatic ? dizel_startup || Mains :
FuelPump.start_type == manualwithautofallback ? FuelPump.is_enabled || dizel_startup || Mains :
false)); // shouldn't ever get this far but, eh
}
@@ -2272,12 +2273,13 @@ void TMoverParameters::MotorBlowersCheck(double const Timestep)
void TMoverParameters::PantographsCheck(double const /*Timestep*/)
{
using enum start_t;
{
auto &valve{PantsValve};
auto const lowvoltagepower{valve.solenoid ? Power24vIsAvailable || Power110vIsAvailable : true};
auto const autostart{valve.start_type == start_t::automatic || valve.start_type == start_t::manualwithautofallback};
auto const manualcontrol{valve.start_type == start_t::manual || valve.start_type == start_t::manualwithautofallback};
auto const autostart{valve.start_type == automatic || valve.start_type == manualwithautofallback};
auto const manualcontrol{valve.start_type == manual || valve.start_type == manualwithautofallback};
PantsValve.is_active = (valve.spring ? lowvoltagepower : true) // spring actuator needs power to maintain non-default state
&& (manualcontrol && lowvoltagepower ? false == valve.is_disabled : true) // needs power to change state
@@ -2292,8 +2294,8 @@ void TMoverParameters::PantographsCheck(double const /*Timestep*/)
auto &valve{pantograph.valve};
auto const lowvoltagepower{valve.solenoid ? Power24vIsAvailable || Power110vIsAvailable : true};
auto const autostart{valve.start_type == start_t::automatic || valve.start_type == start_t::manualwithautofallback};
auto const manualcontrol{valve.start_type == start_t::manual || valve.start_type == start_t::manualwithautofallback};
auto const autostart{valve.start_type == automatic || valve.start_type == manualwithautofallback};
auto const manualcontrol{valve.start_type == manual || valve.start_type == manualwithautofallback};
valve.is_active = (valve.spring ? lowvoltagepower : true) // spring actuator needs power to maintain non-default state
&& (manualcontrol && lowvoltagepower ? false == valve.is_disabled : true) // needs power to change state, without it just pass through
@@ -3128,6 +3130,7 @@ void TMoverParameters::SecuritySystemCheck(double dt)
// *************************************************************************************************
bool TMoverParameters::BatterySwitch(bool State, range_t const Notify)
{
using enum range_t;
auto const initialstate{Battery};
// Ra: ukrotnienie załączania baterii jest jakąś fikcją...
@@ -3137,10 +3140,10 @@ bool TMoverParameters::BatterySwitch(bool State, range_t const Notify)
}
// switching batteries does not require activation
if (Notify != range_t::local)
if (Notify != local)
{
SendCtrlToNext("BatterySwitch", State ? 1 : 0, 1, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control);
SendCtrlToNext("BatterySwitch", State ? 1 : 0, -1, Notify == range_t::unit ? coupling::control | coupling::permanent : coupling::control);
SendCtrlToNext("BatterySwitch", State ? 1 : 0, 1, Notify == unit ? coupling::control | coupling::permanent : coupling::control);
SendCtrlToNext("BatterySwitch", State ? 1 : 0, -1, Notify == unit ? coupling::control | coupling::permanent : coupling::control);
}
return Battery != initialstate;
@@ -3634,6 +3637,7 @@ void TMoverParameters::MainSwitch_(bool const State)
bool TMoverParameters::MainSwitchCheck() const
{
using enum TEngineType;
// prevent the switch from working if there's no power
// TODO: consider whether it makes sense for diesel engines and such
@@ -3641,15 +3645,15 @@ bool TMoverParameters::MainSwitchCheck() const
switch (EngineType)
{
case TEngineType::DieselElectric:
case TEngineType::DieselEngine:
case TEngineType::Dumb:
case DieselElectric:
case DieselEngine:
case Dumb:
{
powerisavailable = Power24vIsAvailable;
break;
}
case TEngineType::ElectricSeriesMotor:
case TEngineType::ElectricInductionMotor:
case ElectricSeriesMotor:
case ElectricInductionMotor:
{
// TODO: check whether we can simplify this check and skip the outer EngineType switch
powerisavailable = EnginePowerSourceVoltage() > 0.5 * EnginePowerSource.MaxVoltage;
@@ -3661,7 +3665,7 @@ bool TMoverParameters::MainSwitchCheck() const
}
}
return powerisavailable && (ScndCtrlPos == 0 || EngineType == TEngineType::ElectricInductionMotor) && MainsInitTimeCountdown <= 0.0 &&
return powerisavailable && (ScndCtrlPos == 0 || EngineType == ElectricInductionMotor) && MainsInitTimeCountdown <= 0.0 &&
(ConvOvldFlag == false || ConverterOverloadRelayOffWhenMainIsOff) && true == GroundRelay && true == NoVoltRelay && true == OvervoltageRelay && LastSwitchingTime > CtrlDelay &&
(HasCamshaft ? IsMainCtrlActualNoPowerPos() :
LineBreakerClosesOnlyAtNoPowerPos ? IsMainCtrlNoPowerPos() :
@@ -7147,40 +7151,41 @@ bool TMoverParameters::OperatePantographsValve(operation_t const State, range_t
switch (State)
{
case operation_t::none:
using enum operation_t;
case none:
{
valve.is_enabled = false;
valve.is_disabled = false;
break;
}
case operation_t::enable:
case enable:
{
valve.is_enabled = true;
valve.is_disabled = false;
break;
}
case operation_t::disable:
case disable:
{
valve.is_enabled = false;
valve.is_disabled = true;
break;
}
case operation_t::enable_on:
case enable_on:
{
valve.is_enabled = true;
break;
}
case operation_t::enable_off:
case enable_off:
{
valve.is_enabled = false;
break;
}
case operation_t::disable_on:
case disable_on:
{
valve.is_disabled = true;
break;
}
case operation_t::disable_off:
case disable_off:
{
valve.is_disabled = false;
break;
@@ -7206,40 +7211,41 @@ bool TMoverParameters::OperatePantographValve(end const End, operation_t const S
switch (State)
{
case operation_t::none:
using enum operation_t;
case none:
{
valve.is_enabled = false;
valve.is_disabled = false;
break;
}
case operation_t::enable:
case enable:
{
valve.is_enabled = true;
valve.is_disabled = false;
break;
}
case operation_t::disable:
case disable:
{
valve.is_enabled = false;
valve.is_disabled = true;
break;
}
case operation_t::enable_on:
case enable_on:
{
valve.is_enabled = true;
break;
}
case operation_t::enable_off:
case enable_off:
{
valve.is_enabled = false;
break;
}
case operation_t::disable_on:
case disable_on:
{
valve.is_disabled = true;
break;
}
case operation_t::disable_off:
case disable_off:
{
valve.is_disabled = false;
break;
@@ -9517,42 +9523,43 @@ bool TMoverParameters::readCompressorList(std::string const &Input)
// *************************************************************************************************
void TMoverParameters::BrakeValveDecode(std::string const &Valve)
{
using enum TBrakeValve;
std::map<std::string, TBrakeValve> valvetypes{{"W", TBrakeValve::W},
{"W_Lu_L", TBrakeValve::W_Lu_L},
{"W_Lu_XR", TBrakeValve::W_Lu_XR},
{"W_Lu_VI", TBrakeValve::W_Lu_VI},
{"K", TBrakeValve::K},
{"Kg", TBrakeValve::Kg},
{"Kp", TBrakeValve::Kp},
{"Kss", TBrakeValve::Kss},
{"Kkg", TBrakeValve::Kkg},
{"Kkp", TBrakeValve::Kkp},
{"Kks", TBrakeValve::Kks},
{"Hikp1", TBrakeValve::Hikp1},
{"Hikss", TBrakeValve::Hikss},
{"Hikg1", TBrakeValve::Hikg1},
{"KE", TBrakeValve::KE},
{"SW", TBrakeValve::SW},
{"EStED", TBrakeValve::EStED},
{"NESt3", TBrakeValve::NESt3},
{"ESt3", TBrakeValve::ESt3},
{"LSt", TBrakeValve::LSt},
{"ESt4", TBrakeValve::ESt4},
{"ESt3AL2", TBrakeValve::ESt3AL2},
{"EP1", TBrakeValve::EP1},
{"EP2", TBrakeValve::EP2},
{"M483", TBrakeValve::M483},
{"CV1_L_TR", TBrakeValve::CV1_L_TR},
{"CV1", TBrakeValve::CV1},
{"CV1_R", TBrakeValve::CV1_R}};
std::map<std::string, TBrakeValve> valvetypes{{"W", W},
{"W_Lu_L", W_Lu_L},
{"W_Lu_XR", W_Lu_XR},
{"W_Lu_VI", W_Lu_VI},
{"K", K},
{"Kg", Kg},
{"Kp", Kp},
{"Kss", Kss},
{"Kkg", Kkg},
{"Kkp", Kkp},
{"Kks", Kks},
{"Hikp1", Hikp1},
{"Hikss", Hikss},
{"Hikg1", Hikg1},
{"KE", KE},
{"SW", SW},
{"EStED", EStED},
{"NESt3", NESt3},
{"ESt3", ESt3},
{"LSt", LSt},
{"ESt4", ESt4},
{"ESt3AL2", ESt3AL2},
{"EP1", EP1},
{"EP2", EP2},
{"M483", M483},
{"CV1_L_TR", CV1_L_TR},
{"CV1", CV1},
{"CV1_R", CV1_R}};
auto lookup = valvetypes.find(Valve);
BrakeValve = lookup != valvetypes.end() ? lookup->second : TBrakeValve::Other;
BrakeValve = lookup != valvetypes.end() ? lookup->second : Other;
if (BrakeValve == TBrakeValve::Other && contains(Valve, "ESt"))
if (BrakeValve == Other && contains(Valve, "ESt"))
{
BrakeValve = TBrakeValve::ESt3;
BrakeValve = ESt3;
}
}
@@ -9561,32 +9568,34 @@ void TMoverParameters::BrakeValveDecode(std::string const &Valve)
// *************************************************************************************************
void TMoverParameters::BrakeSubsystemDecode()
{
BrakeSubsystem = TBrakeSubSystem::ss_None;
using enum TBrakeSubSystem;
BrakeSubsystem = ss_None;
switch (BrakeValve)
{
case TBrakeValve::W:
case TBrakeValve::W_Lu_L:
case TBrakeValve::W_Lu_VI:
case TBrakeValve::W_Lu_XR:
BrakeSubsystem = TBrakeSubSystem::ss_W;
using enum TBrakeValve;
case W:
case W_Lu_L:
case W_Lu_VI:
case W_Lu_XR:
BrakeSubsystem = ss_W;
break;
case TBrakeValve::ESt3:
case TBrakeValve::ESt3AL2:
case TBrakeValve::ESt4:
case TBrakeValve::EP2:
case TBrakeValve::EP1:
BrakeSubsystem = TBrakeSubSystem::ss_ESt;
case ESt3:
case ESt3AL2:
case ESt4:
case EP2:
case EP1:
BrakeSubsystem = ss_ESt;
break;
case TBrakeValve::KE:
BrakeSubsystem = TBrakeSubSystem::ss_KE;
case KE:
BrakeSubsystem = ss_KE;
break;
case TBrakeValve::CV1:
case TBrakeValve::CV1_L_TR:
BrakeSubsystem = TBrakeSubSystem::ss_Dako;
case CV1:
case CV1_L_TR:
BrakeSubsystem = ss_Dako;
break;
case TBrakeValve::LSt:
case TBrakeValve::EStED:
BrakeSubsystem = TBrakeSubSystem::ss_LSt;
case LSt:
case EStED:
BrakeSubsystem = ss_LSt;
break;
default:
break;
@@ -10702,12 +10711,14 @@ void TMoverParameters::LoadFIZ_Cntrl(std::string const &line)
{
{
std::map<std::string, TBrakeSystem> brakesystems{{"Pneumatic", TBrakeSystem::Pneumatic}, {"ElectroPneumatic", TBrakeSystem::ElectroPneumatic}};
using enum TBrakeSystem;
std::map<std::string, TBrakeSystem> brakesystems{{"Pneumatic", Pneumatic}, {"ElectroPneumatic", ElectroPneumatic}};
auto lookup = brakesystems.find(extract_value("BrakeSystem", line));
BrakeSystem = lookup != brakesystems.end() ? lookup->second : TBrakeSystem::Individual;
BrakeSystem = lookup != brakesystems.end() ? lookup->second : Individual;
}
if (BrakeSystem != TBrakeSystem::Individual)
{
using enum TBrakeHandle;
extract_value(BrakeCtrlPosNo, "BCPN", line, "");
for (int idx = 0; idx < 4; ++idx)
@@ -10742,11 +10753,11 @@ void TMoverParameters::LoadFIZ_Cntrl(std::string const &line)
// brakehandle
{
std::map<std::string, TBrakeHandle> brakehandles{
{"FV4a", TBrakeHandle::FV4a}, {"test", TBrakeHandle::testH}, {"D2", TBrakeHandle::D2}, {"MHZ_EN57", TBrakeHandle::MHZ_EN57}, {"MHZ_K5P", TBrakeHandle::MHZ_K5P},
{"MHZ_K8P", TBrakeHandle::MHZ_K8P}, {"MHZ_6P", TBrakeHandle::MHZ_6P}, {"M394", TBrakeHandle::M394}, {"Knorr", TBrakeHandle::Knorr}, {"Westinghouse", TBrakeHandle::West},
{"FVel6", TBrakeHandle::FVel6}, {"FVE408", TBrakeHandle::FVE408}, {"St113", TBrakeHandle::St113}};
{"FV4a", FV4a}, {"test", testH}, {"D2", D2}, {"MHZ_EN57", MHZ_EN57}, {"MHZ_K5P", MHZ_K5P},
{"MHZ_K8P", MHZ_K8P}, {"MHZ_6P", MHZ_6P}, {"M394", M394}, {"Knorr", Knorr}, {"Westinghouse", West},
{"FVel6", FVel6}, {"FVE408", FVE408}, {"St113", St113}};
auto lookup = brakehandles.find(extract_value("BrakeHandle", line));
BrakeHandle = lookup != brakehandles.end() ? lookup->second : TBrakeHandle::NoHandle;
BrakeHandle = lookup != brakehandles.end() ? lookup->second : NoHandle;
}
extract_value(Handle_AutomaticOverload, "HAO", line, "");
extract_value(Handle_ManualOverload, "HMO", line, "");
@@ -10756,9 +10767,9 @@ void TMoverParameters::LoadFIZ_Cntrl(std::string const &line)
extract_value(Handle_OverloadPressureDecrease, "OPD", line, "");
// brakelochandle
{
std::map<std::string, TBrakeHandle> locbrakehandles{{"FD1", TBrakeHandle::FD1}, {"Knorr", TBrakeHandle::Knorr}, {"Westinghouse", TBrakeHandle::West}};
std::map<std::string, TBrakeHandle> locbrakehandles{{"FD1", FD1}, {"Knorr", Knorr}, {"Westinghouse", West}};
auto lookup = locbrakehandles.find(extract_value("LocBrakeHandle", line));
BrakeLocHandle = lookup != locbrakehandles.end() ? lookup->second : TBrakeHandle::NoHandle;
BrakeLocHandle = lookup != locbrakehandles.end() ? lookup->second : NoHandle;
}
// mbpm
@@ -10798,9 +10809,10 @@ void TMoverParameters::LoadFIZ_Cntrl(std::string const &line)
// localbrake
{
std::map<std::string, TLocalBrake> localbrakes{{"ManualBrake", TLocalBrake::ManualBrake}, {"PneumaticBrake", TLocalBrake::PneumaticBrake}, {"HydraulicBrake", TLocalBrake::HydraulicBrake}};
using enum TLocalBrake;
std::map<std::string, TLocalBrake> localbrakes{{"ManualBrake", ManualBrake}, {"PneumaticBrake", PneumaticBrake}, {"HydraulicBrake", HydraulicBrake}};
auto lookup = localbrakes.find(extract_value("LocalBrake", line));
LocalBrake = lookup != localbrakes.end() ? lookup->second : TLocalBrake::NoBrake;
LocalBrake = lookup != localbrakes.end() ? lookup->second : NoBrake;
}
// mbrake
extract_value(MBrake, "ManualBrake", line, "");
@@ -11658,39 +11670,42 @@ void TMoverParameters::LoadFIZ_PowerParamsDecode(TPowerParameters &Powerparamete
TPowerType TMoverParameters::LoadFIZ_PowerDecode(std::string const &Powertype) const
{
using enum TPowerType;
std::map<std::string, TPowerType> powertypes{
{"BioPower", TPowerType::BioPower}, {"MechPower", TPowerType::MechPower}, {"ElectricPower", TPowerType::ElectricPower}, {"SteamPower", TPowerType::SteamPower}};
{"BioPower", BioPower}, {"MechPower", MechPower}, {"ElectricPower", ElectricPower}, {"SteamPower", SteamPower}};
auto lookup = powertypes.find(Powertype);
return lookup != powertypes.end() ? lookup->second : TPowerType::NoPower;
return lookup != powertypes.end() ? lookup->second : NoPower;
}
TPowerSource TMoverParameters::LoadFIZ_SourceDecode(std::string const &Source) const
{
using enum TPowerSource;
std::map<std::string, TPowerSource> powersources{{"Transducer", TPowerSource::Transducer}, {"Generator", TPowerSource::Generator},
{"Accu", TPowerSource::Accumulator}, // legacy compatibility leftover. TODO: check if we can get rid of it
{"Accumulator", TPowerSource::Accumulator}, {"CurrentCollector", TPowerSource::CurrentCollector},
{"PowerCable", TPowerSource::PowerCable}, {"Heater", TPowerSource::Heater},
{"Internal", TPowerSource::InternalSource}, {"Main", TPowerSource::Main}};
std::map<std::string, TPowerSource> powersources{{"Transducer", Transducer}, {"Generator", Generator},
{"Accu", Accumulator}, // legacy compatibility leftover. TODO: check if we can get rid of it
{"Accumulator", Accumulator}, {"CurrentCollector", CurrentCollector},
{"PowerCable", PowerCable}, {"Heater", Heater},
{"Internal", InternalSource}, {"Main", Main}};
auto lookup = powersources.find(Source);
return lookup != powersources.end() ? lookup->second : TPowerSource::NotDefined;
return lookup != powersources.end() ? lookup->second : NotDefined;
}
TEngineType TMoverParameters::LoadFIZ_EngineDecode(std::string const &Engine) const
{
using enum TEngineType;
std::map<std::string, TEngineType> enginetypes{{"ElectricSeriesMotor", TEngineType::ElectricSeriesMotor},
{"DieselEngine", TEngineType::DieselEngine},
{"SteamEngine", TEngineType::SteamEngine},
{"WheelsDriven", TEngineType::WheelsDriven},
{"Dumb", TEngineType::Dumb},
{"DieselElectric", TEngineType::DieselElectric},
{"DumbDE", TEngineType::DieselElectric},
{"ElectricInductionMotor", TEngineType::ElectricInductionMotor},
{"Main", TEngineType::Main}};
std::map<std::string, TEngineType> enginetypes{{"ElectricSeriesMotor", ElectricSeriesMotor},
{"DieselEngine", DieselEngine},
{"SteamEngine", SteamEngine},
{"WheelsDriven", WheelsDriven},
{"Dumb", Dumb},
{"DieselElectric", DieselElectric},
{"DumbDE", DieselElectric},
{"ElectricInductionMotor", ElectricInductionMotor},
{"Main", Main}};
auto lookup = enginetypes.find(Engine);
return lookup != enginetypes.end() ? lookup->second : TEngineType::None;
return lookup != enginetypes.end() ? lookup->second : None;
}
// *************************************************************************************************
@@ -11844,35 +11859,36 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int /*Dir*/)
switch (BrakeHandle)
{
case TBrakeHandle::FV4a:
using enum TBrakeHandle;
case FV4a:
Handle = std::make_shared<TFV4aM>();
break;
case TBrakeHandle::MHZ_EN57:
case TBrakeHandle::MHZ_K8P:
case MHZ_EN57:
case MHZ_K8P:
Handle = std::make_shared<TMHZ_EN57>();
break;
case TBrakeHandle::FVel6:
case FVel6:
Handle = std::make_shared<TFVel6>();
break;
case TBrakeHandle::FVE408:
case FVE408:
Handle = std::make_shared<TFVE408>();
break;
case TBrakeHandle::testH:
case testH:
Handle = std::make_shared<Ttest>();
break;
case TBrakeHandle::M394:
case M394:
Handle = std::make_shared<TM394>();
break;
case TBrakeHandle::Knorr:
case Knorr:
Handle = std::make_shared<TH14K1>();
break;
case TBrakeHandle::St113:
case St113:
Handle = std::make_shared<TSt113>();
break;
case TBrakeHandle::MHZ_K5P:
case MHZ_K5P:
Handle = std::make_shared<TMHZ_K5P>();
break;
case TBrakeHandle::MHZ_6P:
case MHZ_6P:
Handle = std::make_shared<TMHZ_6P>();
break;
default: