From 60c077c79076f50317a4637b65c69bff3df134a7 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 24 Aug 2015 10:52:08 +0200 Subject: tag/Settings: add function IsTagEnabled() wrapping access to ignore_tag_items[] --- src/TagPrint.cxx | 2 +- src/db/plugins/simple/DatabaseSave.cxx | 4 ++-- src/tag/Set.cxx | 2 +- src/tag/TagBuilder.cxx | 2 +- src/tag/TagSettings.h | 19 +++++++++++++++++++ 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/TagPrint.cxx b/src/TagPrint.cxx index 3914a5860..4a97d851e 100644 --- a/src/TagPrint.cxx +++ b/src/TagPrint.cxx @@ -27,7 +27,7 @@ void tag_print_types(Response &r) { for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) - if (!ignore_tag_items[i]) + if (IsTagEnabled(i)) r.Format("tagtype: %s\n", tag_item_names[i]); } diff --git a/src/db/plugins/simple/DatabaseSave.cxx b/src/db/plugins/simple/DatabaseSave.cxx index 36e310bc9..02690dcf8 100644 --- a/src/db/plugins/simple/DatabaseSave.cxx +++ b/src/db/plugins/simple/DatabaseSave.cxx @@ -58,7 +58,7 @@ db_save_internal(BufferedOutputStream &os, const Directory &music_root) os.Format("%s%s\n", DIRECTORY_FS_CHARSET, GetFSCharset()); for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) - if (!ignore_tag_items[i]) + if (IsTagEnabled(i)) os.Format(DB_TAG_PREFIX "%s\n", tag_item_names[i]); os.Format("%s\n", DIRECTORY_INFO_END); @@ -142,7 +142,7 @@ db_load_internal(TextFile &file, Directory &music_root, Error &error) } for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) { - if (!ignore_tag_items[i] && !tags[i]) { + if (IsTagEnabled(i) && !tags[i]) { error.Set(db_domain, "Tag list mismatch, " "discarding database file"); diff --git a/src/tag/Set.cxx b/src/tag/Set.cxx index 22d1728ad..24ca30ee3 100644 --- a/src/tag/Set.cxx +++ b/src/tag/Set.cxx @@ -110,7 +110,7 @@ TagSet::InsertUnique(const Tag &tag, if (!CheckUnique(type, tag, type, group_mask) && (type != TAG_ALBUM_ARTIST || - ignore_tag_items[TAG_ALBUM_ARTIST] || + !IsTagEnabled(TAG_ALBUM_ARTIST) || /* fall back to "Artist" if no "AlbumArtist" was found */ !CheckUnique(type, tag, TAG_ARTIST, group_mask))) InsertUnique(tag, type, nullptr, group_mask); diff --git a/src/tag/TagBuilder.cxx b/src/tag/TagBuilder.cxx index 42e11e798..4e810475f 100644 --- a/src/tag/TagBuilder.cxx +++ b/src/tag/TagBuilder.cxx @@ -220,7 +220,7 @@ TagBuilder::AddItem(TagType type, const char *value, size_t length) assert(value != nullptr); #endif - if (length == 0 || ignore_tag_items[type]) + if (length == 0 || !IsTagEnabled(type)) return; AddItemInternal(type, value, length); diff --git a/src/tag/TagSettings.h b/src/tag/TagSettings.h index cf91b52e1..a58bd8915 100644 --- a/src/tag/TagSettings.h +++ b/src/tag/TagSettings.h @@ -21,9 +21,28 @@ #define MPD_TAG_SETTINGS_H #include "TagType.h" +#include "Compiler.h" #include extern bool ignore_tag_items[TAG_NUM_OF_ITEM_TYPES]; +#ifdef __cplusplus + +gcc_const +static inline bool +IsTagEnabled(unsigned tag) +{ + return !ignore_tag_items[tag]; +} + +gcc_const +static inline bool +IsTagEnabled(TagType tag) +{ + return IsTagEnabled(unsigned(tag)); +} + +#endif + #endif -- cgit v1.2.3