Commit 9d312ab2 authored by Max Kellermann's avatar Max Kellermann

PlaylistFile: reuse classes PlaylistInfo and PlaylistVector

.. instead of rolling own classes.
parent 06be0a19
...@@ -57,7 +57,7 @@ extern "C" { ...@@ -57,7 +57,7 @@ extern "C" {
#include <string.h> #include <string.h>
static void static void
print_spl_list(Client *client, const PlaylistFileList &list) print_spl_list(Client *client, const PlaylistVector &list)
{ {
for (const auto &i : list) { for (const auto &i : list) {
client_printf(client, "playlist: %s\n", i.name.c_str()); client_printf(client, "playlist: %s\n", i.name.c_str());
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "PlaylistPrint.hxx" #include "PlaylistPrint.hxx"
#include "PlaylistSave.hxx" #include "PlaylistSave.hxx"
#include "PlaylistFile.hxx" #include "PlaylistFile.hxx"
#include "PlaylistVector.hxx"
#include "PlaylistQueue.hxx" #include "PlaylistQueue.hxx"
#include "TimePrint.hxx" #include "TimePrint.hxx"
#include "ClientInternal.hxx" #include "ClientInternal.hxx"
...@@ -40,7 +41,7 @@ extern "C" { ...@@ -40,7 +41,7 @@ extern "C" {
#include <stdlib.h> #include <stdlib.h>
static void static void
print_spl_list(Client *client, const PlaylistFileList &list) print_spl_list(Client *client, const PlaylistVector &list)
{ {
for (const auto &i : list) { for (const auto &i : list) {
client_printf(client, "playlist: %s\n", i.name.c_str()); client_printf(client, "playlist: %s\n", i.name.c_str());
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "config.h" #include "config.h"
#include "PlaylistFile.hxx" #include "PlaylistFile.hxx"
#include "PlaylistSave.hxx" #include "PlaylistSave.hxx"
#include "PlaylistInfo.hxx"
#include "PlaylistVector.hxx"
#include "DatabasePlugin.hxx" #include "DatabasePlugin.hxx"
#include "DatabaseGlue.hxx" #include "DatabaseGlue.hxx"
#include "song.h" #include "song.h"
...@@ -140,7 +142,7 @@ playlist_errno(GError **error_r) ...@@ -140,7 +142,7 @@ playlist_errno(GError **error_r)
} }
static bool static bool
LoadPlaylistFileInfo(PlaylistFileInfo &info, LoadPlaylistFileInfo(PlaylistInfo &info,
const char *parent_path_fs, const char *name_fs) const char *parent_path_fs, const char *name_fs)
{ {
size_t name_length = strlen(name_fs); size_t name_length = strlen(name_fs);
...@@ -172,10 +174,10 @@ LoadPlaylistFileInfo(PlaylistFileInfo &info, ...@@ -172,10 +174,10 @@ LoadPlaylistFileInfo(PlaylistFileInfo &info,
return true; return true;
} }
PlaylistFileList PlaylistVector
ListPlaylistFiles(GError **error_r) ListPlaylistFiles(GError **error_r)
{ {
PlaylistFileList list; PlaylistVector list;
const char *parent_path_fs = spl_map(error_r); const char *parent_path_fs = spl_map(error_r);
if (parent_path_fs == NULL) if (parent_path_fs == NULL)
...@@ -187,7 +189,7 @@ ListPlaylistFiles(GError **error_r) ...@@ -187,7 +189,7 @@ ListPlaylistFiles(GError **error_r)
return list; return list;
} }
PlaylistFileInfo info; PlaylistInfo info;
struct dirent *ent; struct dirent *ent;
while ((ent = readdir(dir)) != NULL) { while ((ent = readdir(dir)) != NULL) {
if (LoadPlaylistFileInfo(info, parent_path_fs, ent->d_name)) if (LoadPlaylistFileInfo(info, parent_path_fs, ent->d_name))
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#ifndef MPD_PLAYLIST_FILE_HXX #ifndef MPD_PLAYLIST_FILE_HXX
#define MPD_PLAYLIST_FILE_HXX #define MPD_PLAYLIST_FILE_HXX
#include <list>
#include <vector> #include <vector>
#include <string> #include <string>
...@@ -28,14 +27,8 @@ ...@@ -28,14 +27,8 @@
#include <time.h> #include <time.h>
struct song; struct song;
struct PlaylistInfo;
struct PlaylistFileInfo { class PlaylistVector;
std::string name;
time_t mtime;
};
typedef std::list<PlaylistFileInfo> PlaylistFileList;
typedef std::vector<std::string> PlaylistFileContents; typedef std::vector<std::string> PlaylistFileContents;
...@@ -60,7 +53,7 @@ spl_valid_name(const char *name_utf8); ...@@ -60,7 +53,7 @@ spl_valid_name(const char *name_utf8);
* Returns a list of stored_playlist_info struct pointers. Returns * Returns a list of stored_playlist_info struct pointers. Returns
* NULL if an error occurred. * NULL if an error occurred.
*/ */
PlaylistFileList PlaylistVector
ListPlaylistFiles(GError **error_r); ListPlaylistFiles(GError **error_r);
PlaylistFileContents PlaylistFileContents
......
...@@ -50,6 +50,8 @@ struct PlaylistInfo { ...@@ -50,6 +50,8 @@ struct PlaylistInfo {
} }
}; };
PlaylistInfo() = default;
template<typename N> template<typename N>
PlaylistInfo(N &&_name, time_t _mtime) PlaylistInfo(N &&_name, time_t _mtime)
:name(std::forward<N>(_name)), mtime(_mtime) {} :name(std::forward<N>(_name)), mtime(_mtime) {}
......
...@@ -37,6 +37,7 @@ public: ...@@ -37,6 +37,7 @@ public:
using std::list<PlaylistInfo>::empty; using std::list<PlaylistInfo>::empty;
using std::list<PlaylistInfo>::begin; using std::list<PlaylistInfo>::begin;
using std::list<PlaylistInfo>::end; using std::list<PlaylistInfo>::end;
using std::list<PlaylistInfo>::push_back;
using std::list<PlaylistInfo>::erase; using std::list<PlaylistInfo>::erase;
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment