diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/db/Helpers.cxx | 36 | ||||
-rw-r--r-- | src/db/Helpers.hxx | 11 | ||||
-rw-r--r-- | src/db/UniqueTags.cxx | 59 | ||||
-rw-r--r-- | src/db/UniqueTags.hxx | 38 | ||||
-rw-r--r-- | src/db/plugins/simple/SimpleDatabasePlugin.cxx | 1 |
5 files changed, 98 insertions, 47 deletions
diff --git a/src/db/Helpers.cxx b/src/db/Helpers.cxx index 5b1e1d6c6..b849e73e8 100644 --- a/src/db/Helpers.cxx +++ b/src/db/Helpers.cxx @@ -22,13 +22,9 @@ #include "Interface.hxx" #include "LightSong.hxx" #include "tag/Tag.hxx" -#include "tag/TagBuilder.hxx" -#include "tag/Set.hxx" -#include <functional> #include <set> -#include <assert.h> #include <string.h> struct StringLess { @@ -40,38 +36,6 @@ struct StringLess { typedef std::set<const char *, StringLess> StringSet; -static bool -CollectTags(TagSet &set, TagType tag_type, uint32_t group_mask, - const LightSong &song) -{ - assert(song.tag != nullptr); - const Tag &tag = *song.tag; - - set.InsertUnique(tag, tag_type, group_mask); - return true; -} - -bool -VisitUniqueTags(const Database &db, const DatabaseSelection &selection, - TagType tag_type, uint32_t group_mask, - VisitTag visit_tag, - Error &error) -{ - TagSet set; - - using namespace std::placeholders; - const auto f = std::bind(CollectTags, std::ref(set), - tag_type, group_mask, _1); - if (!db.Visit(selection, f, error)) - return false; - - for (const auto &value : set) - if (!visit_tag(value, error)) - return false; - - return true; -} - static void StatsVisitTag(DatabaseStats &stats, StringSet &artists, StringSet &albums, const Tag &tag) diff --git a/src/db/Helpers.hxx b/src/db/Helpers.hxx index b9a7af4cf..651bac0e0 100644 --- a/src/db/Helpers.hxx +++ b/src/db/Helpers.hxx @@ -20,23 +20,12 @@ #ifndef MPD_MEMORY_DATABASE_PLUGIN_HXX #define MPD_MEMORY_DATABASE_PLUGIN_HXX -#include "Visitor.hxx" -#include "tag/TagType.h" - -#include <stdint.h> - class Error; class Database; struct DatabaseSelection; struct DatabaseStats; bool -VisitUniqueTags(const Database &db, const DatabaseSelection &selection, - TagType tag_type, uint32_t group_mask, - VisitTag visit_tag, - Error &error); - -bool GetStats(const Database &db, const DatabaseSelection &selection, DatabaseStats &stats, Error &error); diff --git a/src/db/UniqueTags.cxx b/src/db/UniqueTags.cxx new file mode 100644 index 000000000..589dc936d --- /dev/null +++ b/src/db/UniqueTags.cxx @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2003-2014 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "UniqueTags.hxx" +#include "Interface.hxx" +#include "LightSong.hxx" +#include "tag/Set.hxx" + +#include <functional> + +#include <assert.h> + +static bool +CollectTags(TagSet &set, TagType tag_type, uint32_t group_mask, + const LightSong &song) +{ + assert(song.tag != nullptr); + const Tag &tag = *song.tag; + + set.InsertUnique(tag, tag_type, group_mask); + return true; +} + +bool +VisitUniqueTags(const Database &db, const DatabaseSelection &selection, + TagType tag_type, uint32_t group_mask, + VisitTag visit_tag, + Error &error) +{ + TagSet set; + + using namespace std::placeholders; + const auto f = std::bind(CollectTags, std::ref(set), + tag_type, group_mask, _1); + if (!db.Visit(selection, f, error)) + return false; + + for (const auto &value : set) + if (!visit_tag(value, error)) + return false; + + return true; +} diff --git a/src/db/UniqueTags.hxx b/src/db/UniqueTags.hxx new file mode 100644 index 000000000..61004fc56 --- /dev/null +++ b/src/db/UniqueTags.hxx @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2003-2014 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_DB_UNIQUE_TAGS_HXX +#define MPD_DB_UNIQUE_TAGS_HXX + +#include "Visitor.hxx" +#include "tag/TagType.h" + +#include <stdint.h> + +class Error; +class Database; +struct DatabaseSelection; + +bool +VisitUniqueTags(const Database &db, const DatabaseSelection &selection, + TagType tag_type, uint32_t group_mask, + VisitTag visit_tag, + Error &error); + +#endif diff --git a/src/db/plugins/simple/SimpleDatabasePlugin.cxx b/src/db/plugins/simple/SimpleDatabasePlugin.cxx index d616c793f..97d3e52df 100644 --- a/src/db/plugins/simple/SimpleDatabasePlugin.cxx +++ b/src/db/plugins/simple/SimpleDatabasePlugin.cxx @@ -23,6 +23,7 @@ #include "db/DatabasePlugin.hxx" #include "db/Selection.hxx" #include "db/Helpers.hxx" +#include "db/UniqueTags.hxx" #include "db/LightDirectory.hxx" #include "Directory.hxx" #include "Song.hxx" |