mpdpp: make all consumers take values, not rvalue references
This commit is contained in:
@@ -1263,7 +1263,7 @@ void EditLibraryTag::run()
|
||||
assert(set);
|
||||
bool success = true;
|
||||
std::string dir_to_update;
|
||||
Mpd.CommitSearchSongs([set, &dir_to_update, &new_tag, &success](MPD::Song &&s) {
|
||||
Mpd.CommitSearchSongs([set, &dir_to_update, &new_tag, &success](MPD::Song s) {
|
||||
if (!success)
|
||||
return;
|
||||
MPD::MutableSong ms = s;
|
||||
|
||||
@@ -337,18 +337,14 @@ MPD::SongList Browser::getSelectedSongs()
|
||||
else
|
||||
# endif // !WIN32
|
||||
{
|
||||
Mpd.GetDirectoryRecursive(item.name, [&result](MPD::Song &&s) {
|
||||
result.push_back(s);
|
||||
});
|
||||
Mpd.GetDirectoryRecursive(item.name, vectorMoveInserter(result));
|
||||
}
|
||||
}
|
||||
else if (item.type == itSong)
|
||||
result.push_back(*item.song);
|
||||
else if (item.type == itPlaylist)
|
||||
{
|
||||
Mpd.GetPlaylistContent(item.name, [&result](MPD::Song &&s) {
|
||||
result.push_back(s);
|
||||
});
|
||||
Mpd.GetPlaylistContent(item.name, vectorMoveInserter(result));
|
||||
}
|
||||
};
|
||||
for (auto it = w.begin(); it != w.end(); ++it)
|
||||
@@ -415,9 +411,7 @@ void Browser::GetDirectory(std::string dir, std::string subdir)
|
||||
if (isLocal())
|
||||
GetLocalDirectory(list, itsBrowsedDir, false);
|
||||
else
|
||||
Mpd.GetDirectory(dir, [&list](MPD::Item &&item) {
|
||||
list.push_back(item);
|
||||
});
|
||||
Mpd.GetDirectory(dir, vectorMoveInserter(list));
|
||||
# else
|
||||
list = Mpd.GetDirectory(dir);
|
||||
# endif // !WIN32
|
||||
|
||||
@@ -334,6 +334,12 @@ void clearPlaylist(NC::Menu<MPD::Song> &m, F delete_fun, G clear_fun)
|
||||
clear_fun(Mpd);
|
||||
}
|
||||
|
||||
template <typename ItemT>
|
||||
std::function<void (ItemT)> vectorMoveInserter(std::vector<ItemT> &v)
|
||||
{
|
||||
return [&](ItemT item) { v.push_back(std::move(item)); };
|
||||
}
|
||||
|
||||
template <typename Iterator> std::string getSharedDirectory(Iterator first, Iterator last)
|
||||
{
|
||||
assert(first != last);
|
||||
|
||||
@@ -256,7 +256,7 @@ void MediaLibrary::update()
|
||||
Albums.clearSearchResults();
|
||||
m_albums_update_request = false;
|
||||
std::map<std::tuple<std::string, std::string, std::string>, time_t> albums;
|
||||
Mpd.GetDirectoryRecursive("/", [&albums](MPD::Song &&s) {
|
||||
Mpd.GetDirectoryRecursive("/", [&albums](MPD::Song s) {
|
||||
unsigned idx = 0;
|
||||
std::string tag = s.get(Config.media_lib_primary_tag, idx);
|
||||
do
|
||||
@@ -298,7 +298,7 @@ void MediaLibrary::update()
|
||||
Tags.clearSearchResults();
|
||||
m_tags_update_request = false;
|
||||
std::map<std::string, time_t> tags;
|
||||
Mpd.GetDirectoryRecursive("/", [&tags](MPD::Song &&s) {
|
||||
Mpd.GetDirectoryRecursive("/", [&tags](MPD::Song s) {
|
||||
unsigned idx = 0;
|
||||
std::string tag = s.get(Config.media_lib_primary_tag, idx);
|
||||
do
|
||||
@@ -336,7 +336,7 @@ void MediaLibrary::update()
|
||||
Mpd.StartSearch(true);
|
||||
Mpd.AddSearch(Config.media_lib_primary_tag, primary_tag);
|
||||
std::map<std::tuple<std::string, std::string>, time_t> albums;
|
||||
Mpd.CommitSearchSongs([&albums](MPD::Song &&s) {
|
||||
Mpd.CommitSearchSongs([&albums](MPD::Song s) {
|
||||
auto key = std::make_tuple(s.getAlbum(), s.getDate());
|
||||
auto it = albums.find(key);
|
||||
if (it == albums.end())
|
||||
@@ -388,7 +388,7 @@ void MediaLibrary::update()
|
||||
}
|
||||
withUnfilteredMenuReapplyFilter(Songs, [this, &album]() {
|
||||
size_t idx = 0;
|
||||
Mpd.CommitSearchSongs([this, &idx](MPD::Song &&s) {
|
||||
Mpd.CommitSearchSongs([this, &idx](MPD::Song s) {
|
||||
bool is_playlist = myPlaylist->checkForSong(s);
|
||||
if (idx < Songs.size())
|
||||
{
|
||||
@@ -714,9 +714,7 @@ MPD::SongList MediaLibrary::getSelectedSongs()
|
||||
auto tag_handler = [&result](const std::string &tag) {
|
||||
Mpd.StartSearch(true);
|
||||
Mpd.AddSearch(Config.media_lib_primary_tag, tag);
|
||||
Mpd.CommitSearchSongs([&result](MPD::Song &&s) {
|
||||
result.push_back(s);
|
||||
});
|
||||
Mpd.CommitSearchSongs(vectorMoveInserter(result));
|
||||
};
|
||||
for (auto it = Tags.begin(); it != Tags.end(); ++it)
|
||||
if (it->isSelected())
|
||||
@@ -741,9 +739,7 @@ MPD::SongList MediaLibrary::getSelectedSongs()
|
||||
Mpd.AddSearch(MPD_TAG_ALBUM, sc.entry().album());
|
||||
Mpd.AddSearch(MPD_TAG_DATE, sc.entry().date());
|
||||
size_t begin = result.size();
|
||||
Mpd.CommitSearchSongs([&result](MPD::Song &&s) {
|
||||
result.push_back(s);
|
||||
});
|
||||
Mpd.CommitSearchSongs(vectorMoveInserter(result));
|
||||
std::sort(result.begin()+begin, result.end(), SortSongs(false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -640,7 +640,7 @@ void Connection::Add(const std::string &path)
|
||||
bool Connection::AddRandomTag(mpd_tag_type tag, size_t number)
|
||||
{
|
||||
StringList tags;
|
||||
GetList(tag, [&tags](std::string &&tag_name) {
|
||||
GetList(tag, [&tags](std::string tag_name) {
|
||||
tags.push_back(tag_name);
|
||||
});
|
||||
if (number > tags.size())
|
||||
@@ -658,7 +658,7 @@ bool Connection::AddRandomTag(mpd_tag_type tag, size_t number)
|
||||
StartSearch(1);
|
||||
AddSearch(tag, *it++);
|
||||
SongList songs;
|
||||
CommitSearchSongs([&songs](MPD::Song &&s) {
|
||||
CommitSearchSongs([&songs](MPD::Song s) {
|
||||
songs.push_back(s);
|
||||
});
|
||||
StartCommandsList();
|
||||
|
||||
@@ -148,10 +148,10 @@ class Connection
|
||||
{
|
||||
typedef void (*ErrorHandler) (Connection *, int, const char *, void *);
|
||||
|
||||
typedef std::function<void(Item &&)> ItemConsumer;
|
||||
typedef std::function<void(Output &&)> OutputConsumer;
|
||||
typedef std::function<void(Song &&)> SongConsumer;
|
||||
typedef std::function<void(std::string &&)> StringConsumer;
|
||||
typedef std::function<void(Item)> ItemConsumer;
|
||||
typedef std::function<void(Output)> OutputConsumer;
|
||||
typedef std::function<void(Song)> SongConsumer;
|
||||
typedef std::function<void(std::string)> StringConsumer;
|
||||
|
||||
public:
|
||||
Connection();
|
||||
|
||||
@@ -200,7 +200,7 @@ void MutableSong::clearModifications()
|
||||
m_tags.clear();
|
||||
}
|
||||
|
||||
void MutableSong::replaceTag(mpd_tag_type tag_type, std::string &&orig_value, const std::string &value, unsigned idx)
|
||||
void MutableSong::replaceTag(mpd_tag_type tag_type, std::string orig_value, const std::string &value, unsigned idx)
|
||||
{
|
||||
Tag tag(tag_type, idx);
|
||||
if (value == orig_value)
|
||||
|
||||
@@ -91,7 +91,7 @@ private:
|
||||
unsigned m_idx;
|
||||
};
|
||||
|
||||
void replaceTag(mpd_tag_type tag_type, std::string &&orig_value,
|
||||
void replaceTag(mpd_tag_type tag_type, std::string orig_value,
|
||||
const std::string &value, unsigned idx);
|
||||
|
||||
template <typename F>
|
||||
|
||||
@@ -99,7 +99,7 @@ void Outputs::mouseButtonPressed(MEVENT me)
|
||||
void Outputs::FetchList()
|
||||
{
|
||||
w.clear();
|
||||
Mpd.GetOutputs([this](MPD::Output &&output) {
|
||||
Mpd.GetOutputs([this](MPD::Output output) {
|
||||
w.addItem(output, output.isEnabled());
|
||||
});
|
||||
if (myScreen == this)
|
||||
|
||||
@@ -133,7 +133,7 @@ void PlaylistEditor::update()
|
||||
Playlists.clearSearchResults();
|
||||
withUnfilteredMenuReapplyFilter(Playlists, [this]() {
|
||||
size_t idx = 0;
|
||||
Mpd.GetPlaylists([this, &idx](std::string &&playlist) {
|
||||
Mpd.GetPlaylists([this, &idx](std::string playlist) {
|
||||
if (idx < Playlists.size())
|
||||
Playlists[idx].value() = playlist;
|
||||
else
|
||||
@@ -154,7 +154,7 @@ void PlaylistEditor::update()
|
||||
Content.clearSearchResults();
|
||||
withUnfilteredMenuReapplyFilter(Content, [this]() {
|
||||
size_t idx = 0;
|
||||
Mpd.GetPlaylistContent(Playlists.current().value(), [this, &idx](MPD::Song &&s) {
|
||||
Mpd.GetPlaylistContent(Playlists.current().value(), [this, &idx](MPD::Song s) {
|
||||
if (idx < Content.size())
|
||||
{
|
||||
Content[idx].value() = s;
|
||||
@@ -459,9 +459,7 @@ MPD::SongList PlaylistEditor::getSelectedSongs()
|
||||
if (it->isSelected())
|
||||
{
|
||||
any_selected = true;
|
||||
Mpd.GetPlaylistContent(it->value(), [&result](MPD::Song &&s) {
|
||||
result.push_back(s);
|
||||
});
|
||||
Mpd.GetPlaylistContent(it->value(), vectorMoveInserter(result));
|
||||
}
|
||||
}
|
||||
// we don't check for empty result here as it's possible that
|
||||
|
||||
@@ -434,7 +434,7 @@ void SearchEngine::Search()
|
||||
Mpd.AddSearch(MPD_TAG_DATE, itsConstraints[9]);
|
||||
if (!itsConstraints[10].empty())
|
||||
Mpd.AddSearch(MPD_TAG_COMMENT, itsConstraints[10]);
|
||||
Mpd.CommitSearchSongs([this](MPD::Song &&s) {
|
||||
Mpd.CommitSearchSongs([this](MPD::Song s) {
|
||||
w.addItem(s);
|
||||
});
|
||||
return;
|
||||
@@ -442,9 +442,7 @@ void SearchEngine::Search()
|
||||
|
||||
MPD::SongList list;
|
||||
if (Config.search_in_db)
|
||||
Mpd.GetDirectoryRecursive("/", [&list](MPD::Song &&s) {
|
||||
list.push_back(s);
|
||||
});
|
||||
Mpd.GetDirectoryRecursive("/", vectorMoveInserter(list));
|
||||
else
|
||||
list.insert(list.end(), myPlaylist->main().beginV(), myPlaylist->main().endV());
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ void SelectedItemsAdder::populatePlaylistSelector(BaseScreen *old_screen)
|
||||
if (old_screen != myBrowser || !myBrowser->isLocal())
|
||||
{
|
||||
size_t begin = m_playlist_selector.size();
|
||||
Mpd.GetPlaylists([this](std::string &&playlist) {
|
||||
Mpd.GetPlaylists([this](std::string playlist) {
|
||||
m_playlist_selector.addItem(Entry(playlist,
|
||||
std::bind(&Self::addToExistingPlaylist, this, playlist)
|
||||
));
|
||||
|
||||
@@ -48,12 +48,8 @@ void ServerInfo::switchTo()
|
||||
itsURLHandlers.clear();
|
||||
itsTagTypes.clear();
|
||||
|
||||
Mpd.GetURLHandlers([this](std::string &&handler) {
|
||||
itsURLHandlers.push_back(handler);
|
||||
});
|
||||
Mpd.GetTagTypes([this](std::string &&tag_type) {
|
||||
itsTagTypes.push_back(tag_type);
|
||||
});
|
||||
Mpd.GetURLHandlers(vectorMoveInserter(itsURLHandlers));
|
||||
Mpd.GetTagTypes(vectorMoveInserter(itsTagTypes));
|
||||
}
|
||||
else
|
||||
switchToPreviousScreen();
|
||||
|
||||
@@ -272,7 +272,7 @@ void Status::Changes::playlist()
|
||||
myPlaylist->main().resizeList(playlist_length);
|
||||
}
|
||||
|
||||
Mpd.GetPlaylistChanges(myPlaylist->oldVersion(), [](MPD::Song &&s) {
|
||||
Mpd.GetPlaylistChanges(myPlaylist->oldVersion(), [](MPD::Song s) {
|
||||
size_t pos = s.getPosition();
|
||||
if (pos < myPlaylist->main().size())
|
||||
{
|
||||
|
||||
@@ -238,7 +238,7 @@ void TagEditor::update()
|
||||
Dirs->addItem(std::make_pair("..", getParentDirectory(itsBrowsedDir)));
|
||||
else
|
||||
Dirs->addItem(std::make_pair(".", "/"));
|
||||
Mpd.GetDirectories(itsBrowsedDir, [this](std::string &&directory) {
|
||||
Mpd.GetDirectories(itsBrowsedDir, [this](std::string directory) {
|
||||
Dirs->addItem(std::make_pair(getBasename(directory), directory));
|
||||
if (directory == itsHighlightedDir)
|
||||
Dirs->highlight(Dirs->size()-1);
|
||||
@@ -251,7 +251,7 @@ void TagEditor::update()
|
||||
if (Tags->reallyEmpty())
|
||||
{
|
||||
Tags->reset();
|
||||
Mpd.GetSongs(Dirs->current().value().second, [this](MPD::Song &&s) {
|
||||
Mpd.GetSongs(Dirs->current().value().second, [this](MPD::Song s) {
|
||||
Tags->addItem(s);
|
||||
});
|
||||
std::sort(Tags->beginV(), Tags->endV(),
|
||||
@@ -277,7 +277,7 @@ void TagEditor::enterPressed()
|
||||
if (w == Dirs)
|
||||
{
|
||||
bool has_subdirs = false;
|
||||
Mpd.GetDirectories(Dirs->current().value().second, [&has_subdirs](std::string &&) {
|
||||
Mpd.GetDirectories(Dirs->current().value().second, [&has_subdirs](std::string) {
|
||||
has_subdirs = true;
|
||||
});
|
||||
if (has_subdirs)
|
||||
|
||||
@@ -216,7 +216,7 @@ void Visualizer::FindOutputID()
|
||||
if (!Config.visualizer_output_name.empty())
|
||||
{
|
||||
size_t idx = 0;
|
||||
Mpd.GetOutputs([this, &idx](MPD::Output &&output) {
|
||||
Mpd.GetOutputs([this, &idx](MPD::Output output) {
|
||||
if (output.name() == Config.visualizer_output_name)
|
||||
m_output_id = idx;
|
||||
++idx;
|
||||
|
||||
Reference in New Issue
Block a user