diff options
author | Max Kellermann <max@duempel.org> | 2014-04-26 22:59:21 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-04-26 22:59:21 +0200 |
commit | fcb55f841ae4772ee94f80eed5b45947ef644337 (patch) | |
tree | 3f3b2f09d055439febb9b3a973578f60ad25d823 | |
parent | 154e601f4e99e5334005279eb64ba6a541d9e844 (diff) | |
download | mpd-fcb55f841ae4772ee94f80eed5b45947ef644337.tar.gz mpd-fcb55f841ae4772ee94f80eed5b45947ef644337.tar.xz mpd-fcb55f841ae4772ee94f80eed5b45947ef644337.zip |
DatabasePrint: move PrintSongCount() to Count.cxx
Diffstat (limited to '')
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | src/command/DatabaseCommands.cxx | 1 | ||||
-rw-r--r-- | src/db/Count.cxx | 75 | ||||
-rw-r--r-- | src/db/Count.hxx | 35 | ||||
-rw-r--r-- | src/db/DatabasePrint.cxx | 48 | ||||
-rw-r--r-- | src/db/DatabasePrint.hxx | 6 |
6 files changed, 112 insertions, 54 deletions
diff --git a/Makefile.am b/Makefile.am index 969011849..a7a7bef1f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -194,6 +194,7 @@ libmpd_a_SOURCES += \ src/queue/PlaylistUpdate.cxx \ src/command/StorageCommands.cxx src/command/StorageCommands.hxx \ src/command/DatabaseCommands.cxx src/command/DatabaseCommands.hxx \ + src/db/Count.cxx src/db/Count.hxx \ src/db/LightSong.cxx src/db/LightSong.hxx \ src/db/LightDirectory.hxx \ src/db/update/UpdateDomain.cxx src/db/update/UpdateDomain.hxx \ diff --git a/src/command/DatabaseCommands.cxx b/src/command/DatabaseCommands.cxx index 6e9d3caa5..0f23dc959 100644 --- a/src/command/DatabaseCommands.cxx +++ b/src/command/DatabaseCommands.cxx @@ -23,6 +23,7 @@ #include "db/DatabaseQueue.hxx" #include "db/DatabasePlaylist.hxx" #include "db/DatabasePrint.hxx" +#include "db/Count.hxx" #include "db/Selection.hxx" #include "CommandError.hxx" #include "client/Client.hxx" diff --git a/src/db/Count.cxx b/src/db/Count.cxx new file mode 100644 index 000000000..4fa1c02a3 --- /dev/null +++ b/src/db/Count.cxx @@ -0,0 +1,75 @@ +/* + * 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 "config.h" +#include "Count.hxx" +#include "Selection.hxx" +#include "Interface.hxx" +#include "client/Client.hxx" +#include "LightSong.hxx" + +#include <functional> + +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; +} diff --git a/src/db/Count.hxx b/src/db/Count.hxx new file mode 100644 index 000000000..5c5fca1bd --- /dev/null +++ b/src/db/Count.hxx @@ -0,0 +1,35 @@ +/* + * 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_COUNT_HXX +#define MPD_DB_COUNT_HXX + +#include "Compiler.h" + +class Client; +class SongFilter; +class Error; + +gcc_nonnull(2) +bool +PrintSongCount(Client &client, const char *name, + const SongFilter *filter, + Error &error); + +#endif diff --git a/src/db/DatabasePrint.cxx b/src/db/DatabasePrint.cxx index c65de373f..f6663311e 100644 --- a/src/db/DatabasePrint.cxx +++ b/src/db/DatabasePrint.cxx @@ -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) { diff --git a/src/db/DatabasePrint.hxx b/src/db/DatabasePrint.hxx index 4e71a7552..2ab5e703d 100644 --- a/src/db/DatabasePrint.hxx +++ b/src/db/DatabasePrint.hxx @@ -37,12 +37,6 @@ bool db_selection_print(Client &client, const DatabaseSelection &selection, bool full, bool base, Error &error); -gcc_nonnull(2) -bool -PrintSongCount(Client &client, const char *name, - const SongFilter *filter, - Error &error); - bool PrintUniqueTags(Client &client, unsigned type, uint32_t group_mask, const SongFilter *filter, |