diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2016-12-08 04:28:43 +0100 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2016-12-14 08:02:37 +0100 |
commit | b7386c4fa6c9d9f383639f5f418be618f7c38bba (patch) | |
tree | ed18aa7be436168a7d16c261997d6b07432a16a8 /src/song_list.h | |
parent | 612f8c3145ff6c71c43fd8103d45e2ab247257e0 (diff) |
song list: get rid of boost::zip_iterator and improve {Const,}SongIterator
Diffstat (limited to 'src/song_list.h')
-rw-r--r-- | src/song_list.h | 84 |
1 files changed, 72 insertions, 12 deletions
diff --git a/src/song_list.h b/src/song_list.h index 3b8a0b93..184c1dc2 100644 --- a/src/song_list.h +++ b/src/song_list.h @@ -22,25 +22,85 @@ #define NCMPCPP_SONG_LIST_H #include <boost/range/detail/any_iterator.hpp> -#include <boost/tuple/tuple.hpp> #include "menu.h" #include "song.h" +#include "utility/const.h" -template <typename ValueT> +struct SongProperties +{ + enum class State { Undefined, Const, Mutable }; + + SongProperties() + : m_state(State::Undefined) + { } + + SongProperties &assign(NC::List::Properties *properties_, MPD::Song *song_) + { + m_state = State::Mutable; + m_properties = properties_; + m_song = song_; + return *this; + } + + SongProperties &assign(const NC::List::Properties *properties_, const MPD::Song *song_) + { + m_state = State::Const; + m_const_properties = properties_; + m_const_song = song_; + return *this; + } + + const NC::List::Properties &properties() const + { + assert(m_state != State::Undefined); + return *m_const_properties; + } + const MPD::Song *song() const + { + assert(m_state != State::Undefined); + return m_const_song; + } + + NC::List::Properties &properties() + { + assert(m_state == State::Mutable); + return *m_properties; + } + MPD::Song *song() + { + assert(m_state == State::Mutable); + return m_song; + } + +private: + State m_state; + + union { + NC::List::Properties *m_properties; + const NC::List::Properties *m_const_properties; + }; + union { + MPD::Song *m_song; + const MPD::Song *m_const_song; + }; +}; + +template <Const const_> using SongIteratorT = boost::range_detail::any_iterator< - ValueT, + typename std::conditional< + const_ == Const::Yes, + const SongProperties, + SongProperties>::type, boost::random_access_traversal_tag, - const ValueT, // const needed, see https://svn.boost.org/trac/boost/ticket/10493 + typename std::conditional< + const_ == Const::Yes, + const SongProperties &, + SongProperties &>::type, std::ptrdiff_t ->; - -typedef SongIteratorT<boost::tuple<NC::List::Properties &, MPD::Song *>> SongIterator; -typedef SongIteratorT<boost::tuple<const NC::List::Properties &, const MPD::Song *>> ConstSongIterator; + >; -namespace Bit { -const size_t Properties = 0; -const size_t Song = 1; -} +typedef SongIteratorT<Const::No> SongIterator; +typedef SongIteratorT<Const::Yes> ConstSongIterator; struct SongList { |