From f548a966f5cb09ba8a5e99939fe5235e5ad59005 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 27 Jan 2014 11:05:21 +0100 Subject: Playlist{Info,Vector}: move to db/ --- Makefile.am | 6 ++-- src/PlaylistDatabase.cxx | 2 +- src/PlaylistFile.cxx | 4 +-- src/PlaylistInfo.hxx | 63 -------------------------------- src/PlaylistVector.cxx | 66 ---------------------------------- src/PlaylistVector.hxx | 56 ----------------------------- src/command/OtherCommands.cxx | 2 +- src/command/PlaylistCommands.cxx | 2 +- src/db/PlaylistInfo.hxx | 63 ++++++++++++++++++++++++++++++++ src/db/PlaylistVector.cxx | 66 ++++++++++++++++++++++++++++++++++ src/db/PlaylistVector.hxx | 56 +++++++++++++++++++++++++++++ src/db/plugins/ProxyDatabasePlugin.cxx | 2 +- src/db/update/UpdateDatabase.cxx | 2 +- src/db/update/UpdateWalk.cxx | 2 +- test/DumpDatabase.cxx | 2 +- 15 files changed, 197 insertions(+), 197 deletions(-) delete mode 100644 src/PlaylistInfo.hxx delete mode 100644 src/PlaylistVector.cxx delete mode 100644 src/PlaylistVector.hxx create mode 100644 src/db/PlaylistInfo.hxx create mode 100644 src/db/PlaylistVector.cxx create mode 100644 src/db/PlaylistVector.hxx diff --git a/Makefile.am b/Makefile.am index ffa92e851..034fad69b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -187,8 +187,8 @@ src_mpd_SOURCES = \ src/PlaylistState.cxx src/PlaylistState.hxx \ src/playlist/PlaylistQueue.cxx src/playlist/PlaylistQueue.hxx \ src/playlist/Print.cxx src/playlist/Print.hxx \ - src/PlaylistVector.cxx src/PlaylistVector.hxx \ - src/PlaylistInfo.hxx \ + src/db/PlaylistVector.cxx src/db/PlaylistVector.hxx \ + src/db/PlaylistInfo.hxx \ src/PlaylistDatabase.cxx src/PlaylistDatabase.hxx \ src/PlaylistUpdate.cxx \ src/queue/IdTable.hxx \ @@ -1281,7 +1281,7 @@ test_DumpDatabase_SOURCES = test/DumpDatabase.cxx \ src/db/Registry.cxx \ src/db/Selection.cxx \ src/db/Directory.cxx src/db/DirectorySave.cxx \ - src/PlaylistVector.cxx src/PlaylistDatabase.cxx \ + src/db/PlaylistVector.cxx src/PlaylistDatabase.cxx \ src/db/DatabaseLock.cxx src/db/DatabaseSave.cxx \ src/db/Song.cxx src/SongSave.cxx src/db/SongSort.cxx \ src/DetachedSong.cxx \ diff --git a/src/PlaylistDatabase.cxx b/src/PlaylistDatabase.cxx index 065aea320..81aeae2cd 100644 --- a/src/PlaylistDatabase.cxx +++ b/src/PlaylistDatabase.cxx @@ -19,7 +19,7 @@ #include "config.h" #include "PlaylistDatabase.hxx" -#include "PlaylistVector.hxx" +#include "db/PlaylistVector.hxx" #include "fs/TextFile.hxx" #include "util/StringUtil.hxx" #include "util/Error.hxx" diff --git a/src/PlaylistFile.cxx b/src/PlaylistFile.cxx index 0b0f8d32d..71dbcba9c 100644 --- a/src/PlaylistFile.cxx +++ b/src/PlaylistFile.cxx @@ -20,8 +20,8 @@ #include "config.h" #include "PlaylistFile.hxx" #include "PlaylistSave.hxx" -#include "PlaylistInfo.hxx" -#include "PlaylistVector.hxx" +#include "db/PlaylistInfo.hxx" +#include "db/PlaylistVector.hxx" #include "db/DatabaseSong.hxx" #include "DetachedSong.hxx" #include "Mapper.hxx" diff --git a/src/PlaylistInfo.hxx b/src/PlaylistInfo.hxx deleted file mode 100644 index baa6cc361..000000000 --- a/src/PlaylistInfo.hxx +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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_PLAYLIST_INFO_HXX -#define MPD_PLAYLIST_INFO_HXX - -#include "check.h" -#include "Compiler.h" - -#include - -#include - -/** - * A directory entry pointing to a playlist file. - */ -struct PlaylistInfo { - /** - * The UTF-8 encoded name of the playlist file. - */ - std::string name; - - time_t mtime; - - class CompareName { - const char *const name; - - public: - constexpr CompareName(const char *_name):name(_name) {} - - gcc_pure - bool operator()(const PlaylistInfo &pi) const { - return pi.name.compare(name) == 0; - } - }; - - PlaylistInfo() = default; - - template - PlaylistInfo(N &&_name, time_t _mtime) - :name(std::forward(_name)), mtime(_mtime) {} - - PlaylistInfo(const PlaylistInfo &other) = delete; - PlaylistInfo(PlaylistInfo &&) = default; -}; - -#endif diff --git a/src/PlaylistVector.cxx b/src/PlaylistVector.cxx deleted file mode 100644 index 82a3519d9..000000000 --- a/src/PlaylistVector.cxx +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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 "PlaylistVector.hxx" -#include "db/DatabaseLock.hxx" - -#include - -#include - -PlaylistVector::iterator -PlaylistVector::find(const char *name) -{ - assert(holding_db_lock()); - assert(name != nullptr); - - return std::find_if(begin(), end(), - PlaylistInfo::CompareName(name)); -} - -bool -PlaylistVector::UpdateOrInsert(PlaylistInfo &&pi) -{ - assert(holding_db_lock()); - - auto i = find(pi.name.c_str()); - if (i != end()) { - if (pi.mtime == i->mtime) - return false; - - i->mtime = pi.mtime; - } else - push_back(std::move(pi)); - - return true; -} - -bool -PlaylistVector::erase(const char *name) -{ - assert(holding_db_lock()); - - auto i = find(name); - if (i == end()) - return false; - - erase(i); - return true; -} diff --git a/src/PlaylistVector.hxx b/src/PlaylistVector.hxx deleted file mode 100644 index 8820ead5c..000000000 --- a/src/PlaylistVector.hxx +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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_PLAYLIST_VECTOR_HXX -#define MPD_PLAYLIST_VECTOR_HXX - -#include "PlaylistInfo.hxx" -#include "Compiler.h" - -#include - -class PlaylistVector : protected std::list { -protected: - /** - * Caller must lock the #db_mutex. - */ - gcc_pure - iterator find(const char *name); - -public: - using std::list::empty; - using std::list::begin; - using std::list::end; - using std::list::push_back; - using std::list::erase; - - /** - * Caller must lock the #db_mutex. - * - * @return true if the vector or one of its items was modified - */ - bool UpdateOrInsert(PlaylistInfo &&pi); - - /** - * Caller must lock the #db_mutex. - */ - bool erase(const char *name); -}; - -#endif /* SONGVEC_H */ diff --git a/src/command/OtherCommands.cxx b/src/command/OtherCommands.cxx index 6432ce4e7..328683d3d 100644 --- a/src/command/OtherCommands.cxx +++ b/src/command/OtherCommands.cxx @@ -42,7 +42,7 @@ #include "Stats.hxx" #include "Permission.hxx" #include "PlaylistFile.hxx" -#include "PlaylistVector.hxx" +#include "db/PlaylistVector.hxx" #include "client/ClientFile.hxx" #include "client/Client.hxx" #include "Idle.hxx" diff --git a/src/command/PlaylistCommands.cxx b/src/command/PlaylistCommands.cxx index fbbb66757..bd2e24a17 100644 --- a/src/command/PlaylistCommands.cxx +++ b/src/command/PlaylistCommands.cxx @@ -24,7 +24,7 @@ #include "PlaylistPrint.hxx" #include "PlaylistSave.hxx" #include "PlaylistFile.hxx" -#include "PlaylistVector.hxx" +#include "db/PlaylistVector.hxx" #include "playlist/PlaylistQueue.hxx" #include "playlist/Print.hxx" #include "TimePrint.hxx" diff --git a/src/db/PlaylistInfo.hxx b/src/db/PlaylistInfo.hxx new file mode 100644 index 000000000..baa6cc361 --- /dev/null +++ b/src/db/PlaylistInfo.hxx @@ -0,0 +1,63 @@ +/* + * 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_PLAYLIST_INFO_HXX +#define MPD_PLAYLIST_INFO_HXX + +#include "check.h" +#include "Compiler.h" + +#include + +#include + +/** + * A directory entry pointing to a playlist file. + */ +struct PlaylistInfo { + /** + * The UTF-8 encoded name of the playlist file. + */ + std::string name; + + time_t mtime; + + class CompareName { + const char *const name; + + public: + constexpr CompareName(const char *_name):name(_name) {} + + gcc_pure + bool operator()(const PlaylistInfo &pi) const { + return pi.name.compare(name) == 0; + } + }; + + PlaylistInfo() = default; + + template + PlaylistInfo(N &&_name, time_t _mtime) + :name(std::forward(_name)), mtime(_mtime) {} + + PlaylistInfo(const PlaylistInfo &other) = delete; + PlaylistInfo(PlaylistInfo &&) = default; +}; + +#endif diff --git a/src/db/PlaylistVector.cxx b/src/db/PlaylistVector.cxx new file mode 100644 index 000000000..82a3519d9 --- /dev/null +++ b/src/db/PlaylistVector.cxx @@ -0,0 +1,66 @@ +/* + * 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 "PlaylistVector.hxx" +#include "db/DatabaseLock.hxx" + +#include + +#include + +PlaylistVector::iterator +PlaylistVector::find(const char *name) +{ + assert(holding_db_lock()); + assert(name != nullptr); + + return std::find_if(begin(), end(), + PlaylistInfo::CompareName(name)); +} + +bool +PlaylistVector::UpdateOrInsert(PlaylistInfo &&pi) +{ + assert(holding_db_lock()); + + auto i = find(pi.name.c_str()); + if (i != end()) { + if (pi.mtime == i->mtime) + return false; + + i->mtime = pi.mtime; + } else + push_back(std::move(pi)); + + return true; +} + +bool +PlaylistVector::erase(const char *name) +{ + assert(holding_db_lock()); + + auto i = find(name); + if (i == end()) + return false; + + erase(i); + return true; +} diff --git a/src/db/PlaylistVector.hxx b/src/db/PlaylistVector.hxx new file mode 100644 index 000000000..8820ead5c --- /dev/null +++ b/src/db/PlaylistVector.hxx @@ -0,0 +1,56 @@ +/* + * 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_PLAYLIST_VECTOR_HXX +#define MPD_PLAYLIST_VECTOR_HXX + +#include "PlaylistInfo.hxx" +#include "Compiler.h" + +#include + +class PlaylistVector : protected std::list { +protected: + /** + * Caller must lock the #db_mutex. + */ + gcc_pure + iterator find(const char *name); + +public: + using std::list::empty; + using std::list::begin; + using std::list::end; + using std::list::push_back; + using std::list::erase; + + /** + * Caller must lock the #db_mutex. + * + * @return true if the vector or one of its items was modified + */ + bool UpdateOrInsert(PlaylistInfo &&pi); + + /** + * Caller must lock the #db_mutex. + */ + bool erase(const char *name); +}; + +#endif /* SONGVEC_H */ diff --git a/src/db/plugins/ProxyDatabasePlugin.cxx b/src/db/plugins/ProxyDatabasePlugin.cxx index daa963c7d..291b1bc1f 100644 --- a/src/db/plugins/ProxyDatabasePlugin.cxx +++ b/src/db/plugins/ProxyDatabasePlugin.cxx @@ -23,7 +23,7 @@ #include "db/DatabaseListener.hxx" #include "db/Selection.hxx" #include "db/DatabaseError.hxx" -#include "PlaylistInfo.hxx" +#include "db/PlaylistInfo.hxx" #include "db/LightDirectory.hxx" #include "db/LightSong.hxx" #include "SongFilter.hxx" diff --git a/src/db/update/UpdateDatabase.cxx b/src/db/update/UpdateDatabase.cxx index 8ef0b6d82..72a68de14 100644 --- a/src/db/update/UpdateDatabase.cxx +++ b/src/db/update/UpdateDatabase.cxx @@ -20,7 +20,7 @@ #include "config.h" /* must be first for large file support */ #include "UpdateDatabase.hxx" #include "UpdateRemove.hxx" -#include "PlaylistVector.hxx" +#include "db/PlaylistVector.hxx" #include "db/Directory.hxx" #include "db/Song.hxx" #include "db/DatabaseLock.hxx" diff --git a/src/db/update/UpdateWalk.cxx b/src/db/update/UpdateWalk.cxx index c5a9936e9..75924a7f7 100644 --- a/src/db/update/UpdateWalk.cxx +++ b/src/db/update/UpdateWalk.cxx @@ -28,7 +28,7 @@ #include "db/DatabaseSimple.hxx" #include "db/Directory.hxx" #include "db/Song.hxx" -#include "PlaylistVector.hxx" +#include "db/PlaylistVector.hxx" #include "playlist/PlaylistRegistry.hxx" #include "Mapper.hxx" #include "ExcludeList.hxx" diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx index 0be1191d2..af1139407 100644 --- a/test/DumpDatabase.cxx +++ b/test/DumpDatabase.cxx @@ -24,7 +24,7 @@ #include "db/DatabaseListener.hxx" #include "db/LightDirectory.hxx" #include "db/LightSong.hxx" -#include "PlaylistVector.hxx" +#include "db/PlaylistVector.hxx" #include "config/ConfigGlobal.hxx" #include "config/ConfigData.hxx" #include "tag/TagConfig.hxx" -- cgit v1.2.3