0

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

Melanie
  • 1,349
  • 2
  • 17
  • 27
  • Is `serialize` `virtual`? How many child classes? Is the number fixed and never changing? Can you change the child classes? Can you change the `Record` class? Give an example concrete interface for `Record`. You say you need to reproduce `serialize` with `DataColumn`s, but you also say you need `Dataset^` -- which do you actually need? – Yakk - Adam Nevraumont Apr 22 '13 at 17:36
  • Good questions. Serialize is virtual, an unknown number of classes inherit record, and for each value of unknown type I need a datacolumn of appropriate type, put together in a dataset. I'll edit the question. – Melanie Apr 22 '13 at 23:34

0 Answers0