Queue: rename and document the Find*() methods
authorMax Kellermann <max@musicpd.org>
Tue, 4 Sep 2018 08:01:30 +0000 (10:01 +0200)
committerMax Kellermann <max@musicpd.org>
Tue, 4 Sep 2018 08:01:30 +0000 (10:01 +0200)
Clarify their meaning.  This is obviously necessary because it has led
to bug #27.  To make it even worse, an attempt to fix that bug in
commit 08f864133ccf92c5839257531dab73827dd3d148 has produced another
bug.

src/FileListPage.cxx
src/Queue.cxx
src/Queue.hxx
src/QueuePage.cxx

index 8e71c24..034de68 100644 (file)
@@ -65,7 +65,7 @@ screen_browser_sync_highlights(FileList *fl, const MpdQueue *playlist)
                if (entity != nullptr && mpd_entity_get_type(entity) == MPD_ENTITY_TYPE_SONG) {
                        const auto *song = mpd_entity_get_song(entity);
 
-                       if (playlist->FindUri(*song) >= 0)
+                       if (playlist->FindByUri(*song) >= 0)
                                entry.flags |= HIGHLIGHT;
                        else
                                entry.flags &= ~HIGHLIGHT;
@@ -142,7 +142,7 @@ enqueue_and_play(struct mpdclient *c, FileListEntry *entry)
                id = -1;
        else
 #endif
-               id = c->playlist.FindUri(*song);
+               id = c->playlist.FindByUri(*song);
 
        if (id < 0) {
                char buf[BUFSIZE];
@@ -279,7 +279,7 @@ browser_select_entry(struct mpdclient *c, FileListEntry *entry,
 
                entry->flags &= ~HIGHLIGHT;
 
-               while ((idx = c->playlist.FindUri(*song)) >= 0)
+               while ((idx = c->playlist.FindByUri(*song)) >= 0)
                        mpdclient_cmd_delete(c, idx);
 #endif
        }
index f3bd612..46afa03 100644 (file)
@@ -63,7 +63,7 @@ MpdQueue::Move(unsigned dest, unsigned src)
 }
 
 int
-MpdQueue::Find(const struct mpd_song &song) const
+MpdQueue::FindByReference(const struct mpd_song &song) const
 {
        for (size_type i = 0; i < size(); ++i)
                if (&(*this)[i] == &song)
@@ -73,7 +73,7 @@ MpdQueue::Find(const struct mpd_song &song) const
 }
 
 int
-MpdQueue::FindId(unsigned id) const
+MpdQueue::FindById(unsigned id) const
 {
        for (size_type i = 0; i < size(); ++i) {
                const auto &song = (*this)[i];
@@ -85,7 +85,7 @@ MpdQueue::FindId(unsigned id) const
 }
 
 int
-MpdQueue::FindUri(const char *filename) const
+MpdQueue::FindByUri(const char *filename) const
 {
        for (size_type i = 0; i < size(); ++i) {
                const auto &song = (*this)[i];
index 1a0582f..a9a190e 100644 (file)
@@ -86,18 +86,42 @@ struct MpdQueue {
 
        void Move(unsigned dest, unsigned src);
 
+       /**
+        * Find a song by its reference.  This method compares
+        * #mpd_song references, so this method makes only sense for
+        * songs references which were obtained from this container.
+        *
+        * @return the song position
+        */
        gcc_pure
-       int Find(const struct mpd_song &song) const;
+       int FindByReference(const struct mpd_song &song) const;
 
+       /**
+        * Find a song by its id.
+        *
+        * @return the song position
+        */
        gcc_pure
-       int FindId(unsigned id) const;
+       int FindById(unsigned id) const;
 
+       /**
+        * Find a song by its URI.
+        *
+        * @return the song position
+        */
        gcc_pure
-       int FindUri(const char *uri) const;
-
+       int FindByUri(const char *uri) const;
+
+       /**
+        * Find a song by its URI (obtained from another #mpd_song
+        * instance).  Unlike FindByReference(), the given #mpd_song
+        * does not need to be obtained from this container.
+        *
+        * @return the song position
+        */
        gcc_pure
-       int FindUri(const struct mpd_song &song) const {
-               return FindUri(mpd_song_get_uri(&song));
+       int FindByUri(const struct mpd_song &song) const {
+               return FindByUri(mpd_song_get_uri(&song));
        }
 };
 
index 7a51fe4..2c65dac 100644 (file)
@@ -168,7 +168,7 @@ QueuePage::RestoreSelection()
                /* selection is still valid */
                return;
 
-       int pos = playlist->FindId(selected_song_id);
+       int pos = playlist->FindById(selected_song_id);
        if (pos >= 0)
                lw.SetCursor(pos);
 
@@ -507,7 +507,7 @@ QueuePage::OnCommand(struct mpdclient &c, command_t cmd)
                SetDirty();
                return false;
        case CMD_SELECT_PLAYING:
-               lw.SetCursor(c.playlist.Find(*c.song));
+               lw.SetCursor(c.playlist.FindByReference(*c.song));
                SaveSelection();
                SetDirty();
                return true;