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) {
return lexical_cast<int64_t> (string_attribute (name));
}
+int64_t
+XMLNode::optional_int64_attribute (string name)
+{
+ string const s = optional_string_attribute (name);
+ if (s.empty ()) {
+ return 0;
+ }
+
+ return lexical_cast<int64_t> (s);
+}
+
+optional<bool>
+XMLNode::optional_bool_attribute (string name)
+{
+ string const s = optional_string_attribute (name);
+ if (s.empty ()) {
+ return optional<bool> ();
+ }
+
+ if (s == "1" || s == "yes") {
+ return optional<bool> (true);
+ }
+
+ 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 ()
{