From 4c987f7feb504fe4011b52ffeb231e3b25823de1 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 13 Aug 2012 01:45:42 +0100 Subject: Basic subtitle test works. --- src/subtitle_asset.cc | 5 +++- src/subtitle_asset.h | 6 ++--- src/xml.cc | 69 +++++++++++++++++++++++++++++++++++++-------------- src/xml.h | 4 +++ 4 files changed, 62 insertions(+), 22 deletions(-) (limited to 'src') 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 (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 > texts () const { + std::list > const & texts () const { return _texts; } @@ -73,7 +73,7 @@ public: Font () {} Font (xmlpp::Node const * node); - std::list > subtitles () const { + std::list > const & subtitles () const { return _subtitles; } @@ -95,7 +95,7 @@ public: return _language; } - std::list > fonts () const { + std::list > 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 #include #include +#include #include #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 (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 b; + boost::split (b, t, is_any_of (":")); + assert (b.size() == 4); + + return Time (lexical_cast (b[0]), lexical_cast (b[1]), lexical_cast (b[2]), lexical_cast (b[3])); +} + +string +XMLNode::string_attribute (string name) +{ + xmlpp::Element const * e = dynamic_cast (_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 (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 (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 #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 boost::shared_ptr sub_node (std::string name) { -- cgit v1.2.3