PlaylistInfo: rename class, use std::string

This commit is contained in:
Max Kellermann 2013-01-02 22:04:03 +01:00
parent 98dbdf72b3
commit 8331de424a
12 changed files with 54 additions and 103 deletions

View File

@ -303,7 +303,7 @@ src_mpd_SOURCES = \
src/PlaylistState.cxx src/PlaylistState.hxx \
src/PlaylistQueue.cxx src/PlaylistQueue.hxx \
src/PlaylistVector.cxx src/PlaylistVector.hxx \
src/PlaylistInfo.cxx src/PlaylistInfo.hxx \
src/PlaylistInfo.hxx \
src/PlaylistDatabase.cxx \
src/queue.c \
src/QueuePrint.cxx src/QueuePrint.hxx \
@ -1072,7 +1072,7 @@ test_DumpDatabase_SOURCES = test/DumpDatabase.cxx \
src/DatabaseRegistry.cxx \
src/DatabaseSelection.cxx \
src/Directory.cxx src/DirectorySave.cxx \
src/PlaylistVector.cxx src/PlaylistInfo.cxx src/PlaylistDatabase.cxx \
src/PlaylistVector.cxx src/PlaylistDatabase.cxx \
src/DatabaseLock.cxx src/DatabaseSave.cxx \
src/Song.cxx src/song_sort.c src/SongSave.cxx \
src/tag.c src/tag_pool.c src/TagSave.cxx \

View File

@ -91,19 +91,19 @@ PrintSongFull(struct client *client, song &song)
static bool
PrintPlaylistBrief(struct client *client,
const playlist_metadata &playlist,
const PlaylistInfo &playlist,
const directory &directory)
{
print_playlist_in_directory(client, directory, playlist.name);
print_playlist_in_directory(client, directory, playlist.name.c_str());
return true;
}
static bool
PrintPlaylistFull(struct client *client,
const playlist_metadata &playlist,
const PlaylistInfo &playlist,
const directory &directory)
{
print_playlist_in_directory(client, directory, playlist.name);
print_playlist_in_directory(client, directory, playlist.name.c_str());
if (playlist.mtime > 0)
time_print(client, "Last-Modified", playlist.mtime);

View File

@ -26,11 +26,11 @@
struct directory;
struct song;
struct playlist_metadata;
struct PlaylistInfo;
typedef std::function<bool(const directory &, GError **)> VisitDirectory;
typedef std::function<bool(struct song &, GError **)> VisitSong;
typedef std::function<bool(const playlist_metadata &, const directory &,
typedef std::function<bool(const PlaylistInfo &, const directory &,
GError **)> VisitPlaylist;
typedef std::function<bool(const char *, GError **)> VisitString;

View File

@ -307,7 +307,7 @@ directory::Walk(bool recursive, const SongFilter *filter,
}
if (visit_playlist) {
struct playlist_metadata *i;
PlaylistInfo *i;
directory_for_each_playlist(i, this)
if (!visit_playlist(*i, *this, error_r))
return false;

View File

@ -38,20 +38,19 @@ playlist_database_quark(void)
void
playlist_vector_save(FILE *fp, const struct list_head *pv)
{
struct playlist_metadata *pm;
PlaylistInfo *pm;
playlist_vector_for_each(pm, pv)
fprintf(fp, PLAYLIST_META_BEGIN "%s\n"
"mtime: %li\n"
"playlist_end\n",
pm->name, (long)pm->mtime);
pm->name.c_str(), (long)pm->mtime);
}
bool
playlist_metadata_load(FILE *fp, struct list_head *pv, const char *name,
GString *buffer, GError **error_r)
{
struct playlist_metadata pm;
pm.mtime = 0;
PlaylistInfo pm(name, 0);
char *line, *colon;
const char *value;
@ -77,6 +76,6 @@ playlist_metadata_load(FILE *fp, struct list_head *pv, const char *name,
}
}
playlist_vector_update_or_add(pv, name, pm.mtime);
playlist_vector_update_or_add(pv, std::move(pm));
return true;
}

View File

@ -1,46 +0,0 @@
/*
* 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.
*/
#include "config.h"
#include "PlaylistInfo.hxx"
#include <glib.h>
#include <assert.h>
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;
}
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);
}

View File

