From 2071070f39216accc02550102017e4f8abb9b5ea Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Jan 2014 19:21:48 +0100 Subject: DespotifyUtils: return Tag, not pointer --- src/DespotifyUtils.cxx | 7 +++---- src/DespotifyUtils.hxx | 4 ++-- src/input/DespotifyInputPlugin.cxx | 11 ++++++----- src/playlist/DespotifyPlaylistPlugin.cxx | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/DespotifyUtils.cxx b/src/DespotifyUtils.cxx index 2a30f11f3..8a499d75d 100644 --- a/src/DespotifyUtils.cxx +++ b/src/DespotifyUtils.cxx @@ -83,8 +83,7 @@ void mpd_despotify_unregister_callback(void (*cb)(struct despotify_session *, in } } - -Tag * +Tag mpd_despotify_tag_from_track(const ds_track &track) { char tracknum[20]; @@ -92,7 +91,7 @@ mpd_despotify_tag_from_track(const ds_track &track) char date[20]; if (!track.has_meta_data) - return new Tag(); + return Tag(); TagBuilder tag; snprintf(tracknum, sizeof(tracknum), "%d", track.tracknumber); @@ -108,7 +107,7 @@ mpd_despotify_tag_from_track(const ds_track &track) tag.AddItem(TAG_COMMENT, comment); tag.SetTime(track.length / 1000); - return tag.CommitNew(); + return tag.Commit(); } struct despotify_session *mpd_despotify_get_session(void) diff --git a/src/DespotifyUtils.hxx b/src/DespotifyUtils.hxx index ad22acf92..c8d90afa4 100644 --- a/src/DespotifyUtils.hxx +++ b/src/DespotifyUtils.hxx @@ -42,9 +42,9 @@ struct despotify_session *mpd_despotify_get_session(void); * * @param track the track to convert * - * @return a pointer to the filled in tags structure + * @return filled in #Tag structure */ -Tag * +Tag mpd_despotify_tag_from_track(const ds_track &track); /** diff --git a/src/input/DespotifyInputPlugin.cxx b/src/input/DespotifyInputPlugin.cxx index 787e0722e..18704bd40 100644 --- a/src/input/DespotifyInputPlugin.cxx +++ b/src/input/DespotifyInputPlugin.cxx @@ -41,7 +41,7 @@ class DespotifyInputStream { struct despotify_session *session; struct ds_track *track; - Tag *tag; + Tag tag; struct ds_pcm_data pcm; size_t len_available; bool eof; @@ -64,8 +64,6 @@ class DespotifyInputStream { public: ~DespotifyInputStream() { - delete tag; - despotify_free_track(track); } @@ -79,8 +77,11 @@ public: size_t Read(void *ptr, size_t size, Error &error); Tag *ReadTag() { - Tag *result = tag; - tag = nullptr; + if (tag.IsEmpty()) + return nullptr; + + Tag *result = new Tag(std::move(tag)); + tag.Clear(); return result; } diff --git a/src/playlist/DespotifyPlaylistPlugin.cxx b/src/playlist/DespotifyPlaylistPlugin.cxx index f082778ab..67400e20a 100644 --- a/src/playlist/DespotifyPlaylistPlugin.cxx +++ b/src/playlist/DespotifyPlaylistPlugin.cxx @@ -53,7 +53,7 @@ add_song(std::forward_list &songs, ds_track &track) } song = Song::NewRemote(uri); - song->tag = mpd_despotify_tag_from_track(track); + song->tag = new Tag(mpd_despotify_tag_from_track(track)); songs.emplace_front(song); } -- cgit v1.2.3