Some maths operations with Time.
[libdcp.git] / src / xml.cc
index bc42ebce34be11aa2bc835193491c21afb4fe130..35c4fe1274de2ef8e8f0e0701d6a9091f2d9b805 100644 (file)
@@ -126,17 +126,27 @@ XMLNode::ignore_node (string name)
 Time
 XMLNode::time_attribute (string name)
 {
-       string const t = string_attribute (name);
+       return Time (string_attribute (name));
+}
 
-       vector<string> b;
-       boost::split (b, t, is_any_of (":"));
-       assert (b.size() == 4);
+string
+XMLNode::string_attribute (string name)
+{
+       xmlpp::Element const * e = dynamic_cast<const xmlpp::Element *> (_node);
+       if (!e) {
+               throw XMLError ("missing attribute");
+       }
+       
+       xmlpp::Attribute* a = e->get_attribute (name);
+       if (!a) {
+               throw XMLError ("missing attribute");
+       }
 
-       return Time (lexical_cast<int> (b[0]), lexical_cast<int> (b[1]), lexical_cast<int> (b[2]), lexical_cast<int> (b[3]));
+       return a->get_value ();
 }
 
 string
-XMLNode::string_attribute (string name)
+XMLNode::optional_string_attribute (string name)
 {
        xmlpp::Element const * e = dynamic_cast<const xmlpp::Element *> (_node);
        if (!e) {
@@ -166,7 +176,7 @@ XMLNode::int64_attribute (string name)
 int64_t
 XMLNode::optional_int64_attribute (string name)
 {
-       string const s = string_attribute (name);
+       string const s = optional_string_attribute (name);
        if (s.empty ()) {
                return 0;
        }
@@ -177,7 +187,7 @@ XMLNode::optional_int64_attribute (string name)
 optional<bool>
 XMLNode::optional_bool_attribute (string name)
 {
-       string const s = string_attribute (name);
+       string const s = optional_string_attribute (name);
        if (s.empty ()) {
                return optional<bool> ();
        }
@@ -189,6 +199,17 @@ XMLNode::optional_bool_attribute (string name)
        return optional<bool> (false);
 }
 
+optional<Color>
+XMLNode::optional_color_attribute (string name)
+{
+       string const s = optional_string_attribute (name);
+       if (s.empty ()) {
+               return optional<Color> ();
+       }
+
+       return optional<Color> (Color (s));
+}
+
 void
 XMLNode::done ()
 {