diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2014-11-01 16:43:03 +0100 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2014-11-01 16:43:03 +0100 |
commit | 485e6ee4a30ee00c238611b6395371607f19eed1 (patch) | |
tree | 3d049f3b50eef08e43b573aee174e7e03d2df1d3 /src/mpdpp.h | |
parent | fb9c0ffdf57c8896dbdec265475b3b8ddd9c0cdd (diff) |
mpd: add SongIterator
Diffstat (limited to 'src/mpdpp.h')
-rw-r--r-- | src/mpdpp.h | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/src/mpdpp.h b/src/mpdpp.h index d067a191..edee3f63 100644 --- a/src/mpdpp.h +++ b/src/mpdpp.h @@ -21,6 +21,7 @@ #ifndef NCMPCPP_MPDPP_H #define NCMPCPP_MPDPP_H +#include <boost/noncopyable.hpp> #include <cassert> #include <exception> #include <set> @@ -29,8 +30,8 @@ #include <mpd/client.h> #include "song.h" -namespace MPD {// - +namespace MPD { + enum ItemType { itDirectory, itSong, itPlaylist }; enum PlayerState { psUnknown, psStop, psPlay, psPause }; enum ReplayGainMode { rgmOff, rgmTrack, rgmAlbum }; @@ -144,7 +145,35 @@ typedef std::vector<Item> ItemList; typedef std::vector<std::string> StringList; typedef std::vector<Output> OutputList; -class Connection +struct SongIterator : std::iterator<std::forward_iterator_tag, Song> +{ + friend class Connection; + + SongIterator() : m_connection(nullptr) { } + ~SongIterator(); + + Song &operator*(); + Song *operator->(); + + SongIterator &operator++(); + SongIterator operator++(int); + + bool operator==(const SongIterator &rhs) { + return m_connection == rhs.m_connection + && m_song == rhs.m_song; + } + bool operator!=(const SongIterator &rhs) { + return !(*this == rhs); + } + +private: + SongIterator(std::shared_ptr<mpd_connection> conn) : m_connection(std::move(conn)) { } + + std::shared_ptr<mpd_connection> m_connection; + Song m_song; +}; + +class Connection : private boost::noncopyable { typedef void (*ErrorHandler) (Connection *, int, const char *, void *); @@ -155,7 +184,6 @@ class Connection public: Connection(); - ~Connection(); void Connect(); bool Connected() const; @@ -265,7 +293,7 @@ private: void prechecksNoCommandsList(); void checkErrors() const; - mpd_connection *m_connection; + std::shared_ptr<mpd_connection> m_connection; bool m_command_list_active; int m_fd; |