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 » ValueArray behaviour / inconsistantcy / BUG?
ValueArray behaviour / inconsistantcy / BUG? [message #29434] Wed, 20 October 2010 09:33 Go to previous message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
hi guys, i'm trying to make ValueArray work for me.
i cant quite get it to the point to be persistant, means to serialize and xmlize properly..

maybe one of you familiar with ValueArray could quickly spot the error in my code bellow (if there is any).

the test prog is attached as well as a ready to run package.
thanks a lot in advance.

Xmlize of ValueArray is kinda custom, but seems to work..
Serialize OTOH does not, and i dont exactly know why..
it deserializes but i cant get the ValueArray back from beeing Value.

#include <Core/Core.h>

using namespace Upp;

void ValueArrayXmlize(XmlIO xml, Value& v)
{
	if(xml.IsStoring())
	{
		const ValueArray& va = v;
		XmlizeStore(xml, va.Get());
	}
	if(xml.IsLoading())
	{
		ValueArray va;
		Vector<Value>& vv = const_cast<Vector<Value>&>(va.Get());
		::Xmlize(xml, vv);
		v = va;
	}
}
INITBLOCK { RegisterValueXmlize(GetValueTypeNo<ValueArray>(), &ValueArrayXmlize, "ValueArray"); }


CONSOLE_APP_MAIN
{
	ValueArray va;
	Vector<Value>& vv = const_cast<Vector<Value>&>(va.Get());
	vv << 123;
	vv << "Hallo";

	Value v = va;

	RLOG(v);
	
	StoreAsXMLFile(v);
	StoreToFile(v);

	Value v2;
	LoadFromXMLFile(v2);

	RLOG(v2);	

	const ValueArray& va2 = v2;

	const Vector<Value>& vv2 = va2.Get();
	
	ASSERT(v2.Is<ValueArray>());
	ASSERT(va2.GetCount() == va.GetCount());
	ASSERT(vv2.GetCount() == vv.GetCount());
	
	for(int i = 0; i < vv2.GetCount(); i++)
		ASSERT(vv2[i] == vv[i]);


	Value v3;
	LoadFromFile(v3);

	RLOG(v3);	

	const ValueArray& va3 = v3; //CRASH

	const Vector<Value>& vv3 = va3.Get();
	
	ASSERT(v3.Is<ValueArray>());
	ASSERT(va3.GetCount() == va.GetCount());
	ASSERT(vv3.GetCount() == vv.GetCount());
	
	for(int i = 0; i < vv3.GetCount(); i++)
		ASSERT(vv3[i] == vv[i]);
}
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: First use of SetVppLogName will call sOpenVppLog twice
Next Topic: Middle-ground between CONSOLE_APP_MAIN and GUI_APP_MAIN
Goto Forum:
  


Current Time: Wed May 15 09:29:49 CEST 2024

Total time taken to generate the page: 0.03005 seconds