diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2014-10-02 04:05:38 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2014-10-02 04:05:38 (GMT) |
commit | 9c9326c7debc3b4f32602ec21cc67cfccafa6fc0 (patch) | |
tree | 5860b1568bae4fb51cd4051191e48a729e368cbc /c++/src/H5ArrayType.cpp | |
parent | 40c17513405c1056c90b7324a954df2a217efd65 (diff) | |
download | hdf5-9c9326c7debc3b4f32602ec21cc67cfccafa6fc0.zip hdf5-9c9326c7debc3b4f32602ec21cc67cfccafa6fc0.tar.gz hdf5-9c9326c7debc3b4f32602ec21cc67cfccafa6fc0.tar.bz2 |
[svn-r25653] Purpose: Fixed HDFFV-4259
Description:
- Used H5I_INVALID_HID instead of 0 to initialized member "id" in classes
that represent HDF5 objects. For PropList, H5P_DEFAULT has to be used
instead of H5I_INVALID_HID.
- Added try/catch block to some dynamically allocating memory code and
re-throw the bad_alloc exception with a message informing the location of
the failure.
(merged from trunk-r25640)
Purpose: Fixed HDFFV-8852
Description:
H5F_ACC_CREAT was included in the C++ API while the C library doesn't
allow it yet. Possibly, in the future, but not now. In addition, the
two flags H5F_ACC_RDONLY and H5F_ACC_RDWR were missing from the
documentation, causing confusion that appending is not supported.
Solution:
- Removed H5F_ACC_CREAT from the function until the C library support it
- Added H5F_ACC_RDONLY and H5F_ACC_RDWR to the comments to update the
documentation
(merged from trunk-r25632)
Platforms tested:
Linux/ppc64 (ostrich)
Linux/32 2.6 (jam)
SunOS 5.11 (emu)
Diffstat (limited to 'c++/src/H5ArrayType.cpp')
-rw-r--r-- | c++/src/H5ArrayType.cpp | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/c++/src/H5ArrayType.cpp b/c++/src/H5ArrayType.cpp index 852658b..8807dca 100644 --- a/c++/src/H5ArrayType.cpp +++ b/c++/src/H5ArrayType.cpp @@ -54,15 +54,16 @@ ArrayType::ArrayType( const hid_t existing_id ) : DataType( existing_id ) rank = H5Tget_array_ndims(existing_id); if (rank < 0) { - throw DataTypeIException("ArrayType overloaded constructor", "H5Tget_array_ndims failed"); + throw DataTypeIException("ArrayType constructor (existing id)", "H5Tget_array_ndims failed"); } - // Get the dimensions of the existing array and store it in this array - dimensions = new hsize_t[rank]; - //hsize_t rdims2[H5S_MAX_RANK]; - int ret_value = H5Tget_array_dims2(id, dimensions); - if (ret_value < 0) - throw DataTypeIException("ArrayType::getArrayDims", "H5Tget_array_dims2 failed"); + // Allocate space for the dimensions + dimensions = new hsize_t[rank]; + + // Get the dimensions of the existing array and store it in this array + int ret_value = H5Tget_array_dims2(id, dimensions); + if (ret_value < 0) + throw DataTypeIException("ArrayType constructor (existing id)", "H5Tget_array_dims2 failed"); } //-------------------------------------------------------------------------- @@ -72,10 +73,13 @@ ArrayType::ArrayType( const hid_t existing_id ) : DataType( existing_id ) //-------------------------------------------------------------------------- ArrayType::ArrayType( const ArrayType& original ) : DataType( original ) { - rank = original.rank; - dimensions = new hsize_t[rank]; - for (int i = 0; i < rank; i++) - dimensions[i] = original.dimensions[i]; + // Copy the rank of the original array + rank = original.rank; + + // Allocate space then copy the dimensions from the original array + dimensions = new hsize_t[rank]; + for (int i = 0; i < rank; i++) + dimensions[i] = original.dimensions[i]; } //-------------------------------------------------------------------------- @@ -90,14 +94,19 @@ ArrayType::ArrayType( const ArrayType& original ) : DataType( original ) //-------------------------------------------------------------------------- ArrayType::ArrayType(const DataType& base_type, int ndims, const hsize_t* dims) : DataType() { - hid_t new_type_id = H5Tarray_create2(base_type.getId(), ndims, dims); - if (new_type_id < 0) - throw DataTypeIException("ArrayType constructor", "H5Tarray_create2 failed"); - id = new_type_id; - rank = ndims; - dimensions = new hsize_t[rank]; - for (int i = 0; i < rank; i++) - dimensions[i] = dims[i]; + // Call C API to create an array data type + hid_t new_type_id = H5Tarray_create2(base_type.getId(), ndims, dims); + if (new_type_id < 0) + throw DataTypeIException("ArrayType constructor", "H5Tarray_create2 failed"); + + // Set the id and rank for this object + id = new_type_id; + rank = ndims; + + // Allocate space then set the dimensions as provided by caller + dimensions = new hsize_t[rank]; + for (int i = 0; i < rank; i++) + dimensions[i] = dims[i]; } //-------------------------------------------------------------------------- @@ -132,19 +141,19 @@ int ArrayType::getArrayNDims() //-------------------------------------------------------------------------- int ArrayType::getArrayDims(hsize_t* dims) { - // if the array's dimensions have not been stored, retrieve them via C API + // If the array's dimensions have not been stored, retrieve them via C API if (dimensions == NULL) { int ndims = H5Tget_array_dims2(id, dims); if (ndims < 0) throw DataTypeIException("ArrayType::getArrayDims", "H5Tget_array_dims2 failed"); - // store the array's info in memory + // Store the array's info in memory rank = ndims; dimensions = new hsize_t[rank]; for (int i = 0; i < rank; i++) dimensions[i] = dims[i]; } - // otherwise, simply copy what's in 'dimensions' to 'dims' + // Otherwise, simply copy what's in 'dimensions' to 'dims' for (int i = 0; i < rank; i++) dims[i] = dimensions[i]; return(rank); |