openframeworks/openFrameworks — pull request #2235 by arturoc (2013-07-13 12:28:27+00:00)
Title: Bugfix ofXml + ofxGui using ofXml- don't merge yet

I'm trying to port ofxGui to use ofXml instead of ofxXmlSettings so no additional addons are needed but have found some bugs in ofXml, i've fixed some of them but not sure how to go about others:

Fixed
====

- getValue as string was cutting strings with spaces in them, i've fixed it by using a new function ofFromString that is specialized for strings returning the whole thing instead of using a stringstream to parse the string
- added specific getters for the most used types
- ofXml implements ofBaseFileSerializer which forces it to implement:
load(path)
save(path)
serialize(parameter)
deserialize(parameter)
- fixed several warnings that came mostly from comparisons between signed and unsigned ints
- converted several while loops to for loops which are prefered in OF

Not Fixed
=======

- In ofXml.cpp line 676:
parent = (Poco::XML::Element*) parent->parentNode();
parent is not initialized yet so any call that arrives to that line will make the app crash
- When an ofXml is created and nothing is loaded or when load fails, element is set to NULL but there's lots of calls that don't check that so some calls crash the applciation. To test, in the guiExample, delete data/settings.xml and try to save the gui. The gui internally tries to load the document then saves the new values, when it tries to save a call to exists(path) makes the app crash since it tries to call element without checking that it's NULL. I've tried to add the checks but there's some calls where i'm not sure how to go about it for example in addXml
- in ofXml.h in getValue, line 209 there's now (i changed it but the result was the same before):

ofLogWarning("ofXml", "Path not found when getting value ");
return T(); // hmm. this could be a problem

which will actually return an unitialized value for primitive types, perhaps we could add a default value like:

getValue(name,value=T())

then the specialized functions will set the correct value like

getIntValue()

will set it to 0. or we can just force to pass a default value as it worked in ofXmlSettings

@joshuajnoble can you take a look? let me know if you have any doubts about the code i've added