Home » U++ Library support » U++ Core » S_type and ValueMap
Re: S_type and ValueMap [message #52518 is a reply to message #52517] |
Tue, 15 October 2019 12:00 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
Giorgio wrote on Tue, 15 October 2019 11:40Hi there,
I have the following code: the idea is to get data from db, put them in a vector of ValueMap and then put them in a S_type structure.
std::vector<ValueMap> * results=this->dao->QueryTable(table, vmfields); //ValueMap(s) here represent lines from db
for(auto it = results->begin(); it != results->end(); ++it)
S_FILLER s(*it); //S_FILLER is defined in a .sch file
//Do something with s
}
S_FILLER is defined as follows:
TABLE_ (FILLER)
STRING (KMP,8) PRIMARY_KEY REFERENCES(ITEM.KMP)
STRING_ (DESCRIPTION,50)
STRING (STATUS,8)
INT_ (NOELEMENTS)
DOUBLE_ (DENSITY)
END_TABLE
The problem is that the code crashes if in the S_type structure there are numerical types, if they are just strings the code runs perfectly.
Is there a way to force some kind of "automatic" conversion from String to the correct type?
Thanks,
gio
No. I believe that would be dangerous.
I think you can do this by using S_type introspection and doing the conversion yourself. E.g. use GetRef to get a reference to column attribute, then you can use 'Is' to check for its type. Create a template function to do the conversion to accomodate various S_tables.
Mirek
|
|
|
Goto Forum:
Current Time: Sat May 04 00:12:41 CEST 2024
Total time taken to generate the page: 0.03016 seconds
|