1 /***************************************************************************
2 * Copyright (C) 2008-2016 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
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. *
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. *
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"
27 #include "utility/const.h"
31 enum class State
{ Undefined
, Const
, Mutable
};
34 : m_state(State::Undefined
)
37 SongProperties
&assign(NC::List::Properties
*properties_
, MPD::Song
*song_
)
39 m_state
= State::Mutable
;
40 m_properties
= properties_
;
45 SongProperties
&assign(const NC::List::Properties
*properties_
, const MPD::Song
*song_
)
47 m_state
= State::Const
;
48 m_const_properties
= properties_
;
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
);
64 NC::List::Properties
&properties()
66 assert(m_state
== State::Mutable
);
71 assert(m_state
== State::Mutable
);
79 NC::List::Properties
*m_properties
;
80 const NC::List::Properties
*m_const_properties
;
84 const MPD::Song
*m_const_song
;
88 template <Const const_
>
89 using SongIteratorT
= boost::range_detail::any_iterator
<
90 typename
std::conditional
<
93 SongProperties
>::type
,
94 boost::random_access_traversal_tag
,
95 typename
std::conditional
<
97 const SongProperties
&,
98 SongProperties
&>::type
,
102 typedef SongIteratorT
<Const::No
> SongIterator
;
103 typedef SongIteratorT
<Const::Yes
> ConstSongIterator
;
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
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