I have a vector of c++ structs, and I need to put this into a managed, typed dataset.
std::vector<Record*> record_collection;
class Record{
public:
Record(){};
virtual ~Record(){};
virtual void serialize(std::ostream& dest){
dest << "Record" << std::endl;
}
};
Record* is a base class - I need to handle the derived class. A typical example is
class TestRecord:public Record{
public:
TestRecord(){};
~TestRecord(){};
std::string t_str;
int t_int;
double t_double;
void serialize(std::ostream& dest){
dest << t_int << ',' << t_double << ',' << t_str << ',' << std::endl;
};
};
Essentially, I need to reproduce the serialize method, except that I need to make DataColumns for t_str
, t_int
, and t_double
, type the columns appropriately, and then put the values in them.
I can edit anything as required at this point, but I need to set up the pattern such that anything that implements record can have its data members can be serialized into a managed dataset with typed columns.
Can anyone advise on a pattern, or a suggestion, that would help? I could do it with inspection on a tuple if this were Python, but in c++11 a tuple needs to be of predefined type.
The problem here is that I may not compile record or TestRecord with /cli, in which case I could pass in the datatable to the record and let it populate it itself - so I'm looking for a better solution than the ones I have:
a) Write a managed wrapper for every derived class b) Do type inspection.
Is there a pattern I've missed?
Thanks, Melanie