void *
ss_array_get(ss_array_t *array, /* Array from which to retrieve data. */
hid_t mtype, /* Datatype for memory. Pass ss_pers_tm (or preferably negative) for an array
* of persistent object links. */
size_t offset, /* First element to be returned. It is an error to specify a starting element
* that is outside the valid range of values defined for the array. */
size_t nelmts, /* Number of elements to return. The OFFSET and NELMTS define a range of
* elements to be returned. If the range extends beyond the end of the defined
* range of elements for ARRAY then an error is raised; but if NELMTS is the
* constant SS_NOSIZE then all elements up to and including the last element
* are returned. */
void *buffer /* The optional caller-supplied buffer to be filled in by the request. If the
* caller didn't supply a buffer then one will be created. */
)
{
SS_ENTER(ss_array_get, ss_pers_tP);
size_t mtype_size; /* Size of each array element in memory. */
if (!array) SS_ERROR_FMT(USAGE, ("no ss_array_t supplied"));
/* Check requested range of values against those currently defined for the array */
if (offset>array->nelmts)
SS_ERROR_FMT(DOMAIN, ("starting offset %lu but array has only %lu elements",
(unsigned long)offset, (unsigned long)(array->nelmts)));
if (SS_NOSIZE==nelmts) {
nelmts = array->nelmts - offset;
} else if (offset+nelmts>array->nelmts) {
SS_ERROR_FMT(DOMAIN, ("requested elements %lu through %lu but array has only %lu elements",
(unsigned long)offset, (unsigned long)(offset+nelmts-1), (unsigned long)(array->nelmts)));
}
if (0==nelmts) {
if (!buffer && NULL==(buffer=malloc(1))) SS_ERROR(RESOURCE);
goto done;
}
/* Make sure data has been converted to memory format. */
if (ss_array_cache(array, mtype)<0) SS_ERROR(FAILED);
/* Copy data into return value */
if (0==(mtype_size=H5Tget_size(mtype>0?mtype:ss_pers_tm))) SS_ERROR(HDF5);
if (!buffer && NULL==(buffer=malloc(nelmts*mtype_size))) SS_ERROR(RESOURCE);
memcpy(buffer, (char*)(array->mbuf)+offset*mtype_size, nelmts*mtype_size);
done:
SS_CLEANUP:
SS_LEAVE(buffer);
}