actions: use unique_ptr for storing actions
[ncmpcpp.git] / src / song_list.cpp
blob5de4dc10d900e9601bf96826a820b7ca9cbf2ab8
1 /***************************************************************************
2 * Copyright (C) 2008-2016 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
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 *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #include "helpers/song_iterator_maker.h"
22 #include "song_info.h"
23 #include "utility/functional.h"
25 namespace {
27 template <bool Const>
28 struct SongExtractor
30 typedef SongExtractor type;
32 typedef typename NC::Menu<MPD::Song>::Item MenuItem;
33 typedef typename std::conditional<Const, const MenuItem, MenuItem>::type Item;
34 typedef typename std::conditional<Const, const MPD::Song, MPD::Song>::type Song;
36 Song *operator()(Item &item) const
38 return &item.value();
44 SongIterator SongMenu::currentS()
46 return makeSongIterator_<MPD::Song>(current(), SongExtractor<false>());
49 ConstSongIterator SongMenu::currentS() const
51 return makeConstSongIterator_<MPD::Song>(current(), SongExtractor<true>());
54 SongIterator SongMenu::beginS()
56 return makeSongIterator_<MPD::Song>(begin(), SongExtractor<false>());
59 ConstSongIterator SongMenu::beginS() const
61 return makeConstSongIterator_<MPD::Song>(begin(), SongExtractor<true>());
64 SongIterator SongMenu::endS()
66 return makeSongIterator_<MPD::Song>(end(), SongExtractor<false>());
69 ConstSongIterator SongMenu::endS() const
71 return makeConstSongIterator_<MPD::Song>(end(), SongExtractor<true>());
74 std::vector<MPD::Song> SongMenu::getSelectedSongs()
76 std::vector<MPD::Song> result;
77 for (auto it = begin(); it != end(); ++it)
78 if (it->isSelected())
79 result.push_back(it->value());
80 if (result.empty() && !empty())
81 result.push_back(current()->value());
82 return result;