Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » XmlIO - New function proposal
XmlIO - New function proposal [message #8602] Tue, 20 March 2007 23:22 Go to next message
victorb is currently offline  victorb
Messages: 78
Registered: December 2005
Location: Nice, France
Member
My application is using XML to store/retrieve data. Many elements are using the same default value. In this case I don't want to store the attribute value in the XML but I want it restored to a default value (instead of Null) when reading the configuration back. I have added this new function to XmlIO class

	template <class T> XmlIO Attr(const char *id, T& var, T def) {
		if(IsLoading()) {
			XmlAttrLoad(var, node.Attr(id));
			var = Nvl(var, def);
		} else if (var != def) 
			node.SetAttr(id, XmlAttrStore(var));		
		return *this;
	}


Do you think it might be useful to have this in standard Upp ?
Re: XmlIO - New function proposal [message #8605 is a reply to message #8602] Tue, 20 March 2007 23:54 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 14105
Registered: November 2005
Ultimate Member
This is a good idea, but it would IMHO require a little bit more complex change; the trouble is that XmlAttrLoad do not always use Null as the default value.

Maybe we should change it so that XmlAttrLoad would not set the value if it is missing? Or add another parameter to XmlAttrLoad?

Mirek
Re: XmlIO - New function proposal [message #8607 is a reply to message #8605] Wed, 21 March 2007 08:45 Go to previous messageGo to next message
victorb is currently offline  victorb
Messages: 78
Registered: December 2005
Location: Nice, France
Member
Oops... you are right about XmlAttrLoad not always returning Null and thanks for pointing me to the right direction "Maybe we should change it so that XmlAttrLoad would not set the value if it is missing?"

The following function should do the trick:

	template <class T> XmlIO Attr(const char *id, T& var, T def) {
		if(IsLoading())
		    if (IsNull(node.Attr(id)))
				var = def;
		    else
				XmlAttrLoad(var, node.Attr(id));		        
	 	else if (var != def) 
				node.SetAttr(id, XmlAttrStore(var));		
		return *this;
	}
Re: XmlIO - New function proposal [message #8713 is a reply to message #8607] Mon, 26 March 2007 21:47 Go to previous message
mirek is currently offline  mirek
Messages: 14105
Registered: November 2005
Ultimate Member
I like it. Now in Core.

Mirek
Previous Topic: "Copy folder recursively" is there a function?
Next Topic: Unsafe Deep Copy
Goto Forum:
  


Current Time: Fri Nov 01 00:42:46 CET 2024

Total time taken to generate the page: 0.02050 seconds