ncmpc  0.30
Queue.hxx
Go to the documentation of this file.
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2018 The Music Player Daemon Project
3  * Project homepage: http://musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef QUEUE_HXX
21 #define QUEUE_HXX
22 
23 #include "Compiler.h"
24 
25 #include <mpd/client.h>
26 
27 #include <vector>
28 #include <memory>
29 
30 #include <assert.h>
31 
32 struct SongDeleter {
33  void operator()(struct mpd_song *song) const {
34  mpd_song_free(song);
35  }
36 };
37 
38 struct MpdQueue {
39  /* queue version number (obtained from mpd_status) */
40  unsigned version = 0;
41 
42  using Vector = std::vector<std::unique_ptr<struct mpd_song, SongDeleter>>;
43 
44  /* the list */
46 
47  using size_type = Vector::size_type;
48 
49  size_type size() const {
50  return items.size();
51  }
52 
53  bool empty() const {
54  return items.empty();
55  }
56 
58  void clear();
59 
60  const struct mpd_song &operator[](size_type i) const {
61  assert(i < size());
62 
63  return *items[i];
64  }
65 
66  struct mpd_song &operator[](size_type i) {
67  assert(i < size());
68 
69  return *items[i];
70  }
71 
72  gcc_pure
73  const struct mpd_song *GetChecked(int i) const;
74 
75  void push_back(const struct mpd_song &song) {
76  items.emplace_back(mpd_song_dup(&song));
77  }
78 
79  void Replace(size_type i, const struct mpd_song &song) {
80  items[i].reset(mpd_song_dup(&song));
81  }
82 
84  items.erase(std::next(items.begin(), i));
85  }
86 
87  void Move(unsigned dest, unsigned src);
88 
89  gcc_pure
90  int Find(const struct mpd_song &song) const;
91 
92  gcc_pure
93  int FindId(unsigned id) const;
94 
95  gcc_pure
96  int FindUri(const char *uri) const;
97 
98  gcc_pure
99  int FindUri(const struct mpd_song &song) const {
100  return FindUri(mpd_song_get_uri(&song));
101  }
102 };
103 
104 #endif
std::vector< std::unique_ptr< struct mpd_song, SongDeleter > > Vector
Definition: Queue.hxx:42
size_type size() const
Definition: Queue.hxx:49
Vector items
Definition: Queue.hxx:45
unsigned version
Definition: Queue.hxx:40
void Replace(size_type i, const struct mpd_song &song)
Definition: Queue.hxx:79
struct mpd_song & operator[](size_type i)
Definition: Queue.hxx:66
Definition: Queue.hxx:32
void operator()(struct mpd_song *song) const
Definition: Queue.hxx:33
gcc_pure int FindUri(const struct mpd_song &song) const
Definition: Queue.hxx:99
gcc_pure const struct mpd_song * GetChecked(int i) const
gcc_pure int Find(const struct mpd_song &song) const
const struct mpd_song & operator[](size_type i) const
Definition: Queue.hxx:60
void Move(unsigned dest, unsigned src)
Vector::size_type size_type
Definition: Queue.hxx:47
gcc_pure int FindId(unsigned id) const
gcc_pure int FindUri(const char *uri) const
#define gcc_pure
Definition: Compiler.h:101
void clear()
void RemoveIndex(size_type i)
Definition: Queue.hxx:83
bool empty() const
Definition: Queue.hxx:53
void push_back(const struct mpd_song &song)
Definition: Queue.hxx:75
Definition: Queue.hxx:38