SongLoader: return instance, not pointer
This commit is contained in:
parent
d184231169
commit
f689e28958
@ -359,8 +359,7 @@ void
|
||||
spl_append_uri(const char *utf8file,
|
||||
const SongLoader &loader, const char *url)
|
||||
{
|
||||
std::unique_ptr<DetachedSong> song(loader.LoadSong(url));
|
||||
spl_append_song(utf8file, *song);
|
||||
spl_append_song(utf8file, loader.LoadSong(url));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -36,12 +36,12 @@ SongLoader::SongLoader(const Client &_client)
|
||||
|
||||
#endif
|
||||
|
||||
DetachedSong *
|
||||
DetachedSong
|
||||
SongLoader::LoadFromDatabase(const char *uri) const
|
||||
{
|
||||
#ifdef ENABLE_DATABASE
|
||||
if (db != nullptr)
|
||||
return new DetachedSong(DatabaseDetachSong(*db, *storage, uri));
|
||||
return DatabaseDetachSong(*db, *storage, uri);
|
||||
#else
|
||||
(void)uri;
|
||||
#endif
|
||||
@ -49,7 +49,7 @@ SongLoader::LoadFromDatabase(const char *uri) const
|
||||
throw PlaylistError(PlaylistResult::NO_SUCH_SONG, "No database");
|
||||
}
|
||||
|
||||
DetachedSong *
|
||||
DetachedSong
|
||||
SongLoader::LoadFile(const char *path_utf8, Path path_fs) const
|
||||
{
|
||||
#ifdef ENABLE_DATABASE
|
||||
@ -66,15 +66,15 @@ SongLoader::LoadFile(const char *path_utf8, Path path_fs) const
|
||||
if (!song.LoadFile(path_fs))
|
||||
throw PlaylistError::NoSuchSong();
|
||||
|
||||
return new DetachedSong(std::move(song));
|
||||
return song;
|
||||
}
|
||||
|
||||
DetachedSong *
|
||||
DetachedSong
|
||||
SongLoader::LoadSong(const LocatedUri &located_uri) const
|
||||
{
|
||||
switch (located_uri.type) {
|
||||
case LocatedUri::Type::ABSOLUTE:
|
||||
return new DetachedSong(located_uri.canonical_uri);
|
||||
return DetachedSong(located_uri.canonical_uri);
|
||||
|
||||
case LocatedUri::Type::RELATIVE:
|
||||
return LoadFromDatabase(located_uri.canonical_uri);
|
||||
@ -86,7 +86,7 @@ SongLoader::LoadSong(const LocatedUri &located_uri) const
|
||||
gcc_unreachable();
|
||||
}
|
||||
|
||||
DetachedSong *
|
||||
DetachedSong
|
||||
SongLoader::LoadSong(const char *uri_utf8) const
|
||||
{
|
||||
#if !CLANG_CHECK_VERSION(3,6)
|
||||
|
@ -67,20 +67,20 @@ public:
|
||||
}
|
||||
#endif
|
||||
|
||||
DetachedSong *LoadSong(const LocatedUri &uri) const;
|
||||
DetachedSong LoadSong(const LocatedUri &uri) const;
|
||||
|
||||
/**
|
||||
* Throws #std::runtime_error on error.
|
||||
*/
|
||||
gcc_nonnull_all
|
||||
DetachedSong *LoadSong(const char *uri_utf8) const;
|
||||
DetachedSong LoadSong(const char *uri_utf8) const;
|
||||
|
||||
private:
|
||||
gcc_nonnull_all
|
||||
DetachedSong *LoadFromDatabase(const char *uri) const;
|
||||
DetachedSong LoadFromDatabase(const char *uri) const;
|
||||
|
||||
gcc_nonnull_all
|
||||
DetachedSong *LoadFile(const char *path_utf8, Path path_fs) const;
|
||||
DetachedSong LoadFile(const char *path_utf8, Path path_fs) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -43,11 +43,9 @@
|
||||
static void
|
||||
AddUri(Client &client, const LocatedUri &uri)
|
||||
{
|
||||
std::unique_ptr<DetachedSong> song(SongLoader(client).LoadSong(uri));
|
||||
assert(song);
|
||||
|
||||
auto &partition = client.partition;
|
||||
partition.playlist.AppendSong(partition.pc, std::move(*song));
|
||||
partition.playlist.AppendSong(partition.pc,
|
||||
SongLoader(client).LoadSong(uri));
|
||||
}
|
||||
|
||||
static CommandResult
|
||||
|
@ -44,25 +44,17 @@ merge_song_metadata(DetachedSong &add, const DetachedSong &base)
|
||||
|
||||
static bool
|
||||
playlist_check_load_song(DetachedSong &song, const SongLoader &loader)
|
||||
{
|
||||
DetachedSong *tmp;
|
||||
try {
|
||||
DetachedSong tmp = loader.LoadSong(song.GetURI());
|
||||
|
||||
try {
|
||||
tmp = loader.LoadSong(song.GetURI());
|
||||
} catch (const std::runtime_error &) {
|
||||
return false;
|
||||
}
|
||||
song.SetURI(tmp.GetURI());
|
||||
if (!song.HasRealURI() && tmp.HasRealURI())
|
||||
song.SetRealURI(tmp.GetRealURI());
|
||||
|
||||
if (tmp == nullptr)
|
||||
return false;
|
||||
|
||||
song.SetURI(tmp->GetURI());
|
||||
if (!song.HasRealURI() && tmp->HasRealURI())
|
||||
song.SetRealURI(tmp->GetRealURI());
|
||||
|
||||
merge_song_metadata(song, *tmp);
|
||||
delete tmp;
|
||||
merge_song_metadata(song, tmp);
|
||||
return true;
|
||||
} catch (const std::runtime_error &) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -125,8 +125,7 @@ unsigned
|
||||
playlist::AppendURI(PlayerControl &pc, const SongLoader &loader,
|
||||
const char *uri)
|
||||
{
|
||||
std::unique_ptr<DetachedSong> song(loader.LoadSong(uri));
|
||||
return AppendSong(pc, std::move(*song));
|
||||
return AppendSong(pc, loader.LoadSong(uri));
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user