@ -23,26 +23,29 @@
#include "check.h"
#include "util/list.h"
#include <string>
#include <sys/time.h>
/**
* A directory entry pointing to a playlist file.
*/
struct playlist_metadata {
struct PlaylistInfo {
struct list_head siblings;
/**
* The UTF-8 encoded name of the playlist file.
*/
char *name;
std::string name;
time_t mtime;
template<typename N>
PlaylistInfo(N &&_name, time_t _mtime)
:name(std::forward<N>(_name)), mtime(_mtime) {}
PlaylistInfo(const PlaylistInfo &other) = delete;
PlaylistInfo(PlaylistInfo &&) = default;
};
struct playlist_metadata *
playlist_metadata_new(const char *name, time_t mtime);
void
playlist_metadata_free(struct playlist_metadata *pm);
#endif

View File

@ -30,50 +30,48 @@ playlist_vector_deinit(struct list_head *pv)
{
assert(pv != NULL);
struct playlist_metadata *pm, *n;
PlaylistInfo *pm, *n;
playlist_vector_for_each_safe(pm, n, pv)
playlist_metadata_free(pm);
delete pm;
}
struct playlist_metadata *
PlaylistInfo *
playlist_vector_find(struct list_head *pv, const char *name)
{
assert(holding_db_lock());
assert(pv != NULL);
assert(name != NULL);
struct playlist_metadata *pm;
PlaylistInfo *pm;
playlist_vector_for_each(pm, pv)
if (strcmp(pm->name, name) == 0)
if (pm->name.compare(name) == 0)
return pm;
return NULL;
}
void
playlist_vector_add(struct list_head *pv,
const char *name, time_t mtime)
playlist_vector_add(struct list_head *pv, PlaylistInfo &&pi)
{
assert(holding_db_lock());
struct playlist_metadata *pm = playlist_metadata_new(name, mtime);
PlaylistInfo *pm = new PlaylistInfo(std::move(pi));
list_add_tail(&pm->siblings, pv);
}
bool
playlist_vector_update_or_add(struct list_head *pv,
const char *name, time_t mtime)
playlist_vector_update_or_add(struct list_head *pv, PlaylistInfo &&pi)
{
assert(holding_db_lock());
struct playlist_metadata *pm = playlist_vector_find(pv, name);
PlaylistInfo *pm = playlist_vector_find(pv, pi.name.c_str());
if (pm != NULL) {
if (mtime == pm->mtime)
if (pi.mtime == pm->mtime)
return false;
pm->mtime = mtime;
pm->mtime = pi.mtime;
} else
playlist_vector_add(pv, name, mtime);
playlist_vector_add(pv, std::move(pi));
return true;
}
@ -83,11 +81,11 @@ playlist_vector_remove(struct list_head *pv, const char *name)
{
assert(holding_db_lock());
struct playlist_metadata *pm = playlist_vector_find(pv, name);
PlaylistInfo *pm = playlist_vector_find(pv, name);
if (pm == NULL)
return false;
list_del(&pm->siblings);
playlist_metadata_free(pm);
delete pm;
return true;
}

View File

@ -37,15 +37,14 @@ playlist_vector_deinit(struct list_head *pv);
/**
* Caller must lock the #db_mutex.
*/
struct playlist_metadata *
PlaylistInfo *
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);
playlist_vector_add(struct list_head *pv, PlaylistInfo &&pi);
/**
* Caller must lock the #db_mutex.
@ -53,8 +52,7 @@ playlist_vector_add(struct list_head *pv,
* @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);
playlist_vector_update_or_add(struct list_head *pv, PlaylistInfo &&pi);
/**
* Caller must lock the #db_mutex.

View File

@ -159,11 +159,12 @@ purge_deleted_from_directory(struct directory *directory)
g_free(path);
}
struct playlist_metadata *pm, *np;
PlaylistInfo *pm, *np;
directory_for_each_playlist_safe(pm, np, directory) {
if (!directory_child_is_regular(directory, pm->name)) {
if (!directory_child_is_regular(directory, pm->name.c_str())) {
db_lock();
playlist_vector_remove(&directory->playlists, pm->name);
playlist_vector_remove(&directory->playlists,
pm->name.c_str());
db_unlock();
}
}
@ -214,9 +215,11 @@ update_playlist_file2(struct directory *directory,
if (!playlist_suffix_supported(suffix))
return false;
PlaylistInfo pi(name, st->st_mtime);
db_lock();
if (playlist_vector_update_or_add(&directory->playlists, name,
st->st_mtime))
if (playlist_vector_update_or_add(&directory->playlists,
std::move(pi)))
modified = true;
db_unlock();
return true;

View File

@ -314,14 +314,10 @@ Visit(const struct mpd_playlist *playlist,
if (!visit_playlist)
return true;
struct playlist_metadata p;
p.name = g_strdup(mpd_playlist_get_path(playlist));
p.mtime = mpd_playlist_get_last_modified(playlist);
PlaylistInfo p(mpd_playlist_get_path(playlist),
mpd_playlist_get_last_modified(playlist));
bool success = visit_playlist(p, detached_root, error_r);
g_free(p.name);
return success;
return visit_playlist(p, detached_root, error_r);
}
class ProxyEntity {

View File

@ -62,10 +62,10 @@ DumpSong(song &song, GError **)
}
static bool
DumpPlaylist(const playlist_metadata &playlist,
DumpPlaylist(const PlaylistInfo &playlist,
const directory &directory, GError **)
{
cout << "P " << directory.path << "/" << playlist.name << endl;
cout << "P " << directory.path << "/" << playlist.name.c_str() << endl;
return true;
}