ReplayGainInfo: don't use array in struct ReplayGainInfo

Declare two named elements.  An enum should not be used as an array
index, as this is error prone.
This commit is contained in:
Max Kellermann
2016-11-24 16:45:56 +01:00
parent 1261327fa6
commit 25e58df5e0
9 changed files with 29 additions and 34 deletions

View File

@@ -49,26 +49,21 @@ struct ReplayGainTuple {
};
struct ReplayGainInfo {
ReplayGainTuple tuples[2];
ReplayGainTuple track, album;
constexpr bool IsDefined() const {
return tuples[REPLAY_GAIN_ALBUM].IsDefined() ||
tuples[REPLAY_GAIN_TRACK].IsDefined();
return track.IsDefined() || album.IsDefined();
}
const ReplayGainTuple &Get(ReplayGainMode mode) const {
return mode == REPLAY_GAIN_ALBUM
? (tuples[REPLAY_GAIN_ALBUM].IsDefined()
? tuples[REPLAY_GAIN_ALBUM]
: tuples[REPLAY_GAIN_TRACK])
: (tuples[REPLAY_GAIN_TRACK].IsDefined()
? tuples[REPLAY_GAIN_TRACK]
: tuples[REPLAY_GAIN_ALBUM]);
? (album.IsDefined() ? album : track)
: (track.IsDefined() ? track : album);
}
void Clear() {
tuples[REPLAY_GAIN_ALBUM].Clear();
tuples[REPLAY_GAIN_TRACK].Clear();
track.Clear();
album.Clear();
}
};