X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fxmlstructure.cpp;h=415f7036c96b185cba2f29b51f63d8ff97eba77f;hb=49d6b9552ae4871e934140db8089889936bee85b;hp=f2832c3a86f02ca19150cb01be944ab4a1618a81;hpb=526db67540bf69a4c09ed0d0f4d62bad0a37ee70;p=lsystem3d.git diff --git a/src/xmlstructure.cpp b/src/xmlstructure.cpp index f2832c3..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; @@ -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(); +}