diff options
author | Max Kellermann <max@duempel.org> | 2014-09-24 22:19:55 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-09-24 22:19:55 +0200 |
commit | 9f4fc8ad33470d2f82faafb96d5db41967faa151 (patch) | |
tree | c5c8f54408436c90bbd311bb7d138a32d98bfa01 | |
parent | d1e31261fe7d58f9ea50c93b58ace9befd5ea0cc (diff) | |
download | mpd-9f4fc8ad33470d2f82faafb96d5db41967faa151.tar.gz mpd-9f4fc8ad33470d2f82faafb96d5db41967faa151.tar.xz mpd-9f4fc8ad33470d2f82faafb96d5db41967faa151.zip |
tag/ReplayGain: move code to template function
-rw-r--r-- | src/tag/ReplayGain.cxx | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/tag/ReplayGain.cxx b/src/tag/ReplayGain.cxx index f2f52e59c..d2347dba5 100644 --- a/src/tag/ReplayGain.cxx +++ b/src/tag/ReplayGain.cxx @@ -25,24 +25,46 @@ #include <assert.h> #include <stdlib.h> -bool -ParseReplayGainTag(ReplayGainInfo &info, const char *name, const char *value) +template<typename T> +static bool +ParseReplayGainTagTemplate(ReplayGainInfo &info, const T t) { - assert(name != nullptr); - assert(value != nullptr); + const char *value; - if (StringEqualsCaseASCII(name, "replaygain_track_gain")) { + if ((value = t["replaygain_track_gain"]) != nullptr) { info.tuples[REPLAY_GAIN_TRACK].gain = atof(value); return true; - } else if (StringEqualsCaseASCII(name, "replaygain_album_gain")) { + } else if ((value = t["replaygain_album_gain"]) != nullptr) { info.tuples[REPLAY_GAIN_ALBUM].gain = atof(value); return true; - } else if (StringEqualsCaseASCII(name, "replaygain_track_peak")) { + } else if ((value = t["replaygain_track_peak"]) != nullptr) { info.tuples[REPLAY_GAIN_TRACK].peak = atof(value); return true; - } else if (StringEqualsCaseASCII(name, "replaygain_album_peak")) { + } else if ((value = t["replaygain_album_peak"]) != nullptr) { info.tuples[REPLAY_GAIN_ALBUM].peak = atof(value); return true; } else return false; + +} + +bool +ParseReplayGainTag(ReplayGainInfo &info, const char *name, const char *value) +{ + assert(name != nullptr); + assert(value != nullptr); + + struct NameValue { + const char *name; + const char *value; + + gcc_pure + const char *operator[](const char *n) const { + return StringEqualsCaseASCII(name, n) + ? value + : nullptr; + } + }; + + return ParseReplayGainTagTemplate(info, NameValue{name, value}); } |