22 #include "SheafSystem/data_converter.h" 24 #include "SheafSystem/assert_contract.h" 25 #include "SheafSystem/error_message.h" 26 #include "SheafSystem/primitive_attributes.h" 27 #include "SheafSystem/sheaf_file.h" 28 #include "SheafSystem/std_cstring.h" 29 #include "SheafSystem/std_iostream.h" 77 delete []
static_cast<char*
>(_result);
84 H5Pclose(_transfer_plist);
125 result = result && (_result != 0);
168 sheaf::data_converter::
169 data_converter(hid_t xexternal_type,
170 hid_t xinternal_type,
180 _external_type = xexternal_type;
181 _external_size = H5Tget_size(_external_type);
185 _internal_type = xinternal_type;
186 _internal_index = xinternal_index;
187 _internal_size = H5Tget_size(_internal_type);
194 post_fatal_error_message(
"fatal conflict between HDF internal type and sheaf primitive type");
197 _internal_alignment = lprim_desc.alignment;
202 _result =
new char[_result_size];
206 _transfer_plist = H5Pcreate(H5P_DATASET_XFER);
207 if(_transfer_plist < 0)
209 post_fatal_error_message(
"Unable to create transfer property list.");
214 htri_t ltri = H5Tequal(_internal_type, _external_type);
219 _conversion_required =
false;
225 _conversion_required =
true;
231 post_fatal_error_message(
"error while checking for type equality");
251 require(xitem_ct > 0);
252 require(xint_buf != 0);
254 require(xext_buf != 0);
263 char** lint_buf =
reinterpret_cast<char**
>(
const_cast<void*
>(xint_buf));
264 char* lext_buf =
reinterpret_cast<char*
>(xext_buf);
266 for(
int i=0; i<xitem_ct; i++)
275 (void) memcpy(lext_buf, lint_buf[i], lstrlen);
289 (void) memcpy(xext_buf, xint_buf, xitem_ct*_internal_size);
309 require(xitem_ct > 0);
310 require(xext_buf != 0);
311 require(xext_buf_ub >= xitem_ct*
max_size());
321 herr_t lerr = H5Tconvert(_internal_type, _external_type, xitem_ct, xext_buf, 0, _transfer_plist);
340 require(xint_buf != 0);
350 (void) memcpy(_result, xint_buf, _internal_size);
356 herr_t lerr = H5Tconvert(_internal_type, _external_type, 1, _result, 0, _transfer_plist);
383 result = strlen(xbuf)+1;
411 char** lbuf =
reinterpret_cast<char**
>(
const_cast<void*
>(xbuf));
415 for(
int i=0; i<xitem_ct; i++)
440 require(xitem_ct > 0);
441 require(xext_buf != 0);
443 require(xint_buf != 0);
469 char* lext_buf =
reinterpret_cast<char*
>(
const_cast<void*
>(xext_buf));
470 char** lint_buf =
reinterpret_cast<char**
>(xint_buf);
472 for(
int i=0; i<xitem_ct; i++)
482 char* lstring =
new char[lstrlen];
488 (void) strncpy(lstring, lext_buf, lstrlen);
493 lint_buf[i] = lstring;
506 (void) memcpy(xint_buf, xext_buf, xitem_ct*_external_size);
527 require(xitem_ct > 0);
529 require(xbuf_ub >= xitem_ct*
max_size());
539 herr_t lerr = H5Tconvert(_external_type, _internal_type, xitem_ct, xbuf, 0, _transfer_plist);
568 (void) memcpy(_result, xbuf, _external_size);
574 herr_t lerr = H5Tconvert(_external_type, _internal_type, 1, _result, 0, _transfer_plist);
591 sheaf::data_converter::
611 sheaf::data_converter::
631 _result =
new char[_result_size];
633 _transfer_plist = H5Pcreate(H5P_DATASET_XFER);
637 htri_t ltri = H5Tequal(_internal_type, _external_type);
642 _conversion_required =
false;
648 _conversion_required =
true;
654 post_fatal_error_message(
"error while checking for type equality");
virtual bool invariant() const
Class invariant, intended to be redefined in each descendant. See below for template for invariant in...
bool external_size_greater() const
True if the external size is greater than the internal size.
virtual data_converter * clone() const
Virtual constructor; makes a new instance of the same type as this.
hid_t external_type() const
The external type identifier.
static primitive_descriptor descriptor(pod_index_type xid)
Primitive descriptor for the primitive type with id xid.
size_t internal_size() const
The size in bytes of the internal type.
void externalize(const void *xint_buf, size_t xint_buf_ub, void *xext_buf, size_t xext_buf_ub, int xitem_ct)
Copy xitem_ct data items from xint_buf to xext_buf and then convert them from internal to external fo...
bool is_string_type() const
True if this is a converter for a string type.
bool conversion_required() const
True if internal and external types are not identical.
size_t internal_alignment() const
The alignment of the internal type.
void internalize(const void *xext_buf, size_t xext_buf_ub, void *xint_buf, size_t xint_buf_ub, int xitem_ct)
Convert xitem_ct data items in xext_buf from external to internal format and place the result in xint...
Abstract base class with useful features for all objects.
hid_t internal_index() const
The primitives poset member index for the internal type.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
virtual bool invariant() const
Class invariant.
size_t result_size() const
The allocated size of the result buffer.
virtual ~data_converter()
Destructor.
size_t string_length_total(const void *xbuf, int xitem_ct) const
The total number of characters, including the terminators in all the strings in the array of strings ...
SHEAF_DLL_SPEC bool is_primitive_index(pod_index_type xindex)
True if xindex is a valid primitive index.
void disable_invariant_check() const
Disable invariant check. Intended for preventing recursive calls to invariant and for suppressing inv...
size_t external_size() const
The size in bytes of the external type.
bool invariant_check() const
True if invariant checking is enabled.
bool internal_size_greater() const
True if the internal size is greater than the external size.
Function object to convert between internal and external data formats.
size_t max_size() const
The maximum of internal_size() and external_size().
hid_t internal_type() const
The HDF type identifier for the internal type.
static size_t string_length(const char *xbuf)
The number of characters in the string, including the terminator.
void * result() const
The result of the conversion.
bool is_same_type(const any *other) const
True if other is the same type as this.
void enable_invariant_check() const
Enable invariant checking.