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 » Xmlize has problem with WithDeepCopy<Array<...
Re: Xmlize has problem with WithDeepCopy<Array<... [message #37686 is a reply to message #37684] Fri, 02 November 2012 01:47 Go to previous messageGo to previous message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
OK got it. Not sure why Xmlize is not working for WithDeepCopy <Vector <double> > but in any case the following two functions give slightly more functionality

	template<class T> static bool XmlizeArray1D(XmlIO& xml,String sCollection,String sItem,T& ar)
	{
		DUMP("XmlizeArray1D");
		
		int n;
		
		if(xml.IsStoring())
		{
			XmlIO xmla = xml.Add(sCollection);

			n = ar.GetCount();
			DUMP(n);
			xmla("Count",n);

			for(int i=0;i<n;i++)
			{
				String s = Format("%s%d",sItem,i);
				xmla(s,ar[i]);			
			}

		}
		else // IsLoading
		{
			int ii = -1;
			for(int i = 0; i < xml->GetCount(); i++)
			{
				if(xml->Node(i).IsTag(sCollection))
					ii = i;
			}
	
			if(ii<0)
			{
				DUMP("FAILED IN XmlizeArray1D");
				return false;
			}
			XmlIO xmla = xml.At(ii);

			xmla("Count",n);
			
			DUMP(n);
			
			if(n>=0)
				ar.SetCount(n);	
			else
				return false;	
			
			for(int i=0;i<n;i++)
			{
				String s = Format("%s%d",sItem,i);
				xmla(s,ar[i]);			
			}
			
		}	
	
		
		return true;
	}

	template<class S,class T> static bool XmlizeArray2D(XmlIO& xml,String sCollection,String Column,S& ss,T& ar)
	{
		DUMP("XmlizeArray2D");
		
		int n1,n2;
		
		if(xml.IsStoring())
		{
			XmlIO xmla = xml.Add(sCollection);

			n1 = ar.GetCount();
			xmla("Columns",n1);

			for(int i=0;i<n1;i++)
			{
				String sHeader = Format("%s%f",Column,ss[i]);
				XmlIO xmlb = xmla.Add(sHeader);
				
				n2 = ar[i].GetCount();
				xmlb("Rows",n2);
				
				for(int j=0;j<n2;j++)
				{
					String label = Format("v%d-%d",i,j);

					xmlb(label,ar[i][j]);
				}
			}			
		}
		else // IsLoading
		{
			int ii = -1;
			for(int i = 0; i < xml->GetCount(); i++)
			{
				if(xml->Node(i).IsTag(sCollection))
					ii = i;
			}
	
			if(ii<0)
			{
				DUMP("FAILED IN XmlizeArray2D1");
				return false;
			}
			
			XmlIO xmla = xml.At(ii);
							
			xmla("Columns",n1);
			ar.SetCount(n1);		

			DUMP(n1);
	
			for(int i=0;i<n1;i++)
			{
				String sHeader = Format("%s%f",Column,ss[i]);

				int jj = -1;
				for(int j = 0; j < xmla->GetCount(); j++)
				{
					if(xmla->Node(j).IsTag(sHeader))
						jj = j;
				}

				if(jj<0)
				{
					DUMP("FAILED IN XmlizeArray2D2");
					return false;
				}

				XmlIO xmlb = xmla.At(jj);
						
				xmlb("Rows",n2);
				ar[i].SetCount(n2);

				DUMP(n2);

				for(int j=0;j<n2;j++)
				{
					String label = Format("v%d-%d",i,j);

					xmlb(label,ar[i][j]);
				}
			}			
		}	
		
		return true;
	}



 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: LocalProcess to read from stderr
Next Topic: NTL container equivalent to STL bitset
Goto Forum:
  


Current Time: Mon Jun 16 19:39:17 CEST 2025

Total time taken to generate the page: 0.04624 seconds