mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-17 05:09:20 +02: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.
This commit is contained in:
@@ -27,12 +27,13 @@ enum class comparison_pass {
|
||||
template <typename Type_>
|
||||
bool compare( Type_ const Left, Type_ const Right, comparison_operator const Operator ) {
|
||||
switch( Operator ) {
|
||||
case comparison_operator::equal: { return Left == Right; }
|
||||
case comparison_operator::not_equal: { return Left != Right; }
|
||||
case comparison_operator::lt: { return Left < Right; }
|
||||
case comparison_operator::gt: { return Left > Right; }
|
||||
case comparison_operator::lt_eq: { return Left <= Right; }
|
||||
case comparison_operator::gt_eq: { return Left >= Right; }
|
||||
using enum comparison_operator;
|
||||
case equal: { return Left == Right; }
|
||||
case not_equal: { return Left != Right; }
|
||||
case lt: { return Left < Right; }
|
||||
case gt: { return Left > Right; }
|
||||
case lt_eq: { return Left <= Right; }
|
||||
case gt_eq: { return Left >= Right; }
|
||||
default: { return false; }
|
||||
}
|
||||
}
|
||||
@@ -41,12 +42,13 @@ inline
|
||||
std::string
|
||||
to_string( comparison_operator const Operator ) {
|
||||
switch( Operator ) {
|
||||
case comparison_operator::equal: { return "=="; }
|
||||
case comparison_operator::not_equal: { return "!="; }
|
||||
case comparison_operator::lt: { return "<"; }
|
||||
case comparison_operator::gt: { return ">"; }
|
||||
case comparison_operator::lt_eq: { return "<="; }
|
||||
case comparison_operator::gt_eq: { return ">"; }
|
||||
using enum comparison_operator;
|
||||
case equal: { return "=="; }
|
||||
case not_equal: { return "!="; }
|
||||
case lt: { return "<"; }
|
||||
case gt: { return ">"; }
|
||||
case lt_eq: { return "<="; }
|
||||
case gt_eq: { return ">"; }
|
||||
default: { return "??"; }
|
||||
}
|
||||
}
|
||||
@@ -54,24 +56,26 @@ to_string( comparison_operator const Operator ) {
|
||||
inline
|
||||
comparison_pass
|
||||
comparison_pass_from_string( std::string const Input ) {
|
||||
if( Input == "all" ) { return comparison_pass::all; }
|
||||
else if( Input == "any" ) { return comparison_pass::any; }
|
||||
else if( Input == "none" ) { return comparison_pass::none; }
|
||||
using enum comparison_pass;
|
||||
if( Input == "all" ) { return all; }
|
||||
else if( Input == "any" ) { return any; }
|
||||
else if( Input == "none" ) { return none; }
|
||||
|
||||
return comparison_pass::all; // legacy default
|
||||
return all; // legacy default
|
||||
}
|
||||
|
||||
inline
|
||||
comparison_operator
|
||||
comparison_operator_from_string( std::string const Input ) {
|
||||
if( Input == "==" ) { return comparison_operator::equal; }
|
||||
else if( Input == "!=" ) { return comparison_operator::not_equal; }
|
||||
else if( Input == "<" ) { return comparison_operator::lt; }
|
||||
else if( Input == ">" ) { return comparison_operator::gt; }
|
||||
else if( Input == "<=" ) { return comparison_operator::lt_eq; }
|
||||
else if( Input == ">=" ) { return comparison_operator::gt_eq; }
|
||||
using enum comparison_operator;
|
||||
if( Input == "==" ) { return equal; }
|
||||
else if( Input == "!=" ) { return not_equal; }
|
||||
else if( Input == "<" ) { return lt; }
|
||||
else if( Input == ">" ) { return gt; }
|
||||
else if( Input == "<=" ) { return lt_eq; }
|
||||
else if( Input == ">=" ) { return gt_eq; }
|
||||
|
||||
return comparison_operator::equal; // legacy default
|
||||
return equal; // legacy default
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user