diff --git a/sequence_task_1/student/include/impl.h b/sequence_task_1/student/include/impl.h index e03f3e9..d81b998 100644 --- a/sequence_task_1/student/include/impl.h +++ b/sequence_task_1/student/include/impl.h @@ -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 + StaticPlaylist(const T& container) : + m_tracklist(container.rbegin(), container.rend()) {} /** @todo Assignment from any reversible sequence container */ + template + StaticPlaylist& operator=(const T& container) { + m_tracklist.assign(container.rbegin(), container.rend()); + return *this; + } /** @todo Add track from initializer */ template - const Song_t& play(Args&&... songData); + const Song_t& play(Args&&... songData) { + m_tracklist.emplace_back(std::forward(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;