summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-08-13 01:45:42 +0100
committerCarl Hetherington <cth@carlh.net>2012-08-13 01:45:42 +0100
commit4c987f7feb504fe4011b52ffeb231e3b25823de1 (patch)
tree893c852593830fa5fe5a769bf61fcef86d57b9bf /src
parentc14a05a935886345d4d891a92a31b1c35bf10582 (diff)
Basic subtitle test works.
Diffstat (limited to 'src')
-rw-r--r--src/subtitle_asset.cc5
-rw-r--r--src/subtitle_asset.h6
-rw-r--r--src/xml.cc69
-rw-r--r--src/xml.h4
4 files changed, 62 insertions, 22 deletions
diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc
index 19697a7f..ca27d6da 100644
--- a/src/subtitle_asset.cc
+++ b/src/subtitle_asset.cc
@@ -44,11 +44,14 @@ Font::Font (xmlpp::Node const * node)
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");
}
diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h
index 392d70b4..02db6815 100644
--- a/src/subtitle_asset.h
+++ b/src/subtitle_asset.h
@@ -57,7 +57,7 @@ public:
return _out;
}
- std::list<boost::shared_ptr<Text> > texts () const {
+ std::list<boost::shared_ptr<Text> > const & texts () const {
return _texts;
}
@@ -73,7 +73,7 @@ public:
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;
}
@@ -95,7 +95,7 @@ public:
return _language;
}
- std::list<boost::shared_ptr<Font> > fonts () const {
+ std::list<boost::shared_ptr<Font> > const & fonts () const {
return _fonts;
}
diff --git a/src/xml.cc b/src/xml.cc
index 79baa01c..21912bdf 100644
--- a/src/xml.cc
+++ b/src/xml.cc
@@ -2,6 +2,7 @@
#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"
@@ -59,24 +60,7 @@ XMLNode::xml_nodes (string name)
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
@@ -142,7 +126,35 @@ XMLNode::ignore_node (string name)
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
@@ -156,6 +168,27 @@ XMLNode::done ()
}
}
+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)) {
diff --git a/src/xml.h b/src/xml.h
index 5c071958..85589a0f 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -8,6 +8,7 @@
#include <boost/shared_ptr.hpp>
#include "types.h"
#include "exceptions.h"
+#include "dcp_time.h"
namespace xmlpp {
class Node;
@@ -35,6 +36,9 @@ protected:
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) {