db/Helpers: split library

This commit is contained in:
Max Kellermann 2014-04-25 18:39:21 +02:00
parent 4cca75b2e1
commit 154e601f4e
6 changed files with 99 additions and 47 deletions

View File

@ -590,6 +590,7 @@ libdb_plugins_a_SOURCES = \
src/PlaylistDatabase.cxx src/PlaylistDatabase.hxx \
src/db/Registry.cxx src/db/Registry.hxx \
src/db/Helpers.cxx src/db/Helpers.hxx \
src/db/UniqueTags.cxx src/db/UniqueTags.hxx \
src/db/plugins/simple/DatabaseSave.cxx \
src/db/plugins/simple/DatabaseSave.hxx \
src/db/plugins/simple/DirectorySave.cxx \

View File

@ -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)

View File

@ -20,22 +20,11 @@
#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);

59
src/db/UniqueTags.cxx Normal file
View File

@ -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;
}

38
src/db/UniqueTags.hxx Normal file
View File

@ -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

View File

@ -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"