changed duration_from_string() calls to TimeConversion::parseTimeDuration()

This commit is contained in:
fgerlits 2005-07-26 11:34:02 +00:00
parent aba0318f3c
commit 1769fe5b48
9 changed files with 49 additions and 46 deletions

View file

@ -7,4 +7,4 @@
<!ATTLIST fadeInfo fadeOut NMTOKEN #REQUIRED > <!ATTLIST fadeInfo fadeOut NMTOKEN #REQUIRED >
]> ]>
<fadeInfo id="0000000000009901" fadeIn="00:00:02.000000" <fadeInfo id="0000000000009901" fadeIn="00:00:02.000000"
fadeOut="00:00:01.500"/> fadeOut="00:00:01.0005"/>

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $ Author : $Author: fgerlits $
Version : $Revision: 1.28 $ Version : $Revision: 1.29 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/AudioClip.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -130,8 +130,8 @@ using namespace boost::posix_time;
* &lt;!ATTLIST audioClip uri CDATA #IMPLIED &gt; * &lt;!ATTLIST audioClip uri CDATA #IMPLIED &gt;
* </code></pre> * </code></pre>
* *
* @author $Author: maroy $ * @author $Author: fgerlits $
* @version $Revision: 1.28 $ * @version $Revision: 1.29 $
*/ */
class AudioClip : public Configurable, class AudioClip : public Configurable,
public Playable public Playable
@ -207,7 +207,7 @@ class AudioClip : public Configurable,
* a valid ISO-8601 time * a valid ISO-8601 time
*/ */
void void
setPlaylength(const std::string & timeString) setPlaylength(Ptr<const std::string>::Ref timeString)
throw (std::invalid_argument); throw (std::invalid_argument);

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.40 $ Version : $Revision: 1.41 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -128,7 +128,7 @@ using namespace boost::posix_time;
* </code></pre> * </code></pre>
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.40 $ * @version $Revision: 1.41 $
*/ */
class Playlist : public Configurable, class Playlist : public Configurable,
public Playable public Playable
@ -218,7 +218,7 @@ class Playlist : public Configurable,
* a valid ISO-8601 time * a valid ISO-8601 time
*/ */
void void
setPlaylength(const std::string & timeString) setPlaylength(Ptr<const std::string>::Ref timeString)
throw (std::invalid_argument); throw (std::invalid_argument);
/** /**

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.10 $ Version : $Revision: 1.11 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/TimeConversion.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/TimeConversion.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -71,7 +71,7 @@ using namespace LiveSupport;
* A helper object holding static time conversion functions. * A helper object holding static time conversion functions.
* *
* @author $Author: fgerlits $ * @author $Author: fgerlits $
* @version $Revision: 1.10 $ * @version $Revision: 1.11 $
*/ */
class TimeConversion class TimeConversion
{ {
@ -221,7 +221,7 @@ class TimeConversion
* @return the duration as a time_duration * @return the duration as a time_duration
*/ */
static Ptr<time_duration>::Ref static Ptr<time_duration>::Ref
parseTimeDuration(Ptr<std::string>::Ref durationString) parseTimeDuration(Ptr<const std::string>::Ref durationString)
throw (); throw ();
/** /**

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.30 $ Version : $Revision: 1.31 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/AudioClip.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/AudioClip.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -40,6 +40,7 @@
#include <id3v1tag.h> // for TagLib #include <id3v1tag.h> // for TagLib
#include <id3v2tag.h> // for TagLib #include <id3v2tag.h> // for TagLib
#include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Core/AudioClip.h" #include "LiveSupport/Core/AudioClip.h"
using namespace boost::posix_time; using namespace boost::posix_time;
@ -285,22 +286,15 @@ AudioClip :: setTitle(Ptr<const Glib::ustring>::Ref title)
* Set the value of the playlength from a string (private). * Set the value of the playlength from a string (private).
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void void
AudioClip :: setPlaylength(const std::string & timeString) AudioClip :: setPlaylength(Ptr<const std::string>::Ref timeString)
throw (std::invalid_argument) throw (std::invalid_argument)
{ {
try { try {
playlength.reset(new time_duration(duration_from_string(timeString))); playlength = TimeConversion::parseTimeDuration(timeString);
} catch (boost::bad_lexical_cast &e) {
std::string eMsg = "bad time format in playlength: ";
eMsg += e.what();
throw std::invalid_argument(eMsg);
} catch (std::exception &e) { } catch (std::exception &e) {
std::string eMsg = "bad time format in playlength: "; std::string eMsg = "bad time format in playlength: ";
eMsg += e.what(); eMsg += e.what();
throw std::invalid_argument(eMsg); throw std::invalid_argument(eMsg);
} catch ( ... ) {
std::string eMsg = "bad time format in playlength";
throw std::invalid_argument(eMsg);
} }
} }
@ -380,7 +374,10 @@ AudioClip :: configure(const xmlpp::Element & element)
if (!playlength && prefix == extentElementPrefix if (!playlength && prefix == extentElementPrefix
&& name == extentElementName) { && name == extentElementName) {
if (dataElement->has_child_text()) { if (dataElement->has_child_text()) {
setPlaylength(dataElement->get_child_text()->get_content()); Ptr<std::string>::Ref playlengthString(new std::string(
dataElement->get_child_text()
->get_content() ));
setPlaylength(playlengthString);
} else { // or just leave blank? bad either way } else { // or just leave blank? bad either way
playlength.reset(new time_duration(0,0,0,0)); playlength.reset(new time_duration(0,0,0,0));
} }
@ -496,7 +493,9 @@ AudioClip :: setMetadata(Ptr<const Glib::ustring>::Ref value,
throw (std::invalid_argument) throw (std::invalid_argument)
{ {
if (prefix == extentElementPrefix && name == extentElementName) { if (prefix == extentElementPrefix && name == extentElementName) {
setPlaylength(*value); // may throw invalid_argument Ptr<const std::string>::Ref valueString(new const std::string(
*value));
setPlaylength(valueString); // may throw invalid_argument
} }
if (prefix == titleElementPrefix && name == titleElementName) { if (prefix == titleElementPrefix && name == titleElementName) {

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.6 $ Version : $Revision: 1.7 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/FadeInfo.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/FadeInfo.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -35,6 +35,7 @@
#include <sstream> #include <sstream>
#include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Core/FadeInfo.h" #include "LiveSupport/Core/FadeInfo.h"
using namespace boost::posix_time; using namespace boost::posix_time;
@ -99,16 +100,18 @@ FadeInfo :: configure(const xmlpp::Element & element)
eMsg += idAttrName; eMsg += idAttrName;
throw std::invalid_argument(eMsg); throw std::invalid_argument(eMsg);
} }
fadeIn.reset(new time_duration( Ptr<std::string>::Ref fadeInString(new std::string(
duration_from_string(attribute->get_value()))); attribute->get_value() ));
fadeIn = TimeConversion::parseTimeDuration(fadeInString);
if (!(attribute = element.get_attribute(fadeOutAttrName))) { if (!(attribute = element.get_attribute(fadeOutAttrName))) {
std::string eMsg = "missing attribute "; std::string eMsg = "missing attribute ";
eMsg += idAttrName; eMsg += idAttrName;
throw std::invalid_argument(eMsg); throw std::invalid_argument(eMsg);
} }
fadeOut.reset(new time_duration( Ptr<std::string>::Ref fadeOutString(new std::string(
duration_from_string(attribute->get_value()))); attribute->get_value() ));
fadeOut = TimeConversion::parseTimeDuration(fadeOutString);
} }

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.39 $ Version : $Revision: 1.40 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -35,6 +35,7 @@
#include <sstream> #include <sstream>
#include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Core/Playlist.h" #include "LiveSupport/Core/Playlist.h"
using namespace boost::posix_time; using namespace boost::posix_time;
@ -279,22 +280,15 @@ Playlist :: setPlaylength(Ptr<time_duration>::Ref playlength)
* Set the value of the playlength from a string (private). * Set the value of the playlength from a string (private).
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void void
Playlist :: setPlaylength(const std::string & timeString) Playlist :: setPlaylength(Ptr<const std::string>::Ref timeString)
throw (std::invalid_argument) throw (std::invalid_argument)
{ {
try { try {
playlength.reset(new time_duration(duration_from_string(timeString))); playlength = TimeConversion::parseTimeDuration(timeString);
} catch (boost::bad_lexical_cast &e) {
std::string eMsg = "bad time format in playlength: ";
eMsg += e.what();
throw std::invalid_argument(eMsg);
} catch (std::exception &e) { } catch (std::exception &e) {
std::string eMsg = "bad time format in playlength: "; std::string eMsg = "bad time format in playlength: ";
eMsg += e.what(); eMsg += e.what();
throw std::invalid_argument(eMsg); throw std::invalid_argument(eMsg);
} catch ( ... ) {
std::string eMsg = "bad time format in playlength";
throw std::invalid_argument(eMsg);
} }
} }
@ -381,7 +375,10 @@ Playlist :: configure(const xmlpp::Element & element)
if (!playlength && prefix == extentElementPrefix if (!playlength && prefix == extentElementPrefix
&& name == extentElementName) { && name == extentElementName) {
if (dataElement->has_child_text()) { if (dataElement->has_child_text()) {
setPlaylength(dataElement->get_child_text()->get_content()); Ptr<const std::string>::Ref playlengthString(
new std::string(dataElement->get_child_text()
->get_content() ));
setPlaylength(playlengthString);
} else { // or just leave blank? bad either way } else { // or just leave blank? bad either way
playlength.reset(new time_duration(0,0,0,0)); playlength.reset(new time_duration(0,0,0,0));
} }
@ -708,7 +705,9 @@ Playlist :: setMetadata(Ptr<const Glib::ustring>::Ref value,
throw (std::invalid_argument) throw (std::invalid_argument)
{ {
if (prefix == extentElementPrefix && name == extentElementName) { if (prefix == extentElementPrefix && name == extentElementName) {
setPlaylength(*value); Ptr<const std::string>::Ref valueString(new const std::string(
*value));
setPlaylength(valueString);
} }
if (prefix == titleElementPrefix && name == titleElementName) { if (prefix == titleElementPrefix && name == titleElementName) {

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.12 $ Version : $Revision: 1.13 $
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 $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -35,6 +35,7 @@
#include <sstream> #include <sstream>
#include "LiveSupport/Core/TimeConversion.h"
#include "LiveSupport/Core/Playlist.h" #include "LiveSupport/Core/Playlist.h"
#include "LiveSupport/Core/PlaylistElement.h" #include "LiveSupport/Core/PlaylistElement.h"
@ -112,8 +113,9 @@ PlaylistElement :: configure(const xmlpp::Element & element)
eMsg += relativeOffsetAttrName; eMsg += relativeOffsetAttrName;
throw std::invalid_argument(eMsg); throw std::invalid_argument(eMsg);
} }
relativeOffset.reset(new time_duration( Ptr<std::string>::Ref relativeOffsetString(new std::string(
duration_from_string(attribute->get_value()))); attribute->get_value() ));
relativeOffset = TimeConversion::parseTimeDuration(relativeOffsetString);
// set audio clip // set audio clip
xmlpp::Node::NodeList childNodes xmlpp::Node::NodeList childNodes

View file

@ -22,7 +22,7 @@
Author : $Author: fgerlits $ Author : $Author: fgerlits $
Version : $Revision: 1.10 $ Version : $Revision: 1.11 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversion.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/TimeConversion.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -218,7 +218,7 @@ TimeConversion :: timeDurationToHhMmSsString(
* Parse a string to a time_duration. * Parse a string to a time_duration.
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
Ptr<time_duration>::Ref Ptr<time_duration>::Ref
TimeConversion :: parseTimeDuration(Ptr<std::string>::Ref durationString) TimeConversion :: parseTimeDuration(Ptr<const std::string>::Ref durationString)
throw () throw ()
{ {
int micros = 0; int micros = 0;