Fixed support for automatic type saving in HDF5

This commit is contained in:
Guilhem Lavaux 2015-01-31 15:47:44 +01:00
parent 84e841814a
commit 44756de2a9
2 changed files with 40 additions and 8 deletions

View file

@ -38,10 +38,24 @@ knowledge of the CeCILL license and that you accept its terms.
using namespace std;
struct MyStruct
{
int a;
double b;
char c;
};
CTOOL_STRUCT_TYPE(MyStruct, hdf5t_MyStruct,
((int, a))
((double, b))
((char, c))
)
int main()
{
typedef boost::multi_array<float, 2> array_type;
typedef boost::multi_array<float, 3> array3_type;
typedef boost::multi_array<MyStruct, 1> array_mys_type;
typedef boost::multi_array<std::complex<double>, 2> arrayc_type;
typedef array_type::index index;
@ -53,13 +67,23 @@ int main()
array_type B;
array3_type C(boost::extents[2][3][4]);
arrayc_type D, E;
array_mys_type F(boost::extents[10]), G;
int values = 0;
for (index i = 0; i != 2; i++)
for (index j = 0; j != 3; j++)
A[i][j] = values++;
for (index i = 0; i != 10; i++)
{
F[i].a = i;
F[i].b = double(i)/4.;
F[i].c = 'r'+i;
}
std::cout << " c = " << ((char *)&F[1])[offsetof(MyStruct, c)] << endl;
CosmoTool::hdf5_write_array(g, "test_data", A);
CosmoTool::hdf5_write_array(g, "test_struct", F);
CosmoTool::hdf5_read_array(g, "test_data", B);
@ -95,5 +119,12 @@ int main()
abort();
}
CosmoTool::hdf5_read_array(g, "test_struct", G);
for (index i = 0; i != 10; i++)
if (G[i].a != F[i].a || G[i].b != F[i].b || G[i].c != F[i].c) {
std::cout << "Invalid struct content" << endl;
abort();
}
return 0;
}