Move ncurses related files to curses directory
[ncmpcpp.git] / src / song_list.h
blob6e4060705aac7c74ed8ee532f855f93e238eb0e4
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 #ifndef NCMPCPP_SONG_LIST_H
22 #define NCMPCPP_SONG_LIST_H
24 #include <boost/range/detail/any_iterator.hpp>
25 #include "curses/menu.h"
26 #include "song.h"
27 #include "utility/const.h"
29 struct SongProperties
31 enum class State { Undefined, Const, Mutable };
33 SongProperties()
34 : m_state(State::Undefined)
35 { }
37 SongProperties &assign(NC::List::Properties *properties_, MPD::Song *song_)
39 m_state = State::Mutable;
40 m_properties = properties_;
41 m_song = song_;
42 return *this;
45 SongProperties &assign(const NC::List::Properties *properties_, const MPD::Song *song_)
47 m_state = State::Const;
48 m_const_properties = properties_;
49 m_const_song = song_;
50 return *this;
53 const NC::List::Properties &properties() const
55 assert(m_state != State::Undefined);
56 return *m_const_properties;
58 const MPD::Song *song() const
60 assert(m_state != State::Undefined);
61 return m_const_song;
64 NC::List::Properties &properties()
66 assert(m_state == State::Mutable);
67 return *m_properties;
69 MPD::Song *song()
71 assert(m_state == State::Mutable);
72 return m_song;
75 private:
76 State m_state;
78 union {
79 NC::List::Properties *m_properties;
80 const NC::List::Properties *m_const_properties;
82 union {
83 MPD::Song *m_song;
84 const MPD::Song *m_const_song;
88 template <Const const_>
89 using SongIteratorT = boost::range_detail::any_iterator<
90 typename std::conditional<
91 const_ == Const::Yes,
92 const SongProperties,
93 SongProperties>::type,
94 boost::random_access_traversal_tag,
95 typename std::conditional<
96 const_ == Const::Yes,
97 const SongProperties &,
98 SongProperties &>::type,
99 std::ptrdiff_t
102 typedef SongIteratorT<Const::No> SongIterator;
103 typedef SongIteratorT<Const::Yes> ConstSongIterator;
105 struct SongList
107 virtual SongIterator currentS() = 0;
108 virtual ConstSongIterator currentS() const = 0;
109 virtual SongIterator beginS() = 0;
110 virtual ConstSongIterator beginS() const = 0;
111 virtual SongIterator endS() = 0;
112 virtual ConstSongIterator endS() const = 0;
114 virtual std::vector<MPD::Song> getSelectedSongs() = 0;
117 inline SongIterator begin(SongList &list) { return list.beginS(); }
118 inline ConstSongIterator begin(const SongList &list) { return list.beginS(); }
119 inline SongIterator end(SongList &list) { return list.endS(); }
120 inline ConstSongIterator end(const SongList &list) { return list.endS(); }
122 struct SongMenu: NC::Menu<MPD::Song>, SongList
124 SongMenu() { }
125 SongMenu(NC::Menu<MPD::Song> &&base)
126 : NC::Menu<MPD::Song>(std::move(base)) { }
128 virtual SongIterator currentS() override;
129 virtual ConstSongIterator currentS() const override;
130 virtual SongIterator beginS() override;
131 virtual ConstSongIterator beginS() const override;
132 virtual SongIterator endS() override;
133 virtual ConstSongIterator endS() const override;
135 virtual std::vector<MPD::Song> getSelectedSongs() override;
138 #endif // NCMPCPP_SONG_LIST_H