20 #include "SheafSystem/file_data_type_map.h" 22 #include "SheafSystem/assert_contract.h" 23 #include "SheafSystem/data_converter.h" 24 #include "SheafSystem/namespace_relative_member_index.h" 25 #include "SheafSystem/namespace_relative_subposet_index.h" 26 #include "SheafSystem/primitive_attributes.h" 27 #include "SheafSystem/sheaf_file.h" 51 ensure(is_same_type(result));
74 result = result && data_type_map::invariant();
80 disable_invariant_check();
84 enable_invariant_check();
124 sheaf::file_data_type_map::
125 file_data_type_map(hid_t xfile,
bool xcreate_ext_types)
136 hid_t linternal_hdf_types[PRIMITIVE_TYPE_END];
137 create_internal_hdf_types(linternal_hdf_types, PRIMITIVE_TYPE_END);
141 hid_t lexternal_hdf_types[PRIMITIVE_TYPE_END];
142 if(xcreate_ext_types)
146 create_external_hdf_types(linternal_hdf_types,
155 open_external_hdf_types(lexternal_hdf_types, PRIMITIVE_TYPE_END);
160 _max_internal_size = 0;
161 _max_external_size = 0;
163 for(
int i=PRIMITIVE_TYPE_BEGIN; i<PRIMITIVE_TYPE_END; i++)
166 new data_converter(lexternal_hdf_types[i], linternal_hdf_types[i], i);
168 size_t lsize = _converters[i]->internal_size();
169 _max_internal_size = lsize > _max_internal_size ? lsize : _max_internal_size;
171 lsize = _converters[i]->external_size();
172 _max_external_size = lsize > _max_external_size ? lsize : _max_external_size;
178 ensure(max_internal_size() > 0);
179 ensure(max_external_size() > 0);
187 sheaf::file_data_type_map::
216 close_internal_hdf_types();
217 close_external_hdf_types();
221 for(
int i=PRIMITIVE_TYPE_BEGIN; i<PRIMITIVE_TYPE_END; i++)
237 sheaf::file_data_type_map::
359 sheaf::file_data_type_map::
360 create_internal_hdf_types(hid_t* xinternal_hdf_types,
size_t xinternal_hdf_types_ub)
364 require(xinternal_hdf_types != 0);
365 require(xinternal_hdf_types_ub >= PRIMITIVE_TYPE_END);
371 for(
int i=PRIMITIVE_TYPE_BEGIN; i<PRIMITIVE_TYPE_END; i++)
376 hid_t lhdf_id, lmbr_type;
382 lhdf_id = H5Tcopy(H5T_C_S1);
385 post_fatal_error_message(
"Unable to copy H5T_C_S1 datatype.");
388 lstatus = H5Tset_size(lhdf_id, H5T_VARIABLE);
391 post_fatal_error_message(
"Unable to set char_ptr datatype padding.");
394 xinternal_hdf_types[C_STRING] = lhdf_id;
417 lhdf_id = H5Tcreate (H5T_COMPOUND,
sizeof(nrmi_type));
420 post_fatal_error_message(
"unable to create internal HDF type");
425 lstatus = H5Tinsert (lhdf_id,
"poset_id", HOFFSET(nrmi_type, poset_id), lmbr_type);
428 post_fatal_error_message(
"unable to insert member in compound data type");
431 lstatus = H5Tinsert (lhdf_id,
"member_id", HOFFSET(nrmi_type, member_id), lmbr_type);
434 post_fatal_error_message(
"unable to insert member in compound data type");
437 xinternal_hdf_types[NAMESPACE_RELATIVE_MEMBER_INDEX] = lhdf_id;
443 lhdf_id = H5Tcreate (H5T_COMPOUND,
sizeof(nrsi_type));
446 post_fatal_error_message(
"unable to create internal HDF type");
451 lstatus = H5Tinsert (lhdf_id,
"poset_id", HOFFSET(nrsi_type, poset_id), lmbr_type);
454 post_fatal_error_message(
"unable to insert member in compound data type");
457 lstatus = H5Tinsert (lhdf_id,
"subposet_id", HOFFSET(nrsi_type, subposet_id), lmbr_type);
460 post_fatal_error_message(
"unable to insert member in compound data type");
463 xinternal_hdf_types[NAMESPACE_RELATIVE_SUBPOSET_INDEX] = lhdf_id;
475 sheaf::file_data_type_map::
476 close_internal_hdf_types()
480 require(unexecutable(
"converters are valid."));
486 static const int lcloseable_internal_types[3] =
489 NAMESPACE_RELATIVE_MEMBER_INDEX,
490 NAMESPACE_RELATIVE_SUBPOSET_INDEX
493 for(
int i= 0; i<3; i++)
497 if(H5Tclose(
_converters[lcloseable_internal_types[i]]->internal_type()) < 0)
501 post_fatal_error_message(
"Unable to close internal HDF datatype.");
515 sheaf::file_data_type_map::
516 create_external_hdf_types(
const hid_t* xinternal_hdf_types,
517 size_t xinternal_hdf_types_ub,
518 hid_t* xexternal_hdf_types,
519 size_t xexternal_hdf_types_ub)
523 require(xinternal_hdf_types != 0);
524 require(xinternal_hdf_types_ub >= PRIMITIVE_TYPE_END);
525 require(xexternal_hdf_types != 0);
526 require(xexternal_hdf_types_ub >= PRIMITIVE_TYPE_END);
530 for(
int i=PRIMITIVE_TYPE_BEGIN; i<PRIMITIVE_TYPE_END; i++)
534 hid_t lhdf_id = H5Tcopy(xinternal_hdf_types[i]);
537 post_fatal_error_message(
"can't create external type");
544 herr_t lstatus = H5Tcommit1(
_file, lhdf_name.c_str(), lhdf_id);
547 post_fatal_error_message(
"can't commit external data type to file");
550 xexternal_hdf_types[i] = lhdf_id;
562 sheaf::file_data_type_map::
563 open_external_hdf_types(hid_t* xexternal_hdf_types,
size_t xexternal_hdf_types_ub)
567 require(xexternal_hdf_types != 0);
568 require(xexternal_hdf_types_ub >= PRIMITIVE_TYPE_END);
574 for(
int i=PRIMITIVE_TYPE_BEGIN; i<PRIMITIVE_TYPE_END; i++)
580 lhdf_id = H5Topen1(
_file, lhdf_name.c_str());
583 post_fatal_error_message(
"external type doesn't exist");
586 xexternal_hdf_types[i] = lhdf_id;
599 sheaf::file_data_type_map::
600 close_external_hdf_types()
604 require(unexecutable(
"converters are valid."));
608 for(
int i=PRIMITIVE_TYPE_BEGIN; i<PRIMITIVE_TYPE_END; i++)
616 post_fatal_error_message(
"can't close external type");
hid_t _file
The hdf file handle.
A collection of data converters that map data types between internal and external representations ass...
static const std::string & hdf_type_name(pod_index_type xid)
The name in the hdf file of primitive type with id xid.
virtual file_data_type_map * clone() const
Virtual constructor; makes a new instance of the same type as this.
Abstract base class with useful features for all objects.
int hdf_type() const
The hdf type of the primitive type associated with this.
POD type associated with namespace_relative_subposet_index.
POD type for namespace_relative_member_index.
virtual ~file_data_type_map()
Destructor.
static const primitive_attributes & prototype(pod_index_type xid)
The prototype for the primitive value of the type associated with xid.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
Function object to convert between internal and external data formats.
data_converter * _converters[PRIMITIVE_TYPE_END]
Table of converters, one for each type defined in the file.
A collection of data converters that map data types between internal and external representations...
virtual bool invariant() const
Class invariant.
const std::string & hdf_type_name() const
The name in the hdf file of the primitive type associated with this.