U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ Core » Xmlize works only for storing
Re: Xmlize works only for storing [message #18486 is a reply to message #18483] Fri, 03 October 2008 11:54 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
Mindtraveller wrote on Fri, 03 October 2008 03:13

I see no critical problem with this. You may write your own class derived from std::list<...> with Xmlize function.
Besides I do not thnk it is good idea to mix STL and NTL libraries in code.


Well, I certainly would not recomend using STL Smile but sometimes you perhaps need to deal with existing code...

You can define Xmlize as template function specialisation and that solves the problem of "external" types:

#include <Core/Core.h>
#include <vector>

using namespace Upp;
using namespace std;

template<> void Upp::Xmlize(XmlIO xml, vector<int>& data) {
	if(xml.IsStoring())
		for(int i = 0; i < (int)data.size(); i++)
			Xmlize(xml.Add("item"), data[i]);
	else {
		data.clear();
		for(int i = 0; i < xml->GetCount(); i++)
			if(xml->Node(i).IsTag("item")) {
				data.push_back(0);
				Xmlize(xml.At(i), data.back());
			}
	}
}

CONSOLE_APP_MAIN
{
	vector<int> x;
	x.push_back(1);
	x.push_back(2);
	x.push_back(3);
	String s = StoreAsXML(x, "std-test");
	DUMP(s);
	vector<int> y;
	LoadFromXML(y, s);
	for(int i = 0; i < (int)y.size(); i++)
		DUMP(y[i]);
}


Mirek

[Updated on: Fri, 03 October 2008 11:54]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: FindFile, get dir list
Next Topic: String reverse find
Goto Forum:
  


Current Time: Fri Jun 19 02:49:26 GMT+2 2026

Total time taken to generate the page: 0.00564 seconds