I am working on the codebase of a simulation program. At the moment output of simulation timeseries data is in text form. This is unwieldy, and I would like to write the data to HDF5 instead so that I can read and process the data using Python.
So far, my experience with C++ has been restricted to understanding existing code and making revisions, so I would like some feedback on how I might implement my HDF5 writer.
My idea is to wrap the C API of HDF5 in a class so that the main executable code doesn't need to have knowledge of the HDF5 datatypes and details. I have some idea of what functions the class would need, like create_group, write_attribute_str, write_attribute_int, write_buffered, close_group, close_file, etc.
What I'm unsure about is that there are already three output classes for three different styles of text output, differing in how much data is generated. The three classes all print data to a std::ostream. Would I have to create three additional output classes that interface with the HDF5 writer class?
Within the executable, things currently look like
1 2 3 4 5 6 7 8 9 10 11 12 13
|
// build output class
switch (simOut)
{
case OUT_E:
output = new OutEnergy(...);
break;
case OUT_ALL:
output = new OutAll(...);
break;
case OUT_S:
output = new OutStruct(...);
break;
}
|
And I'm thinking to change things to...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
bool outHDF; // whether to output in HDF
if (outHDF)
HDF5Writer writer(...);
...
// build output class:
switch (simOut)
{
case OUT_E:
if (outHDF)
output = new OutEnergyHDF(writer, ...);
else
output = new OutEnergy(...);
break;
case OUT_ALL:
if (outHDF)
output = new OutAllHDF(writer, ...);
else
output = new OutAll(...);
break;
case OUT_S:
if (outHDF)
output = new OutStructHDF(writer, ...);
else
output = new OutStruct(...);
break;
}
|
It just feels inelegant with all these if statements and now three pairs of output classes. Am I going in the right direction?