playlist/Plugin: pass InputStreamPtr&& to open_stream()
Obsolete class CloseSongEnumerator, which was a kludge.
This commit is contained in:
@@ -144,7 +144,7 @@ asx_char_data(void *user_data, const XML_Char *s, int len)
|
||||
*/
|
||||
|
||||
static SongEnumerator *
|
||||
asx_open_stream(InputStream &is)
|
||||
asx_open_stream(InputStreamPtr &&is)
|
||||
{
|
||||
AsxParser parser;
|
||||
|
||||
@@ -154,7 +154,7 @@ asx_open_stream(InputStream &is)
|
||||
expat.SetCharacterDataHandler(asx_char_data);
|
||||
|
||||
Error error;
|
||||
if (!expat.Parse(is, error)) {
|
||||
if (!expat.Parse(*is, error)) {
|
||||
LogError(error);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -27,22 +27,21 @@
|
||||
#include <string>
|
||||
|
||||
class CuePlaylist final : public SongEnumerator {
|
||||
InputStream &is;
|
||||
TextInputStream tis;
|
||||
CueParser parser;
|
||||
|
||||
public:
|
||||
CuePlaylist(InputStream &_is)
|
||||
:is(_is), tis(is) {
|
||||
CuePlaylist(InputStreamPtr &&is)
|
||||
:tis(std::move(is)) {
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<DetachedSong> NextSong() override;
|
||||
};
|
||||
|
||||
static SongEnumerator *
|
||||
cue_playlist_open_stream(InputStream &is)
|
||||
cue_playlist_open_stream(InputStreamPtr &&is)
|
||||
{
|
||||
return new CuePlaylist(is);
|
||||
return new CuePlaylist(std::move(is));
|
||||
}
|
||||
|
||||
std::unique_ptr<DetachedSong>
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "util/StringUtil.hxx"
|
||||
#include "util/StringCompare.hxx"
|
||||
#include "input/TextInputStream.hxx"
|
||||
#include "input/InputStream.hxx"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -35,28 +36,36 @@ class ExtM3uPlaylist final : public SongEnumerator {
|
||||
TextInputStream tis;
|
||||
|
||||
public:
|
||||
ExtM3uPlaylist(InputStream &is)
|
||||
:tis(is) {
|
||||
ExtM3uPlaylist(InputStreamPtr &&is)
|
||||
:tis(std::move(is)) {
|
||||
}
|
||||
|
||||
bool CheckFirstLine() {
|
||||
/**
|
||||
* @return nullptr if ExtM3U was recognized, or the original
|
||||
* InputStream on error
|
||||
*/
|
||||
InputStreamPtr CheckFirstLine() {
|
||||
char *line = tis.ReadLine();
|
||||
if (line == nullptr)
|
||||
return false;
|
||||
return tis.StealInputStream();
|
||||
|
||||
StripRight(line);
|
||||
return strcmp(line, "#EXTM3U") == 0;
|
||||
if (strcmp(line, "#EXTM3U") != 0)
|
||||
return tis.StealInputStream();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<DetachedSong> NextSong() override;
|
||||
};
|
||||
|
||||
static SongEnumerator *
|
||||
extm3u_open_stream(InputStream &is)
|
||||
extm3u_open_stream(InputStreamPtr &&is)
|
||||
{
|
||||
ExtM3uPlaylist *playlist = new ExtM3uPlaylist(is);
|
||||
ExtM3uPlaylist *playlist = new ExtM3uPlaylist(std::move(is));
|
||||
|
||||
if (!playlist->CheckFirstLine()) {
|
||||
is = playlist->CheckFirstLine();
|
||||
if (is) {
|
||||
/* no EXTM3U header: fall back to the plain m3u
|
||||
plugin */
|
||||
delete playlist;
|
||||
|
||||
@@ -29,17 +29,17 @@ class M3uPlaylist final : public SongEnumerator {
|
||||
TextInputStream tis;
|
||||
|
||||
public:
|
||||
M3uPlaylist(InputStream &is)
|
||||
:tis(is) {
|
||||
M3uPlaylist(InputStreamPtr &&is)
|
||||
:tis(std::move(is)) {
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<DetachedSong> NextSong() override;
|
||||
};
|
||||
|
||||
static SongEnumerator *
|
||||
m3u_open_stream(InputStream &is)
|
||||
m3u_open_stream(InputStreamPtr &&is)
|
||||
{
|
||||
return new M3uPlaylist(is);
|
||||
return new M3uPlaylist(std::move(is));
|
||||
}
|
||||
|
||||
std::unique_ptr<DetachedSong>
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "../PlaylistPlugin.hxx"
|
||||
#include "../MemorySongEnumerator.hxx"
|
||||
#include "input/TextInputStream.hxx"
|
||||
#include "input/InputStream.hxx"
|
||||
#include "DetachedSong.hxx"
|
||||
#include "tag/TagBuilder.hxx"
|
||||
#include "util/ASCII.hxx"
|
||||
@@ -142,17 +143,22 @@ ParsePls(TextInputStream &is, std::forward_list<DetachedSong> &songs)
|
||||
}
|
||||
|
||||
static bool
|
||||
ParsePls(InputStream &is, std::forward_list<DetachedSong> &songs)
|
||||
ParsePls(InputStreamPtr &&is, std::forward_list<DetachedSong> &songs)
|
||||
{
|
||||
TextInputStream tis(is);
|
||||
return ParsePls(tis, songs);
|
||||
TextInputStream tis(std::move(is));
|
||||
if (!ParsePls(tis, songs)) {
|
||||
is = tis.StealInputStream();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static SongEnumerator *
|
||||
pls_open_stream(InputStream &is)
|
||||
pls_open_stream(InputStreamPtr &&is)
|
||||
{
|
||||
std::forward_list<DetachedSong> songs;
|
||||
if (!ParsePls(is, songs))
|
||||
if (!ParsePls(std::move(is), songs))
|
||||
return nullptr;
|
||||
|
||||
return new MemorySongEnumerator(std::move(songs));
|
||||
|
||||
@@ -142,7 +142,7 @@ rss_char_data(void *user_data, const XML_Char *s, int len)
|
||||
*/
|
||||
|
||||
static SongEnumerator *
|
||||
rss_open_stream(InputStream &is)
|
||||
rss_open_stream(InputStreamPtr &&is)
|
||||
{
|
||||
RssParser parser;
|
||||
|
||||
@@ -152,7 +152,7 @@ rss_open_stream(InputStream &is)
|
||||
expat.SetCharacterDataHandler(rss_char_data);
|
||||
|
||||
Error error;
|
||||
if (!expat.Parse(is, error)) {
|
||||
if (!expat.Parse(*is, error)) {
|
||||
LogError(error);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ xspf_char_data(void *user_data, const XML_Char *s, int len)
|
||||
*/
|
||||
|
||||
static SongEnumerator *
|
||||
xspf_open_stream(InputStream &is)
|
||||
xspf_open_stream(InputStreamPtr &&is)
|
||||
{
|
||||
XspfParser parser;
|
||||
|
||||
@@ -199,7 +199,7 @@ xspf_open_stream(InputStream &is)
|
||||
expat.SetCharacterDataHandler(xspf_char_data);
|
||||
|
||||
Error error;
|
||||
if (!expat.Parse(is, error)) {
|
||||
if (!expat.Parse(*is, error)) {
|
||||
LogError(error);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user