From 0023dffd0bf8c5793e8e92b9eec9702a296ed8d2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 2 Jan 2013 20:25:20 +0100 Subject: playlist_vector: convert to C++ --- src/DatabasePrint.cxx | 2 +- src/Directory.cxx | 2 +- src/PlaylistDatabase.cxx | 2 +- src/PlaylistVector.cxx | 114 +++++++++++++++++++++++++++++++++++++++++ src/PlaylistVector.hxx | 79 ++++++++++++++++++++++++++++ src/UpdateDatabase.cxx | 5 +- src/UpdateWalk.cxx | 2 +- src/db/ProxyDatabasePlugin.cxx | 2 +- src/playlist_vector.c | 114 ----------------------------------------- src/playlist_vector.h | 80 ----------------------------- 10 files changed, 199 insertions(+), 203 deletions(-) create mode 100644 src/PlaylistVector.cxx create mode 100644 src/PlaylistVector.hxx delete mode 100644 src/playlist_vector.c delete mode 100644 src/playlist_vector.h (limited to 'src') diff --git a/src/DatabasePrint.cxx b/src/DatabasePrint.cxx index 97ff9c12c..980aa0124 100644 --- a/src/DatabasePrint.cxx +++ b/src/DatabasePrint.cxx @@ -21,6 +21,7 @@ #include "DatabasePrint.hxx" #include "DatabaseSelection.hxx" #include "SongFilter.hxx" +#include "PlaylistVector.hxx" extern "C" { #include "database.h" @@ -28,7 +29,6 @@ extern "C" { #include "song.h" #include "song_print.h" #include "time_print.h" -#include "playlist_vector.h" #include "tag.h" } diff --git a/src/Directory.cxx b/src/Directory.cxx index eeba903d1..a371dc41a 100644 --- a/src/Directory.cxx +++ b/src/Directory.cxx @@ -20,11 +20,11 @@ #include "config.h" #include "directory.h" #include "SongFilter.hxx" +#include "PlaylistVector.hxx" extern "C" { #include "song.h" #include "song_sort.h" -#include "playlist_vector.h" #include "path.h" #include "util/list_sort.h" #include "db_lock.h" diff --git a/src/PlaylistDatabase.cxx b/src/PlaylistDatabase.cxx index b88ebbd6b..a2062a517 100644 --- a/src/PlaylistDatabase.cxx +++ b/src/PlaylistDatabase.cxx @@ -19,9 +19,9 @@ #include "config.h" #include "PlaylistDatabase.hxx" +#include "PlaylistVector.hxx" extern "C" { -#include "playlist_vector.h" #include "text_file.h" #include "string_util.h" } diff --git a/src/PlaylistVector.cxx b/src/PlaylistVector.cxx new file mode 100644 index 000000000..ea3172d0d --- /dev/null +++ b/src/PlaylistVector.cxx @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2003-2011 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_lock.h" + +#include +#include +#include + +static struct playlist_metadata * +playlist_metadata_new(const char *name, time_t mtime) +{ + assert(name != NULL); + + struct playlist_metadata *pm = g_slice_new(struct playlist_metadata); + pm->name = g_strdup(name); + pm->mtime = mtime; + return pm; +} + +static void +playlist_metadata_free(struct playlist_metadata *pm) +{ + assert(pm != NULL); + assert(pm->name != NULL); + + g_free(pm->name); + g_slice_free(struct playlist_metadata, pm); +} + +void +playlist_vector_deinit(struct list_head *pv) +{ + assert(pv != NULL); + + struct playlist_metadata *pm, *n; + playlist_vector_for_each_safe(pm, n, pv) + playlist_metadata_free(pm); +} + +struct playlist_metadata * +playlist_vector_find(struct list_head *pv, const char *name) +{ + assert(holding_db_lock()); + assert(pv != NULL); + assert(name != NULL); + + struct playlist_metadata *pm; + playlist_vector_for_each(pm, pv) + if (strcmp(pm->name, name) == 0) + return pm; + + return NULL; +} + +void +playlist_vector_add(struct list_head *pv, + const char *name, time_t mtime) +{ + assert(holding_db_lock()); + + struct playlist_metadata *pm = playlist_metadata_new(name, mtime); + list_add_tail(&pm->siblings, pv); +} + +bool +playlist_vector_update_or_add(struct list_head *pv, + const char *name, time_t mtime) +{ + assert(holding_db_lock()); + + struct playlist_metadata *pm = playlist_vector_find(pv, name); + if (pm != NULL) { + if (mtime == pm->mtime) + return false; + + pm->mtime = mtime; + } else + playlist_vector_add(pv, name, mtime); + + return true; +} + +bool +playlist_vector_remove(struct list_head *pv, const char *name) +{ + assert(holding_db_lock()); + + struct playlist_metadata *pm = playlist_vector_find(pv, name); + if (pm == NULL) + return false; + + list_del(&pm->siblings); + playlist_metadata_free(pm); + return true; +} diff --git a/src/PlaylistVector.hxx b/src/PlaylistVector.hxx new file mode 100644 index 000000000..00347ffdb --- /dev/null +++ b/src/PlaylistVector.hxx @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2003-2013 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 "util/list.h" + +#include +#include + +#define playlist_vector_for_each(pos, head) \ + list_for_each_entry(pos, head, siblings) + +#define playlist_vector_for_each_safe(pos, n, head) \ + list_for_each_entry_safe(pos, n, head, siblings) + +/** + * A directory entry pointing to a playlist file. + */ +struct playlist_metadata { + struct list_head siblings; + + /** + * The UTF-8 encoded name of the playlist file. + */ + char *name; + + time_t mtime; +}; + +void +playlist_vector_deinit(struct list_head *pv); + +/** + * Caller must lock the #db_mutex. + */ +struct playlist_metadata * +playlist_vector_find(struct list_head *pv, const char *name); + +/** + * Caller must lock the #db_mutex. + */ +void +playlist_vector_add(struct list_head *pv, + const char *name, time_t mtime); + +/** + * Caller must lock the #db_mutex. + * + * @return true if the vector or one of its items was modified + */ +bool +playlist_vector_update_or_add(struct list_head *pv, + const char *name, time_t mtime); + +/** + * Caller must lock the #db_mutex. + */ +bool +playlist_vector_remove(struct list_head *pv, const char *name); + +#endif /* SONGVEC_H */ diff --git a/src/UpdateDatabase.cxx b/src/UpdateDatabase.cxx index fa3408d66..e959a4ecc 100644 --- a/src/UpdateDatabase.cxx +++ b/src/UpdateDatabase.cxx @@ -20,14 +20,11 @@ #include "config.h" /* must be first for large file support */ #include "UpdateDatabase.hxx" #include "UpdateRemove.hxx" +#include "PlaylistVector.hxx" #include "directory.h" #include "song.h" #include "db_lock.h" -extern "C" { -#include "playlist_vector.h" -} - #include #include diff --git a/src/UpdateWalk.cxx b/src/UpdateWalk.cxx index a8ca1e4ed..33220ba76 100644 --- a/src/UpdateWalk.cxx +++ b/src/UpdateWalk.cxx @@ -26,11 +26,11 @@ #include "db_lock.h" #include "directory.h" #include "song.h" +#include "PlaylistVector.hxx" extern "C" { #include "exclude.h" #include "database.h" -#include "playlist_vector.h" #include "uri.h" #include "mapper.h" #include "path.h" diff --git a/src/db/ProxyDatabasePlugin.cxx b/src/db/ProxyDatabasePlugin.cxx index d36cebcfd..db8e56dda 100644 --- a/src/db/ProxyDatabasePlugin.cxx +++ b/src/db/ProxyDatabasePlugin.cxx @@ -21,6 +21,7 @@ #include "ProxyDatabasePlugin.hxx" #include "DatabasePlugin.hxx" #include "DatabaseSelection.hxx" +#include "PlaylistVector.hxx" #include "gcc.h" extern "C" { @@ -31,7 +32,6 @@ extern "C" { } #include "directory.h" -#include "playlist_vector.h" #undef MPD_DIRECTORY_H #undef MPD_SONG_H diff --git a/src/playlist_vector.c b/src/playlist_vector.c deleted file mode 100644 index 74c7bf089..000000000 --- a/src/playlist_vector.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2003-2011 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 "playlist_vector.h" -#include "db_lock.h" - -#include -#include -#include - -static struct playlist_metadata * -playlist_metadata_new(const char *name, time_t mtime) -{ - assert(name != NULL); - - struct playlist_metadata *pm = g_slice_new(struct playlist_metadata); - pm->name = g_strdup(name); - pm->mtime = mtime; - return pm; -} - -static void -playlist_metadata_free(struct playlist_metadata *pm) -{ - assert(pm != NULL); - assert(pm->name != NULL); - - g_free(pm->name); - g_slice_free(struct playlist_metadata, pm); -} - -void -playlist_vector_deinit(struct list_head *pv) -{ - assert(pv != NULL); - - struct playlist_metadata *pm, *n; - playlist_vector_for_each_safe(pm, n, pv) - playlist_metadata_free(pm); -} - -struct playlist_metadata * -playlist_vector_find(struct list_head *pv, const char *name) -{ - assert(holding_db_lock()); - assert(pv != NULL); - assert(name != NULL); - - struct playlist_metadata *pm; - playlist_vector_for_each(pm, pv) - if (strcmp(pm->name, name) == 0) - return pm; - - return NULL; -} - -void -playlist_vector_add(struct list_head *pv, - const char *name, time_t mtime) -{ - assert(holding_db_lock()); - - struct playlist_metadata *pm = playlist_metadata_new(name, mtime); - list_add_tail(&pm->siblings, pv); -} - -bool -playlist_vector_update_or_add(struct list_head *pv, - const char *name, time_t mtime) -{ - assert(holding_db_lock()); - - struct playlist_metadata *pm = playlist_vector_find(pv, name); - if (pm != NULL) { - if (mtime == pm->mtime) - return false; - - pm->mtime = mtime; - } else - playlist_vector_add(pv, name, mtime); - - return true; -} - -bool -playlist_vector_remove(struct list_head *pv, const char *name) -{ - assert(holding_db_lock()); - - struct playlist_metadata *pm = playlist_vector_find(pv, name); - if (pm == NULL) - return false; - - list_del(&pm->siblings); - playlist_metadata_free(pm); - return true; -} diff --git a/src/playlist_vector.h b/src/playlist_vector.h deleted file mode 100644 index 0af6df8b4..000000000 --- a/src/playlist_vector.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2003-2011 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_H -#define MPD_PLAYLIST_VECTOR_H - -#include "util/list.h" - -#include -#include -#include - -#define playlist_vector_for_each(pos, head) \ - list_for_each_entry(pos, head, siblings) - -#define playlist_vector_for_each_safe(pos, n, head) \ - list_for_each_entry_safe(pos, n, head, siblings) - -/** - * A directory entry pointing to a playlist file. - */ -struct playlist_metadata { - struct list_head siblings; - - /** - * The UTF-8 encoded name of the playlist file. - */ - char *name; - - time_t mtime; -}; - -void -playlist_vector_deinit(struct list_head *pv); - -/** - * Caller must lock the #db_mutex. - */ -struct playlist_metadata * -playlist_vector_find(struct list_head *pv, const char *name); - -/** - * Caller must lock the #db_mutex. - */ -void -playlist_vector_add(struct list_head *pv, - const char *name, time_t mtime); - -/** - * Caller must lock the #db_mutex. - * - * @return true if the vector or one of its items was modified - */ -bool -playlist_vector_update_or_add(struct list_head *pv, - const char *name, time_t mtime); - -/** - * Caller must lock the #db_mutex. - */ -bool -playlist_vector_remove(struct list_head *pv, const char *name); - -#endif /* SONGVEC_H */ -- cgit v1.2.3