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" ?>
<!DOCTYPE playlist [
<!ELEMENT playlist EMPTY >
<!ELEMENT playlist (playlistElement*) >
<!ATTLIST playlist id 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 $
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 <map>
#include <stdexcept>
#include <libxml++/libxml++.h>
#include <boost/date_time/posix_time/posix_time.hpp>
@ -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<const time_duration, Ptr<PlaylistElement>::Ref>
PlaylistElementListType;
/**
* The list of playlist elements for this playlist.
*/
Ptr<PlaylistElementListType>::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<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 $
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<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 $
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<const xmlpp::Element*> (*it);
if (!(attribute= audioClipElement->get_attribute(audioClipIdAttrName))) {
std::string eMsg = "Missing ";

View File

@ -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<Playlist>::Ref playlist(new Playlist());
// cout << "\nconfig elott\n";
playlist->configure(*root);
// cout << "config utan\n";
CPPUNIT_ASSERT(playlist->getId()->getId() == 1);
Ptr<const boost::posix_time::time_duration>::Ref duration