aboutsummaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-04-24 18:29:11 +0200
committerMax Kellermann <max@duempel.org>2014-04-24 18:32:23 +0200
commitecc12c9ba15809c918be5577cc90eba108569cbd (patch)
treee1139d9ea6c32d667b1acd396b6254378a3b8406 /src/db
parent9e50993c130ee7d3138150d4ebfef985d6ddc810 (diff)
downloadmpd-ecc12c9ba15809c918be5577cc90eba108569cbd.tar.gz
mpd-ecc12c9ba15809c918be5577cc90eba108569cbd.tar.xz
mpd-ecc12c9ba15809c918be5577cc90eba108569cbd.zip
db/Helpers: move code to tag/Set.cxx
Diffstat (limited to 'src/db')
-rw-r--r--src/db/Helpers.cxx89
1 files changed, 1 insertions, 88 deletions
diff --git a/src/db/Helpers.cxx b/src/db/Helpers.cxx
index 25ea50a52..5b1e1d6c6 100644
--- a/src/db/Helpers.cxx
+++ b/src/db/Helpers.cxx
@@ -40,101 +40,14 @@ struct StringLess {
typedef std::set<const char *, StringLess> StringSet;
-/**
- * Copy all tag items of the specified type.
- */
-static bool
-CopyTagItem(TagBuilder &dest, TagType dest_type,
- const Tag &src, TagType src_type)
-{
- bool found = false;
- const unsigned n = src.num_items;
- for (unsigned i = 0; i < n; ++i) {
- if (src.items[i]->type == src_type) {
- dest.AddItem(dest_type, src.items[i]->value);
- found = true;
- }
- }
-
- return found;
-}
-
-/**
- * Copy all tag items of the specified type. Fall back to "Artist" if
- * there is no "AlbumArtist".
- */
-static void
-CopyTagItem(TagBuilder &dest, const Tag &src, TagType type)
-{
- if (!CopyTagItem(dest, type, src, type) &&
- type == TAG_ALBUM_ARTIST)
- CopyTagItem(dest, type, src, TAG_ARTIST);
-}
-
-/**
- * Copy all tag items of the types in the mask.
- */
-static void
-CopyTagMask(TagBuilder &dest, const Tag &src, uint32_t mask)
-{
- for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
- if ((mask & (1u << i)) != 0)
- CopyTagItem(dest, src, TagType(i));
-}
-
-static void
-InsertUniqueTag(TagSet &set, const Tag &src, TagType type, const char *value,
- uint32_t group_mask)
-{
- TagBuilder builder;
- if (value == nullptr)
- builder.AddEmptyItem(type);
- else
- builder.AddItem(type, value);
- CopyTagMask(builder, src, group_mask);
-#if defined(__clang__) || GCC_CHECK_VERSION(4,8)
- set.emplace(builder.Commit());
-#else
- set.insert(builder.Commit());
-#endif
-}
-
-static bool
-CheckUniqueTag(TagSet &set, TagType dest_type,
- const Tag &tag, TagType src_type,
- uint32_t group_mask)
-{
- bool found = false;
- for (unsigned i = 0; i < tag.num_items; ++i) {
- if (tag.items[i]->type == src_type) {
- InsertUniqueTag(set, tag, dest_type,
- tag.items[i]->value,
- group_mask);
- found = true;
- }
- }
-
- return found;
-}
-
static bool
CollectTags(TagSet &set, TagType tag_type, uint32_t group_mask,
const LightSong &song)
{
- static_assert(sizeof(group_mask) * 8 >= TAG_NUM_OF_ITEM_TYPES,
- "Mask is too small");
-
- assert((group_mask & (1u << unsigned(tag_type))) == 0);
-
assert(song.tag != nullptr);
const Tag &tag = *song.tag;
- if (!CheckUniqueTag(set, tag_type, tag, tag_type, group_mask) &&
- (tag_type != TAG_ALBUM_ARTIST ||
- /* fall back to "Artist" if no "AlbumArtist" was found */
- !CheckUniqueTag(set, tag_type, tag, TAG_ARTIST, group_mask)))
- InsertUniqueTag(set, tag, tag_type, nullptr, group_mask);
-
+ set.InsertUnique(tag, tag_type, group_mask);
return true;
}