X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fxmlstructure.cpp;h=415f7036c96b185cba2f29b51f63d8ff97eba77f;hb=49d6b9552ae4871e934140db8089889936bee85b;hp=b7466c0c560278ededb44427e6280a34846ce0da;hpb=dd73b028a74ef8b57569c3e76751481d2124e491;p=lsystem3d.git diff --git a/src/xmlstructure.cpp b/src/xmlstructure.cpp index b7466c0..415f703 100644 --- a/src/xmlstructure.cpp +++ b/src/xmlstructure.cpp @@ -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 @@ -19,15 +19,17 @@ +#include + +#include #include +#include #include #include #include #include -#include - #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(*_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(); +}