added list of playlist elements to the Playlist class

This commit is contained in:
fgerlits 2004-10-14 10:25:16 +00:00
parent 9411445823
commit 0663e46425
5 changed files with 124 additions and 18 deletions

View File

@ -1,8 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE playlist [ <!DOCTYPE playlist [
<!ELEMENT playlist EMPTY > <!ELEMENT playlist (playlistElement*) >
<!ATTLIST playlist id NMTOKEN #REQUIRED > <!ATTLIST playlist id NMTOKEN #REQUIRED >
<!ATTLIST playlist playlength NMTOKEN #REQUIRED > <!ATTLIST playlist playlength NMTOKEN #REQUIRED >
<!ELEMENT playlistElement (audioClip) >
<!ATTLIST playlistElement id NMTOKEN #REQUIRED >
<!ATTLIST playlistElement relativeOffset NMTOKEN #REQUIRED >
<!ELEMENT audioClip EMPTY >
<!ATTLIST audioClip id NMTOKEN #REQUIRED >
<!ATTLIST audioClip playlength NMTOKEN #REQUIRED >
]> ]>
<playlist id="1" playlength="01:30:00.000"/>
<playlist id="1" playlength="01:30:00.000">
<playlistElement id="101" relativeOffset="0" >
<audioClip id="10001" playlength="01:00:00.000"/>
</playlistElement>
<playlistElement id="102" relativeOffset="01:00:00.000" >
<audioClip id="10002" playlength="00:30:00.000"/>
</playlistElement>
</playlist>

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ 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 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/Playlist.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -40,6 +40,7 @@
#include "configure.h" #include "configure.h"
#endif #endif
#include <map>
#include <stdexcept> #include <stdexcept>
#include <libxml++/libxml++.h> #include <libxml++/libxml++.h>
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
@ -47,6 +48,7 @@
#include "LiveSupport/Core/Ptr.h" #include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/UniqueId.h" #include "LiveSupport/Core/UniqueId.h"
#include "LiveSupport/Core/Configurable.h" #include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/PlaylistElement.h"
namespace LiveSupport { namespace LiveSupport {
@ -69,7 +71,7 @@ using namespace boost::posix_time;
* the playlist. * the playlist.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.2 $ * @version $Revision: 1.3 $
*/ */
class Playlist : public Configurable class Playlist : public Configurable
{ {
@ -99,6 +101,18 @@ class Playlist : public Configurable
*/ */
bool isLockedForEditing; bool isLockedForEditing;
/**
* A map type for storing the playlist elements associated with
* this playlist, indexed by their relative offsets.
*/
typedef std::map<const time_duration, Ptr<PlaylistElement>::Ref>
PlaylistElementListType;
/**
* The list of playlist elements for this playlist.
*/
Ptr<PlaylistElementListType>::Ref elementList;
public: public:
/** /**
@ -154,13 +168,10 @@ class Playlist : public Configurable
* @param element the XML element to configure the object from. * @param element the XML element to configure the object from.
* @exception std::invalid_argument if the supplied XML element * @exception std::invalid_argument if the supplied XML element
* contains bad configuraiton information * contains bad configuraiton information
* @exception std::logic_error if the object has already
* been configured, and can not be reconfigured.
*/ */
virtual void virtual void
configure(const xmlpp::Element & element) configure(const xmlpp::Element & element)
throw (std::invalid_argument, throw (std::invalid_argument);
std::logic_error);
/** /**
* Return the id of the playlist. * Return the id of the playlist.
@ -204,6 +215,43 @@ class Playlist : public Configurable
setLockedForPlaying(bool lockStatus) setLockedForPlaying(bool lockStatus)
throw (); 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<PlaylistElement>::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();
}
}; };

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ 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 $ 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"; static const std::string playlengthAttrName = "playlength";
/**
* The name of playlist element child nodes.
*/
static const std::string elementListAttrName = "playlistElement";
/* =============================================== local function prototypes */ /* =============================================== local function prototypes */
@ -72,8 +77,7 @@ static const std::string playlengthAttrName = "playlength";
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void void
Playlist :: configure(const xmlpp::Element & element) Playlist :: configure(const xmlpp::Element & element)
throw (std::logic_error, throw (std::invalid_argument)
std::invalid_argument)
{ {
if (element.get_name() != configElementNameStr) { if (element.get_name() != configElementNameStr) {
std::string eMsg = "Bad configuration element "; std::string eMsg = "Bad configuration element ";
@ -101,6 +105,43 @@ Playlist :: configure(const xmlpp::Element & element)
} }
playlength.reset(new time_duration( playlength.reset(new time_duration(
duration_from_string(attribute->get_value()))); 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<PlaylistElement>::Ref newPlaylistElement(new PlaylistElement);
const xmlpp::Element * childElement
= dynamic_cast<const xmlpp::Element*> (*it);
newPlaylistElement->configure(*childElement);
addPlaylistElement(newPlaylistElement);
++it;
}
isLockedForPlaying = false;
isLockedForEditing = false;
}
/*------------------------------------------------------------------------------
* Add a new playlist element to the playlist.
*----------------------------------------------------------------------------*/
void
Playlist::addPlaylistElement(Ptr<PlaylistElement>::Ref playlistElement)
throw (std::invalid_argument)
{
Ptr<const time_duration>::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;
} }

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ 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 $ 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 */ /* ============================================================= module code */
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
* Create a playlist object based on an XML element. * Create a playlist element object based on an XML element.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void void
PlaylistElement :: configure(const xmlpp::Element & element) PlaylistElement :: configure(const xmlpp::Element & element)
@ -123,10 +123,8 @@ PlaylistElement :: configure(const xmlpp::Element & element)
throw std::invalid_argument(eMsg); throw std::invalid_argument(eMsg);
} }
// this is not really a new allocation, but a new pointer into the inside const xmlpp::Element * audioClipElement
// of the parameter '& element' -- so no delete is needed (nor allowed) = dynamic_cast<const xmlpp::Element*> (*it);
xmlpp::Element * audioClipElement
= new xmlpp::Element( (*it)->cobj() );
if (!(attribute= audioClipElement->get_attribute(audioClipIdAttrName))) { if (!(attribute= audioClipElement->get_attribute(audioClipIdAttrName))) {
std::string eMsg = "Missing "; std::string eMsg = "Missing ";

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ 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 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/PlaylistTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -47,6 +47,7 @@
#include "PlaylistTest.h" #include "PlaylistTest.h"
using namespace std;
using namespace LiveSupport::Core; using namespace LiveSupport::Core;
/* =================================================== local data structures */ /* =================================================== local data structures */
@ -99,7 +100,9 @@ PlaylistTest :: firstTest(void)
const xmlpp::Element * root = document->get_root_node(); const xmlpp::Element * root = document->get_root_node();
Ptr<Playlist>::Ref playlist(new Playlist()); Ptr<Playlist>::Ref playlist(new Playlist());
// cout << "\nconfig elott\n";
playlist->configure(*root); playlist->configure(*root);
// cout << "config utan\n";
CPPUNIT_ASSERT(playlist->getId()->getId() == 1); CPPUNIT_ASSERT(playlist->getId()->getId() == 1);
Ptr<const boost::posix_time::time_duration>::Ref duration Ptr<const boost::posix_time::time_duration>::Ref duration