Subtitle::Subtitle (xmlpp::Node const * node)
: XMLNode (node)
{
+ _in = time_attribute ("TimeIn");
+ _out = time_attribute ("TimeOut");
_texts = sub_nodes<Text> ("Text");
}
Text::Text (xmlpp::Node const * node)
: XMLNode (node)
{
-
+ _text = content ();
+ _v_position = float_attribute ("VPosition");
}
return _out;
}
- std::list<boost::shared_ptr<Text> > texts () const {
+ std::list<boost::shared_ptr<Text> > const & texts () const {
return _texts;
}
Font () {}
Font (xmlpp::Node const * node);
- std::list<boost::shared_ptr<Subtitle> > subtitles () const {
+ std::list<boost::shared_ptr<Subtitle> > const & subtitles () const {
return _subtitles;
}
return _language;
}
- std::list<boost::shared_ptr<Font> > fonts () const {
+ std::list<boost::shared_ptr<Font> > const & fonts () const {
return _fonts;
}
#include <iostream>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
+#include <boost/algorithm/string.hpp>
#include <libxml++/libxml++.h>
#include "xml.h"
#include "exceptions.h"
string
XMLNode::string_node (string name)
{
- xmlpp::Node* node = xml_node (name);
-
- xmlpp::Node::NodeList c = node->get_children ();
-
- if (c.size() > 1) {
- throw XMLError ("unexpected content in XML node");
- }
-
- if (c.empty ()) {
- return "";
- }
-
- xmlpp::ContentNode const * v = dynamic_cast<xmlpp::ContentNode const *> (c.front());
- if (!v) {
- throw XMLError ("missing content in XML node");
- }
-
- return v->get_content ();
+ return XMLNode (xml_node (name)).content ();
}
string
Time
XMLNode::time_attribute (string name)
{
+ string const t = string_attribute (name);
+
+ vector<string> b;
+ boost::split (b, t, is_any_of (":"));
+ assert (b.size() == 4);
+
+ return Time (lexical_cast<int> (b[0]), lexical_cast<int> (b[1]), lexical_cast<int> (b[2]), lexical_cast<int> (b[3]));
+}
+
+string
+XMLNode::string_attribute (string name)
+{
+ xmlpp::Element const * e = dynamic_cast<const xmlpp::Element *> (_node);
+ if (!e) {
+ return "";
+ }
+
+ xmlpp::Attribute* a = e->get_attribute (name);
+ if (!a) {
+ return "";
+ }
+ return a->get_value ();
+}
+
+float
+XMLNode::float_attribute (string name)
+{
+ return lexical_cast<float> (string_attribute (name));
}
void
}
}
+string
+XMLNode::content ()
+{
+ xmlpp::Node::NodeList c = _node->get_children ();
+
+ if (c.size() > 1) {
+ throw XMLError ("unexpected content in XML node");
+ }
+
+ if (c.empty ()) {
+ return "";
+ }
+
+ xmlpp::ContentNode const * v = dynamic_cast<xmlpp::ContentNode const *> (c.front());
+ if (!v) {
+ throw XMLError ("missing content in XML node");
+ }
+
+ return v->get_content ();
+}
+
XMLFile::XMLFile (string file, string root_name)
{
if (!filesystem::exists (file)) {
#include <boost/shared_ptr.hpp>
#include "types.h"
#include "exceptions.h"
+#include "dcp_time.h"
namespace xmlpp {
class Node;
Time time_attribute (std::string);
float float_attribute (std::string);
+ std::string string_attribute (std::string);
+
+ std::string content ();
template <class T>
boost::shared_ptr<T> sub_node (std::string name) {
BOOST_CHECK_EQUAL ((*i)->texts().size(), 1);
BOOST_CHECK_EQUAL ((*i)->texts().front()->v_position(), 15);
BOOST_CHECK_EQUAL ((*i)->texts().front()->text(), "My jacket was Idi Amin's");
+ ++i;
+
+ BOOST_CHECK_EQUAL ((*i)->in(), libdcp::Time (0, 0, 7, 177));
+ BOOST_CHECK_EQUAL ((*i)->out(), libdcp::Time (0, 0, 11, 31));
+ BOOST_CHECK_EQUAL ((*i)->texts().size(), 2);
+ BOOST_CHECK_EQUAL ((*i)->texts().front()->v_position(), 21);
+ BOOST_CHECK_EQUAL ((*i)->texts().front()->text(), "My corset was H.M. The Queen's");
+ BOOST_CHECK_EQUAL ((*i)->texts().back()->v_position(), 15);
+ BOOST_CHECK_EQUAL ((*i)->texts().back()->text(), "My large wonderbra");
+ ++i;
+
+ BOOST_CHECK_EQUAL ((*i)->in(), libdcp::Time (0, 0, 11, 94));
+ BOOST_CHECK_EQUAL ((*i)->out(), libdcp::Time (0, 0, 13, 63));
+ BOOST_CHECK_EQUAL ((*i)->texts().size(), 1);
+ BOOST_CHECK_EQUAL ((*i)->texts().front()->v_position(), 15);
+ BOOST_CHECK_EQUAL ((*i)->texts().front()->text(), "Once belonged to the Shah");
+ ++i;
+
+ BOOST_CHECK_EQUAL ((*i)->in(), libdcp::Time (0, 0, 13, 104));
+ BOOST_CHECK_EQUAL ((*i)->out(), libdcp::Time (0, 0, 15, 177));
+ BOOST_CHECK_EQUAL ((*i)->texts().size(), 1);
+ BOOST_CHECK_EQUAL ((*i)->texts().front()->v_position(), 15);
+ BOOST_CHECK_EQUAL ((*i)->texts().front()->text(), "And these are Roy Hattersley's jeans");
}