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 » Vector a user defined struct for XML persistency
Vector a user defined struct for XML persistency [message #55196] Sat, 17 October 2020 10:20 Go to next message
sinpeople is currently offline  sinpeople
Messages: 8
Registered: October 2020
Location: Singapore
Promising Member

Hi folks,

I am trying to put a user-defined Phase struct into a vector before using XML for persistency. It worked fine before I put it into a vector.

The code is below:
struct Phase
{
	int 						id;
	double 						split;
	Vector<int> 		signal_groups;
	int							min_green;
	int							all_red;
	int							amber;
	int							skip;
	void Xmlize(XmlIO& xml);
};

void Phase::Xmlize(XmlIO& xml)
{
	xml
		("id", id)
		("split", split)
		.List("signal_groups", "signal_group", signal_groups)
		("min_green", min_green)
		("all_red", all_red)
		("amber", amber)
		("skip", skip)
	;
}

struct JunctionCFG {
	Size                      sz;
	int                       lang;
	String                    text;
	Vector<Size>              vector;
	VectorMap<String, int>    score;
	VectorMap<String, String> map;
	ArrayMap<int, Size>       sizemap;
	double                    number;
	bool                      option;

	Phase			phase;
	
//  Comment here, other compiling error	
//	Vector<Phase>  phase_grp;


	void Init();
	void Load();
	void Save();
	//void Dump();
	void Xmlize(XmlIO& xml);
};

void JunctionCFG::Xmlize(XmlIO& xml)
{
	xml
		("Dimension", sz)
		("text", text)
		.List("vector", "size", vector)
		("Scores", score)
		("map", map)
		("sizemap", sizemap)
		("number", number)
		("option", option)
		("phase", phase)
//		.List("phase_group", "phase", phase_grp)
	;
	XmlizeLang(xml, "Language", lang);
}



After the Vector<Phase> is added into the code, it has compiling error like
the following:
Quote:

Core/Topt.h line 171 required from 'void Upp::AssertMoveable(T*)[with T= Phase]'
Core/Topt.h line 157 error: no match for 'operator*'(operand type is 'Phase')


index.php?t=getfile&id=6263&private=0


Ideally, I want the XML looks like
<phases>
	<phase>
		<id value="2"/>
		<split value="0.25"/>
		<signal_groups>
			<signal_group value="25"/>
			<signal_group value="50"/>
		</signal_groups>
		<min_green value="-986896"/>
		<all_red value="20"/>
		<amber value="4"/>
		<skip value="-1"/>
	</phase>
	<phase>
		<id value="2"/>
		<split value="0.25"/>
		<signal_groups>
			<signal_group value="25"/>
			<signal_group value="50"/>
		</signal_groups>
		<min_green value="-986896"/>
		<all_red value="20"/>
		<amber value="4"/>
		<skip value="-1"/>
	</phase>
	<phase>
		<id value="2"/>
		<split value="0.25"/>
		<signal_groups>
			<signal_group value="25"/>
			<signal_group value="50"/>
		</signal_groups>
		<min_green value="-986896"/>
		<all_red value="20"/>
		<amber value="4"/>
		<skip value="-1"/>
	</phase>
	<phase>
		<id value="2"/>
		<split value="0.25"/>
		<signal_groups>
			<signal_group value="25"/>
			<signal_group value="50"/>
		</signal_groups>
		<min_green value="-986896"/>
		<all_red value="20"/>
		<amber value="4"/>
		<skip value="-1"/>
	</phase>
</phases>


Thank you very much for your support!

Best Regards
David WANG
  • Attachment: Capture.JPG
    (Size: 57.23KB, Downloaded 57 times)
Re: Vector a user defined struct for XML persistency [message #55197 is a reply to message #55196] Sat, 17 October 2020 10:33 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 759
Registered: August 2007
Contributor
Hello,

You have to mark the struct as Moveable. (Vector requires its elements to be moveable. Array doesn't.)

struct Phase : Moveable<Phase> // <--
{
	int 			id;
	double 			split;
	Vector<int> 		signal_groups;
	int			min_green;
	int			all_red;
	int			amber;
	int			skip;
	void Xmlize(XmlIO& xml);
};




Best regards,
Oblivion


[Updated on: Sat, 17 October 2020 10:35]

Report message to a moderator

Re: Vector a user defined struct for XML persistency [message #55199 is a reply to message #55197] Sat, 17 October 2020 14:59 Go to previous message
mirek is currently offline  mirek
Messages: 12840
Registered: November 2005
Ultimate Member
Oblivion wrote on Sat, 17 October 2020 10:33
Hello,

You have to mark the struct as Moveable. (Vector requires its elements to be moveable. Array doesn't.)


Actually, I guess the first reply should be "use Array instead of Vector"... Smile

Mirek
Previous Topic: How to construct a struct to get data from this XML?
Next Topic: Looking for examples to split string into container
Goto Forum:
  


Current Time: Wed Oct 28 23:25:14 CET 2020

Total time taken to generate the page: 0.01661 seconds