Home » U++ Library support » U++ Core » Xmlize and double
Xmlize and double [message #739] |
Mon, 30 January 2006 07:55  |
pivica
Messages: 57 Registered: November 2005 Location: Belgrade, Serbia
|
Member |
|
|
How to save and load double into xml. On way to save double is to convert him to String, but when loading I can't find a way to convert that String back to double.
class SomeClass
{
double d;
Vector<double> vd;
void Xmlize(XmlIO xml)
{
String sd;
Vector<String> svd;
if (xml.IsStoring())
{
sd = AsString(d);
int n = vd.GetCount();
for (int i = 0; i < n; ++i)
svd.Add(AsString(vd[i]));
}
xml
("d", sd)
("vd", svd)
;
if (xml.IsLoading())
{
// now what???
}
}
}
|
|
|
|
|
|
Problems with null doubles and Xmlize in 602b version. [message #903 is a reply to message #882] |
Tue, 07 February 2006 16:55   |
pivica
Messages: 57 Registered: November 2005 Location: Belgrade, Serbia
|
Member |
|
|
I've just downloaded 602b. Xmlize class for doubles works OK when numbers are not DOUBLE_NULL. But in application which I am developing user can leave empty EditDouble ctrls and in that case double from that ctrls has DOUBLE_NULL value. When storing with Xmlize such double value has empty string value, but when trying to load it XmlError("expected floating point number") is raised.
For example:
class A
{
public:
void Xmlize(XmlIO xml) { xml ("d", d); }
double d;
};
//...
EditDouble ctrl;
ctrl.Clear();
A a;
a.d = ctrl; // Now d has DOUBLE_NULL value
StoreAsXMLFile(a, "a", "a.xml");
LoadFromXMLFile(a, "a.xml"); // return false!
"a.xml" after StoreAsXMLFile is something like this:
<a>
<d value=""/>
</a>
Problem is in Xmlize.cpp in XmlAttrLoad(double& var, const String& text) method, XmlError is raised when text is empty.
template<> void XmlAttrLoad(double& var, const String& text)
{
CParser p(text);
if(!p.IsDouble())
throw XmlError("expected floating point number");
var = p.ReadDouble();
}
My temporary workaround is to determine if text is empty:
template<> void XmlAttrLoad(double& var, const String& text)
{
CParser p(text);
/////
if (text.IsEmpty())
{
var = DOUBLE_NULL;
return;
}
/////
if(!p.IsDouble())
throw XmlError("expected floating point number");
var = p.ReadDouble();
}
Same problem maybe exist in XmlAttrLoad(int& var, const String& text) and XmlAttrLoad(dword& var, const String& text). They are also throwing XmlError.
|
|
|
|
|
Goto Forum:
Current Time: Tue Apr 29 08:24:39 CEST 2025
Total time taken to generate the page: 0.03374 seconds
|