Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions sequence_task_1/student/include/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,71 @@ class StaticPlaylist
{
public:
/** @todo Member traits */

using reference = Song_t&;
using const_reference = typename Container::const_reference;
using const_iterator = typename Container::const_iterator;
using difference_type = typename Container::difference_type;
using iterator = typename Container::iterator;
using size_type = typename std::size_t;
using value_type = typename Container::value_type;

/** @todo Iterators */
const_iterator begin() const {
return m_tracklist.cbegin();
}
const_iterator end() const {
return m_tracklist.cend();
}

StaticPlaylist() = default;

/** @todo Constructor from any reversible sequence container */
template<class T>
StaticPlaylist(const T& container) :
m_tracklist(container.rbegin(), container.rend()) {}

/** @todo Assignment from any reversible sequence container */
template<class T>
StaticPlaylist<Container, Song_t>& operator=(const T& container) {
m_tracklist.assign(container.rbegin(), container.rend());
return *this;
}

/** @todo Add track from initializer */
template<class... Args>
const Song_t& play(Args&&... songData);
const Song_t& play(Args&&... songData) {
m_tracklist.emplace_back(std::forward<Args>(songData)...);
return current();
}

/** @todo Add track */
const Song_t& play(const Song_t& song);
const Song_t& play(const Song_t& song) {
m_tracklist.push_back(song);
return current();
}

/** @todo Get first track in playlist stack */
const Song_t& current() const;
const Song_t& current() const {
return m_tracklist.back();
}

/** @todo Skip to the next track in playlist, remove current */
void switchNext();
void switchNext() {
if (!hasTracks())
throw std::out_of_range("Track list is empty");

m_tracklist.pop_back();
}

/** @todo Amount of tracks in playlist */
size_type count() const;
size_type count() const {
return m_tracklist.size();
}

/** @todo Checks if playlist has any playable tracks */
bool hasTracks() const;
bool hasTracks() const {
return !m_tracklist.empty();
}

private:
Container m_tracklist;
Expand Down