Removed glibmm dependency.
[lsystem3d.git] / src / xmlstructure.cpp
index b7466c0c560278ededb44427e6280a34846ce0da..415f7036c96b185cba2f29b51f63d8ff97eba77f 100644 (file)
@@ -1,6 +1,6 @@
 // Copyright (C) 2006 Erik Dahlberg
 // 
-// This file is part of LSystem3d.
+// This file is part of LSystem3D.
 // 
 // LSystem3D is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License
 
 
 
+#include <cstdlib>
+
+#include <sstream>
 #include <string>
 
+#include <libxml++/attribute.h>
 #include <libxml++/document.h>
 #include <libxml++/nodes/element.h>
 #include <libxml++/nodes/node.h>
 #include <libxml++/parsers/domparser.h>
 
-#include <glibmm/stringutils.h>
-
 #include "xmlstructure.h"
 
 using namespace std;
@@ -42,7 +44,7 @@ XMLStructure::XMLStructure()
     _rootElement = NULL;
     _activeElement = NULL;
     _activeDocument = NULL;
-    _activeChildInList = NULL;
+    _activeChildInList = (xmlpp::Node::NodeList::iterator)NULL;
 }
 
 
@@ -99,10 +101,7 @@ void XMLStructure::addString(string text)
  */
 void XMLStructure::addNumber(double value)
 {
-    // convert double -> string
-    string numberAsString = Glib::Ascii::dtostr(value);
-    
-    addString(numberAsString);
+    addString(doubleToString(value));
 }
 
 
@@ -206,8 +205,7 @@ string XMLStructure::getString()
  */
 double XMLStructure::getNumber()
 {
-    // convert string -> double
-    double number = Glib::Ascii::strtod(getString());
+    double number = strtod(getString().c_str(), NULL);
 
     return number;
 }
@@ -225,7 +223,28 @@ string XMLStructure::getAttribute(string name)
     xmlpp::Element *child = dynamic_cast<xmlpp::Element*>(*_activeChildInList);
     
     // its attribute value
-    string attributeValue = child->get_attribute(name)->get_value();
+    string attributeValue;
+    xmlpp::Attribute *attribute = child->get_attribute(name);
+    
+    if (attribute)
+    {
+        attributeValue = attribute->get_value();
+    }
     
     return attributeValue;
 }
+
+
+
+/**
+ * Convert double to string
+ * @param doubleValue the double value
+ * @return the corresponding string
+ */
+string XMLStructure::doubleToString(double doubleValue)
+{
+    ostringstream doubleAsString;
+    doubleAsString << doubleValue;
+    
+    return doubleAsString.str();
+}