ncmpc  0.30
filelist.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 FILELIST_H
21 #define FILELIST_H
22 
23 #include "Compiler.h"
24 
25 #include <vector>
26 #include <utility>
27 
28 struct mpd_connection;
29 struct mpd_song;
30 
31 struct FileListEntry {
32  unsigned flags = 0;
33  struct mpd_entity *entity;
34 
35  explicit FileListEntry(struct mpd_entity *_entity)
36  :entity(_entity) {}
38 
40  :flags(src.flags),
41  entity(std::exchange(src.entity, nullptr)) {}
42 
44  using std::swap;
45  flags = src.flags;
46  swap(entity, src.entity);
47  return *this;
48  }
49 
50  gcc_pure
51  bool operator<(const FileListEntry &other) const;
52 };
53 
54 class FileList {
55  using Vector = std::vector<FileListEntry>;
56 
57  /* the list */
58  Vector entries;
59 
60 public:
61  using size_type = Vector::size_type;
62 
63  FileList() = default;
64 
65  FileList(const FileList &) = delete;
66  FileList &operator=(const FileList &) = delete;
67 
68  size_type size() const {
69  return entries.size();
70  }
71 
72  bool empty() const {
73  return entries.empty();
74  }
75 
77  return entries[i];
78  }
79 
81  return entries[i];
82  }
83 
84  FileListEntry &emplace_back(struct mpd_entity *entity);
85 
86  void MoveFrom(FileList &&src);
87 
91  void Sort();
92 
96  void RemoveDuplicateSongs();
97 
98  gcc_pure
99  int FindSong(const struct mpd_song &song) const;
100 
101  gcc_pure
102  int FindDirectory(const char *name) const;
103 
109  void Receive(struct mpd_connection &connection);
110 };
111 
116 FileList *
117 filelist_new_recv(struct mpd_connection *connection);
118 
119 #endif
size_type size() const
Definition: filelist.hxx:68
void Receive(struct mpd_connection &connection)
FileListEntry(struct mpd_entity *_entity)
Definition: filelist.hxx:35
Definition: filelist.hxx:31
bool empty() const
Definition: filelist.hxx:72
FileList()=default
void RemoveDuplicateSongs()
unsigned flags
Definition: filelist.hxx:32
FileListEntry(FileListEntry &&src)
Definition: filelist.hxx:39
Vector::size_type size_type
Definition: filelist.hxx:61
gcc_pure bool operator<(const FileListEntry &other) const
void MoveFrom(FileList &&src)
gcc_pure int FindSong(const struct mpd_song &song) const
gcc_pure int FindDirectory(const char *name) const
const FileListEntry & operator[](size_type i) const
Definition: filelist.hxx:80
Definition: filelist.hxx:54
FileListEntry & operator[](size_type i)
Definition: filelist.hxx:76
void Sort()
FileList & operator=(const FileList &)=delete
FileList * filelist_new_recv(struct mpd_connection *connection)
#define gcc_pure
Definition: Compiler.h:101
FileListEntry & operator=(FileListEntry &&src)
Definition: filelist.hxx:43
FileListEntry & emplace_back(struct mpd_entity *entity)
struct mpd_entity * entity
Definition: filelist.hxx:33