diff options
author | Max Kellermann <max@duempel.org> | 2014-01-07 21:39:47 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-09 09:05:58 +0100 |
commit | 322b0616322760dc162447563d8f4da7e024ca90 (patch) | |
tree | 2f87cb3ce061556161797aba9f57ee08de5b9e21 /src/Song.hxx | |
parent | 43847f2244a34064af24704aac4cfad4a3c76f7d (diff) | |
download | mpd-322b0616322760dc162447563d8f4da7e024ca90.tar.gz mpd-322b0616322760dc162447563d8f4da7e024ca90.tar.xz mpd-322b0616322760dc162447563d8f4da7e024ca90.zip |
DetachedSong: fork of struct Song
From now on, struct Song will be used by the database only, and
DetachedSong will be used by everybody else. DetachedSong is easier
to use, but Song has lower overhead.
Diffstat (limited to '')
-rw-r--r-- | src/Song.hxx | 67 |
1 files changed, 15 insertions, 52 deletions
diff --git a/src/Song.hxx b/src/Song.hxx index 21e158560..c9719edd7 100644 --- a/src/Song.hxx +++ b/src/Song.hxx @@ -32,13 +32,12 @@ #define SONG_TIME "Time: " struct Tag; +struct Directory; +class DetachedSong; /** - * A dummy #directory instance that is used for "detached" song - * copies. + * A song file inside the configured music directory. */ -extern struct Directory detached_root; - struct Song { /** * Pointers to the siblings of this directory within the @@ -51,7 +50,14 @@ struct Song { struct list_head siblings; Tag *tag; + + /** + * The #Directory that contains this song. May be nullptr if + * the current database plugin does not manage the parent + * directory this way. + */ Directory *parent; + time_t mtime; /** @@ -65,11 +71,14 @@ struct Song { */ unsigned end_ms; + /** + * The file name. If #parent is nullptr, then this is the URI + * relative to the music directory. + */ char uri[sizeof(int)]; - /** allocate a new song with a remote URL */ gcc_malloc - static Song *NewRemote(const char *uri); + static Song *NewFrom(DetachedSong &&other, Directory *parent); /** allocate a new song with a local file name */ gcc_malloc @@ -87,47 +96,8 @@ struct Song { return LoadFile(path_utf8, &parent); } - /** - * Replaces the URI of a song object. The given song object - * is destroyed, and a newly allocated one is returned. It - * does not update the reference within the parent directory; - * the caller is responsible for doing that. - */ - gcc_malloc - Song *ReplaceURI(const char *uri); - - /** - * Creates a "detached" song object. - */ - gcc_malloc - static Song *NewDetached(const char *uri); - - /** - * Creates a duplicate of the song object. If the object is - * in the database, it creates a "detached" copy of this song, - * see Song::IsDetached(). - */ - gcc_malloc - Song *DupDetached() const; - void Free(); - bool IsInDatabase() const { - return parent != nullptr; - } - - bool IsFile() const { - return IsInDatabase() || uri[0] == '/'; - } - - bool IsDetached() const { - assert(IsInDatabase()); - - return parent == &detached_root; - } - - void ReplaceTag(Tag &&tag); - bool UpdateFile(); bool UpdateFileInArchive(); @@ -142,11 +112,4 @@ struct Song { double GetDuration() const; }; -/** - * Returns true if both objects refer to the same physical song. - */ -gcc_pure -bool -SongEquals(const Song &a, const Song &b); - #endif |