From 0663e4642584e41aa6ad4dfb6a40c48ce16f0476 Mon Sep 17 00:00:00 2001 From: fgerlits Date: Thu, 14 Oct 2004 10:25:16 +0000 Subject: [PATCH] added list of playlist elements to the Playlist class --- livesupport/modules/core/etc/playlist.xml | 20 ++++++- .../core/include/LiveSupport/Core/Playlist.h | 60 +++++++++++++++++-- livesupport/modules/core/src/Playlist.cxx | 47 ++++++++++++++- .../modules/core/src/PlaylistElement.cxx | 10 ++-- livesupport/modules/core/src/PlaylistTest.cxx | 5 +- 5 files changed, 124 insertions(+), 18 deletions(-) diff --git a/livesupport/modules/core/etc/playlist.xml b/livesupport/modules/core/etc/playlist.xml index 5dc2234ee..1756dfb49 100644 --- a/livesupport/modules/core/etc/playlist.xml +++ b/livesupport/modules/core/etc/playlist.xml @@ -1,8 +1,24 @@ + + + + + + + + + ]> - + + + + + + + + + diff --git a/livesupport/modules/core/include/LiveSupport/Core/Playlist.h b/livesupport/modules/core/include/LiveSupport/Core/Playlist.h index a180eabe5..a9a29944b 100644 --- a/livesupport/modules/core/include/LiveSupport/Core/Playlist.h +++ b/livesupport/modules/core/include/LiveSupport/Core/Playlist.h @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Playlist.h,v $ ------------------------------------------------------------------------------*/ @@ -40,6 +40,7 @@ #include "configure.h" #endif +#include #include #include #include @@ -47,6 +48,7 @@ #include "LiveSupport/Core/Ptr.h" #include "LiveSupport/Core/UniqueId.h" #include "LiveSupport/Core/Configurable.h" +#include "LiveSupport/Core/PlaylistElement.h" namespace LiveSupport { @@ -69,7 +71,7 @@ using namespace boost::posix_time; * the playlist. * * @author $Author: fgerlits $ - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ */ class Playlist : public Configurable { @@ -99,6 +101,18 @@ class Playlist : public Configurable */ bool isLockedForEditing; + /** + * A map type for storing the playlist elements associated with + * this playlist, indexed by their relative offsets. + */ + typedef std::map::Ref> + PlaylistElementListType; + + /** + * The list of playlist elements for this playlist. + */ + Ptr::Ref elementList; + public: /** @@ -154,13 +168,10 @@ class Playlist : public Configurable * @param element the XML element to configure the object from. * @exception std::invalid_argument if the supplied XML element * contains bad configuraiton information - * @exception std::logic_error if the object has already - * been configured, and can not be reconfigured. */ virtual void configure(const xmlpp::Element & element) - throw (std::invalid_argument, - std::logic_error); + throw (std::invalid_argument); /** * Return the id of the playlist. @@ -204,6 +215,43 @@ class Playlist : public Configurable setLockedForPlaying(bool lockStatus) throw (); + /** + * Add a new playlist element to the playlist. + * + * @param playlistElement the new playlist element to be added + * @exception std::invalid_argument if the playlist already contains + * a playlist element with the same relative offset as the + * new playlist element + */ + void + addPlaylistElement(Ptr::Ref playlistElement) + throw (std::invalid_argument); + + /** + * The iterator type for this class. + * + */ + typedef PlaylistElementListType::const_iterator const_iterator; + + /** + * Get an iterator pointing to the first playlist element. + * + */ + const_iterator + begin() const throw () + { + return elementList->begin(); + } + + /** + * Get an iterator pointing to one after the last playlist element. + * + */ + const_iterator + end() const throw () + { + return elementList->end(); + } }; diff --git a/livesupport/modules/core/src/Playlist.cxx b/livesupport/modules/core/src/Playlist.cxx index 428c4a255..831e59909 100644 --- a/livesupport/modules/core/src/Playlist.cxx +++ b/livesupport/modules/core/src/Playlist.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/Playlist.cxx,v $ ------------------------------------------------------------------------------*/ @@ -61,6 +61,11 @@ static const std::string idAttrName = "id"; */ static const std::string playlengthAttrName = "playlength"; +/** + * The name of playlist element child nodes. + */ +static const std::string elementListAttrName = "playlistElement"; + /* =============================================== local function prototypes */ @@ -72,8 +77,7 @@ static const std::string playlengthAttrName = "playlength"; *----------------------------------------------------------------------------*/ void Playlist :: configure(const xmlpp::Element & element) - throw (std::logic_error, - std::invalid_argument) + throw (std::invalid_argument) { if (element.get_name() != configElementNameStr) { std::string eMsg = "Bad configuration element "; @@ -101,6 +105,43 @@ Playlist :: configure(const xmlpp::Element & element) } playlength.reset(new time_duration( duration_from_string(attribute->get_value()))); + + // no exception thrown here: it's OK to have an empty playlist element list + elementList.reset(new PlaylistElementListType); + xmlpp::Node::NodeList childNodes + = element.get_children(elementListAttrName); + xmlpp::Node::NodeList::iterator it = childNodes.begin(); + + while (it != childNodes.end()) { + Ptr::Ref newPlaylistElement(new PlaylistElement); + const xmlpp::Element * childElement + = dynamic_cast (*it); + newPlaylistElement->configure(*childElement); + addPlaylistElement(newPlaylistElement); + ++it; + } + + isLockedForPlaying = false; + isLockedForEditing = false; +} + + +/*------------------------------------------------------------------------------ + * Add a new playlist element to the playlist. + *----------------------------------------------------------------------------*/ +void +Playlist::addPlaylistElement(Ptr::Ref playlistElement) + throw (std::invalid_argument) +{ + Ptr::Ref relativeOffset + = playlistElement->getRelativeOffset(); + + if (elementList->find(*relativeOffset) != elementList->end()) { + std::string eMsg = "Two playlist elements at the same relative offset"; + throw std::invalid_argument(eMsg); + } + + (*elementList)[*relativeOffset] = playlistElement; } diff --git a/livesupport/modules/core/src/PlaylistElement.cxx b/livesupport/modules/core/src/PlaylistElement.cxx index 07ac80480..2a16cb78f 100644 --- a/livesupport/modules/core/src/PlaylistElement.cxx +++ b/livesupport/modules/core/src/PlaylistElement.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistElement.cxx,v $ ------------------------------------------------------------------------------*/ @@ -79,7 +79,7 @@ static const std::string audioClipIdAttrName = "id"; /* ============================================================= module code */ /*------------------------------------------------------------------------------ - * Create a playlist object based on an XML element. + * Create a playlist element object based on an XML element. *----------------------------------------------------------------------------*/ void PlaylistElement :: configure(const xmlpp::Element & element) @@ -123,10 +123,8 @@ PlaylistElement :: configure(const xmlpp::Element & element) throw std::invalid_argument(eMsg); } - // this is not really a new allocation, but a new pointer into the inside - // of the parameter '& element' -- so no delete is needed (nor allowed) - xmlpp::Element * audioClipElement - = new xmlpp::Element( (*it)->cobj() ); + const xmlpp::Element * audioClipElement + = dynamic_cast (*it); if (!(attribute= audioClipElement->get_attribute(audioClipIdAttrName))) { std::string eMsg = "Missing "; diff --git a/livesupport/modules/core/src/PlaylistTest.cxx b/livesupport/modules/core/src/PlaylistTest.cxx index 01fe50cbf..37aadaaa1 100644 --- a/livesupport/modules/core/src/PlaylistTest.cxx +++ b/livesupport/modules/core/src/PlaylistTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.2 $ + Version : $Revision: 1.3 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -47,6 +47,7 @@ #include "PlaylistTest.h" +using namespace std; using namespace LiveSupport::Core; /* =================================================== local data structures */ @@ -99,7 +100,9 @@ PlaylistTest :: firstTest(void) const xmlpp::Element * root = document->get_root_node(); Ptr::Ref playlist(new Playlist()); +// cout << "\nconfig elott\n"; playlist->configure(*root); +// cout << "config utan\n"; CPPUNIT_ASSERT(playlist->getId()->getId() == 1); Ptr::Ref duration