CSV format with C library supporting multiple tables & rdquo; And "named references


I have some data to feed to a C/C++ program and I could easily convert it in CSV format. However I would need a couple of extensions to the CSV standard, or the parts I know about it.

Data are heterogeneous, there are different parameters of different sizes. They could be 1-valued, vectors or multidimensional arrays. My ideal format would be like this one

--+ Size1
--+ Size2

"--+" is some sort of separator. I have two 1-valued parameters named symbolically Size1 and Size2 and two other multidimensional parameters Table1 and Table2. In this case the dimensions of Table1 and Table2 are given by the other two parameters. Also rows and columns could be named, i.e. there could be a table like


Where element ("A","X") is 1 and ("B","X") is 2 and so forth.

In other terms it's like a series of appended CSV files with names for tables, rows and columns.

The parsers should be able to exploit the structure of the file allowing me to write code like this:

parse(my_parser,"Size1",&foo->S1); // read Size1 value and write it in &foo.S1
parse(my_parser,"Size2",&foo->S2); // read Size2 value and write it in &foo.S2
parse(my_parser,"Table2",foo->T2); // read Table2

If it was able to store rows and columns name it would be a bonus.

I don't think it would take much to write such a library, but I have more important things to do ATM.

Is there an already defined format like this one? With open-source libraries for C++? Do you have other suggestions for my problem?

Thanks in advance.


I would use JSON, which boost will readily handle. A scalar is a simple case of an array [ 2 ]

The array is easy [ 1, 2]

Multidimensional [ [1,2,3,4], [5,6,7,8] ]

It's been a while since I've done this sort of thing, so I'm not sure how the code will break down for you. Definitely by expanding on this you could add row/column names. The code will be very nice, perhaps not quite as brainless as in python, but it should be simple.

Here's a link for the JSON format: http://json.org Here's a stackoverflow link for reading JSON with boost: Reading json file with boost