DatabasePrint: move PrintSongCount() to Count.cxx

This commit is contained in:
Max Kellermann
2014-04-26 22:59:21 +02:00
parent 154e601f4e
commit fcb55f841a
6 changed files with 112 additions and 54 deletions

View File

@@ -168,54 +168,6 @@ db_selection_print(Client &client, const DatabaseSelection &selection,
return db->Visit(selection, d, s, p, error);
}
struct SearchStats {
unsigned n_songs;
unsigned long total_time_s;
};
static void
PrintSearchStats(Client &client, const SearchStats &stats)
{
client_printf(client,
"songs: %u\n"
"playtime: %lu\n",
stats.n_songs, stats.total_time_s);
}
static bool
stats_visitor_song(SearchStats &stats, const LightSong &song)
{
stats.n_songs++;
stats.total_time_s += song.GetDuration();
return true;
}
bool
PrintSongCount(Client &client, const char *name,
const SongFilter *filter,
Error &error)
{
const Database *db = client.GetDatabase(error);
if (db == nullptr)
return false;
const DatabaseSelection selection(name, true, filter);
SearchStats stats;
stats.n_songs = 0;
stats.total_time_s = 0;
using namespace std::placeholders;
const auto f = std::bind(stats_visitor_song, std::ref(stats),
_1);
if (!db->Visit(selection, f, error))
return false;
PrintSearchStats(client, stats);
return true;
}
static bool
PrintSongURIVisitor(Client &client, const LightSong &song)
{