Skip to content

Commit

Permalink
Bpm: Simplify </<=/>/>= operator implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Jul 5, 2021
1 parent 4dff17c commit 1880daa
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/track/bpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,32 +152,33 @@ inline Bpm operator/(Bpm bpm, double divisor) {
return Bpm(bpm.getValue() / divisor);
}

inline bool operator==(Bpm bpm1, Bpm bpm2) {
if (!bpm1.hasValue() && !bpm2.hasValue()) {
return true;
}
return bpm1.hasValue() && bpm2.hasValue() && bpm1.getValue() == bpm2.getValue();
}

inline bool operator!=(Bpm bpm1, Bpm bpm2) {
return !(bpm1 == bpm2);
}

inline bool operator<(Bpm bpm1, Bpm bpm2) {
return bpm1.getValue() < bpm2.getValue();
}

inline bool operator<=(Bpm bpm1, Bpm bpm2) {
return (!bpm1.hasValue() && !bpm2.hasValue()) || bpm1.getValue() <= bpm2.getValue();
return (bpm1 == bpm2) || bpm1 < bpm2;
}

inline bool operator>(Bpm bpm1, Bpm bpm2) {
return bpm1.getValue() > bpm2.getValue();
return bpm2 < bpm1;
}

inline bool operator>=(Bpm bpm1, Bpm bpm2) {
return (!bpm1.hasValue() && !bpm2.hasValue()) || bpm1.getValue() >= bpm2.getValue();
return bpm2 <= bpm1;
}

inline bool operator==(Bpm bpm1, Bpm bpm2) {
if (!bpm1.hasValue() && !bpm2.hasValue()) {
return true;
}
return bpm1.hasValue() && bpm2.hasValue() && bpm1.getValue() == bpm2.getValue();
}

inline bool operator!=(Bpm bpm1, Bpm bpm2) {
return !(bpm1 == bpm2);
}

inline QDebug operator<<(QDebug dbg, Bpm arg) {
if (arg.hasValue()) {
Expand Down

0 comments on commit 1880daa

Please sign in to comment.