|
1 | 1 | /* Copyright (c) 2018 vargaconsulting, Toronto,ON Canada
|
2 | 2 | * Author: Varga, Steven <[email protected]>
|
3 | 3 | */
|
4 |
| -#ifndef H5CPP_GUARD_GsMKR |
5 |
| -#define H5CPP_GUARD_GsMKR |
| 4 | +#ifndef H5CPP_GUARD_AKMLr |
| 5 | +#define H5CPP_GUARD_AKMLr |
| 6 | + |
| 7 | +namespace h5{ |
| 8 | + //template specialization of sn::example::Record to create HDF5 COMPOUND type |
| 9 | + template<> hid_t inline register_struct<sn::example::Record>(){ |
| 10 | + hsize_t at_00_[] ={7}; hid_t at_00 = H5Tarray_create(H5T_NATIVE_FLOAT,1,at_00_); |
| 11 | + hsize_t at_01_[] ={3}; hid_t at_01 = H5Tarray_create(H5T_NATIVE_DOUBLE,1,at_01_); |
| 12 | + |
| 13 | + hid_t ct_00 = H5Tcreate(H5T_COMPOUND, sizeof (sn::typecheck::Record)); |
| 14 | + H5Tinsert(ct_00, "_char", HOFFSET(sn::typecheck::Record,_char),H5T_NATIVE_CHAR); |
| 15 | + H5Tinsert(ct_00, "_uchar", HOFFSET(sn::typecheck::Record,_uchar),H5T_NATIVE_UCHAR); |
| 16 | + H5Tinsert(ct_00, "_short", HOFFSET(sn::typecheck::Record,_short),H5T_NATIVE_SHORT); |
| 17 | + H5Tinsert(ct_00, "_ushort", HOFFSET(sn::typecheck::Record,_ushort),H5T_NATIVE_USHORT); |
| 18 | + H5Tinsert(ct_00, "_int", HOFFSET(sn::typecheck::Record,_int),H5T_NATIVE_INT); |
| 19 | + H5Tinsert(ct_00, "_uint", HOFFSET(sn::typecheck::Record,_uint),H5T_NATIVE_UINT); |
| 20 | + H5Tinsert(ct_00, "_long", HOFFSET(sn::typecheck::Record,_long),H5T_NATIVE_LONG); |
| 21 | + H5Tinsert(ct_00, "_ulong", HOFFSET(sn::typecheck::Record,_ulong),H5T_NATIVE_ULONG); |
| 22 | + H5Tinsert(ct_00, "_llong", HOFFSET(sn::typecheck::Record,_llong),H5T_NATIVE_LLONG); |
| 23 | + H5Tinsert(ct_00, "_ullong", HOFFSET(sn::typecheck::Record,_ullong),H5T_NATIVE_ULLONG); |
| 24 | + H5Tinsert(ct_00, "_float", HOFFSET(sn::typecheck::Record,_float),H5T_NATIVE_FLOAT); |
| 25 | + H5Tinsert(ct_00, "_double", HOFFSET(sn::typecheck::Record,_double),H5T_NATIVE_DOUBLE); |
| 26 | + H5Tinsert(ct_00, "_ldouble", HOFFSET(sn::typecheck::Record,_ldouble),H5T_NATIVE_LDOUBLE); |
| 27 | + H5Tinsert(ct_00, "_bool", HOFFSET(sn::typecheck::Record,_bool),H5T_NATIVE_HBOOL); |
| 28 | + hsize_t at_02_[] ={4}; hid_t at_02 = H5Tarray_create(ct_00,1,at_02_); |
| 29 | + |
| 30 | + hid_t ct_01 = H5Tcreate(H5T_COMPOUND, sizeof (sn::other::Record)); |
| 31 | + H5Tinsert(ct_01, "idx", HOFFSET(sn::other::Record,idx),H5T_NATIVE_ULLONG); |
| 32 | + H5Tinsert(ct_01, "aa", HOFFSET(sn::other::Record,aa),H5T_NATIVE_ULLONG); |
| 33 | + H5Tinsert(ct_01, "field_02", HOFFSET(sn::other::Record,field_02),at_01); |
| 34 | + H5Tinsert(ct_01, "field_03", HOFFSET(sn::other::Record,field_03),at_02); |
| 35 | + hsize_t at_03_[] ={5}; hid_t at_03 = H5Tarray_create(ct_01,1,at_03_); |
| 36 | + hsize_t at_04_[] ={8}; hid_t at_04 = H5Tarray_create(ct_01,1,at_04_); |
| 37 | + hsize_t at_05_[] ={3}; hid_t at_05 = H5Tarray_create(at_04,1,at_05_); |
| 38 | + |
| 39 | + hid_t ct_02 = H5Tcreate(H5T_COMPOUND, sizeof (sn::example::Record)); |
| 40 | + H5Tinsert(ct_02, "idx", HOFFSET(sn::example::Record,idx),H5T_NATIVE_ULLONG); |
| 41 | + H5Tinsert(ct_02, "field_02", HOFFSET(sn::example::Record,field_02),at_00); |
| 42 | + H5Tinsert(ct_02, "field_03", HOFFSET(sn::example::Record,field_03),at_03); |
| 43 | + H5Tinsert(ct_02, "field_04", HOFFSET(sn::example::Record,field_04),at_03); |
| 44 | + H5Tinsert(ct_02, "field_05", HOFFSET(sn::example::Record,field_05),at_05); |
| 45 | + |
| 46 | + //closing all hid_t allocations to prevent resource leakage |
| 47 | + H5Tclose(at_00); H5Tclose(at_01); H5Tclose(ct_00); H5Tclose(at_02); H5Tclose(ct_01); |
| 48 | + H5Tclose(at_03); H5Tclose(at_04); H5Tclose(at_05); |
| 49 | + |
| 50 | + //if not used with h5cpp framework, but as a standalone code generator then |
| 51 | + //the returned 'hid_t ct_02' must be closed: H5Tclose(ct_02); |
| 52 | + return ct_02; |
| 53 | + }; |
| 54 | +} |
| 55 | +H5CPP_REGISTER_STRUCT(sn::example::Record); |
6 | 56 |
|
7 | 57 | #endif
|
0 commit comments