summaryrefslogtreecommitdiffstats
path: root/c++/src
diff options
context:
space:
mode:
Diffstat (limited to 'c++/src')
-rw-r--r--c++/src/H5AbstractDs.cpp3
-rw-r--r--c++/src/H5ArrayType.cpp123
-rw-r--r--c++/src/H5ArrayType.h3
-rw-r--r--c++/src/H5CompType.cpp11
-rw-r--r--c++/src/H5Library.cpp4
-rw-r--r--c++/src/Makefile.in11
6 files changed, 97 insertions, 58 deletions
diff --git a/c++/src/H5AbstractDs.cpp b/c++/src/H5AbstractDs.cpp
index 06b3e22..4e9a4d5 100644
--- a/c++/src/H5AbstractDs.cpp
+++ b/c++/src/H5AbstractDs.cpp
@@ -141,8 +141,11 @@ ArrayType AbstractDs::getArrayType() const
// depending on which object invokes getArrayType. Then, create and
// return the ArrayType object
try {
+ // Create ArrayType and set values this way to work around the
+ // problem described in the JIRA issue HDFFV-7947
ArrayType arraytype;
f_DataType_setId(&arraytype, p_get_type());
+ arraytype.setArrayInfo();
return(arraytype);
}
catch (DataSetIException E) {
diff --git a/c++/src/H5ArrayType.cpp b/c++/src/H5ArrayType.cpp
index 85340f8..0f09631 100644
--- a/c++/src/H5ArrayType.cpp
+++ b/c++/src/H5ArrayType.cpp
@@ -35,12 +35,7 @@ namespace H5 {
///\brief Default constructor: Creates a stub ArrayType
// Programmer Binh-Minh Ribler - May 2004
//--------------------------------------------------------------------------
-ArrayType::ArrayType() : DataType()
-{
- // Initialize members
- rank = -1;
- dimensions = NULL;
-}
+ArrayType::ArrayType() : DataType(), rank(-1), dimensions(NULL) {}
//--------------------------------------------------------------------------
// Function: ArrayType overloaded constructor
@@ -51,20 +46,7 @@ ArrayType::ArrayType() : DataType()
//--------------------------------------------------------------------------
ArrayType::ArrayType( const hid_t existing_id ) : DataType( existing_id )
{
- // Get the rank of the existing array and store it in this array
- rank = H5Tget_array_ndims(existing_id);
- if (rank < 0)
- {
- throw DataTypeIException("ArrayType constructor (existing id)", "H5Tget_array_ndims 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");
+ setArrayInfo();
}
//--------------------------------------------------------------------------
@@ -111,25 +93,67 @@ ArrayType::ArrayType(const DataType& base_type, int ndims, const hsize_t* dims)
}
//--------------------------------------------------------------------------
+// Function: ArrayType::setArrayInfo
+///\brief Retrieves the rank and dimensions from the array datatype
+/// and store the info in this ArrayType object.
+///\exception H5::DataTypeIException
+// Programmer Binh-Minh Ribler - January 2016
+//--------------------------------------------------------------------------
+void ArrayType::setArrayInfo()
+{
+ // Get the rank of the array type specified by id from the C API
+ int ndims = H5Tget_array_ndims(id);
+ if (ndims < 0)
+ {
+ throw DataTypeIException("ArrayType::setArrayInfo", "H5Tget_array_ndims failed");
+ }
+
+ // Get the dimensions from the C API
+ hsize_t* dims;
+ dims = new hsize_t[ndims];
+ if (dims != NULL)
+ {
+ // Get the dimensions
+ ndims = H5Tget_array_dims2(id, dims);
+ if (ndims < 0)
+ throw DataTypeIException("ArrayType::setArrayInfo", "H5Tget_array_dims2 failed");
+
+ // 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];
+ delete []dims;
+ }
+} // setArrayInfo
+
+//--------------------------------------------------------------------------
// Function: ArrayType::getArrayNDims
///\brief Returns the number of dimensions for an array datatype.
///\return Number of dimensions
///\exception H5::DataTypeIException
// Programmer Binh-Minh Ribler - May 2004
+// Modification
+// Modified to use setArrayInfo().
+// If rank is positive, return rank
+// If rank is invalid but object has a valid identifier, obtain the
+// rank and dimensions, store them in the object, and return rank
+// Otherwise, i.e., rank is invalid and object doesn't have a
+// valid identifier, throw an exception
//--------------------------------------------------------------------------
int ArrayType::getArrayNDims()
{
- // If the array's rank has not been stored, i.e. rank is init to -1,
- // retrieve it via the C API
- if (rank < 0)
- {
- rank = H5Tget_array_ndims(id);
- if (rank < 0)
- {
- throw DataTypeIException("ArrayType::getArrayNDims", "H5Tget_array_ndims failed");
- }
- }
- return(rank);
+ // Validate the id first, this object could be a default object
+ if (!p_valid_id(id))
+ throw DataTypeIException("ArrayType::getArrayNDims", "ArrayType object is not a valid array type.");
+
+ // If the array's info has not been stored, i.e. "rank" still has its
+ // initial value, -1, and "dimensions" is still NULL, retrieve rank and
+ // dimensions via the C API and store them in this ArrayType object.
+ if (rank < 0 && dimensions == NULL)
+ setArrayInfo();
+
+ return(rank);
}
//--------------------------------------------------------------------------
@@ -139,25 +163,30 @@ int ArrayType::getArrayNDims()
///\return Number of dimensions
///\exception H5::DataTypeIException
// Programmer Binh-Minh Ribler - May 2004
+// Modification
+// Jan, 2016
+// Modified to use setArrayInfo().
+// If the array information has not been stored, retrieve rank and
+// dimensions of the array type identified by "id" via the C API.
+// Copy "dimensions" to the user's buffer
//--------------------------------------------------------------------------
int ArrayType::getArrayDims(hsize_t* dims)
{
- // 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
- 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'
- for (int i = 0; i < rank; i++)
- dims[i] = dimensions[i];
- return(rank);
+ // Validate the id first, this object could be a default object
+ if (!p_valid_id(id))
+ throw DataTypeIException("ArrayType::getArrayDims", "ArrayType object is not a valid array type.");
+
+ // If the array's info has not been stored, i.e. "rank" still has its
+ // initial value, -1, and "dimensions" is still NULL, retrieve rank and
+ // dimensions via the C API and store them in this ArrayType object.
+ if (rank < 0 && dimensions == NULL)
+ setArrayInfo();
+
+ // Copy what's in "dimensions" to user's buffer "dims"
+ for (int i = 0; i < rank; i++)
+ dims[i] = dimensions[i];
+
+ return(rank);
}
//--------------------------------------------------------------------------
diff --git a/c++/src/H5ArrayType.h b/c++/src/H5ArrayType.h
index 6577a6e..c0f4b38 100644
--- a/c++/src/H5ArrayType.h
+++ b/c++/src/H5ArrayType.h
@@ -31,6 +31,9 @@ class H5_DLLCPP ArrayType : public DataType {
// specified base type.
ArrayType(const DataType& base_type, int ndims, const hsize_t* dims);
+ // Stores the rank and dimensions in memory.
+ void setArrayInfo();
+
// Returns the number of dimensions of this array datatype.
int getArrayNDims();
diff --git a/c++/src/H5CompType.cpp b/c++/src/H5CompType.cpp
index 6d31a68..82575d6 100644
--- a/c++/src/H5CompType.cpp
+++ b/c++/src/H5CompType.cpp
@@ -228,12 +228,12 @@ hid_t CompType::p_get_member_type(unsigned member_num) const
DataType CompType::getMemberDataType( unsigned member_num ) const
{
try {
- DataType datatype;
+ DataType datatype;
f_DataType_setId(&datatype, p_get_member_type(member_num));
- return(datatype);
+ return(datatype);
}
catch (DataTypeIException E) {
- throw DataTypeIException("CompType::getMemberDataType", E.getDetailMsg());
+ throw DataTypeIException("CompType::getMemberDataType", E.getDetailMsg());
}
}
@@ -249,9 +249,10 @@ DataType CompType::getMemberDataType( unsigned member_num ) const
ArrayType CompType::getMemberArrayType( unsigned member_num ) const
{
try {
- ArrayType arraytype(p_get_member_type(member_num));
+ ArrayType arraytype;
f_DataType_setId(&arraytype, p_get_member_type(member_num));
- return(arraytype);
+ arraytype.setArrayInfo();
+ return(arraytype);
}
catch (DataTypeIException E) {
throw DataTypeIException("CompType::getMemberArrayType", E.getDetailMsg());
diff --git a/c++/src/H5Library.cpp b/c++/src/H5Library.cpp
index 40c766a..be80fe4 100644
--- a/c++/src/H5Library.cpp
+++ b/c++/src/H5Library.cpp
@@ -262,10 +262,10 @@ void H5Library::setFreeListLimits(int reg_global_lim, int reg_list_lim,
}
// Default constructor - private
-H5Library::H5Library(){};
+H5Library::H5Library(){}
// Destructor - private
-H5Library::~H5Library(){};
+H5Library::~H5Library(){}
#ifndef H5_NO_NAMESPACE
} // end namespace
diff --git a/c++/src/Makefile.in b/c++/src/Makefile.in
index 82509d1..cec89c0 100644
--- a/c++/src/Makefile.in
+++ b/c++/src/Makefile.in
@@ -431,16 +431,17 @@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
AM_FCFLAGS = @AM_FCFLAGS@ @H5_FCFLAGS@
AM_LDFLAGS = @AM_LDFLAGS@ @H5_LDFLAGS@
AR = @AR@
+ASSERTS = @ASSERTS@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
+BUILD_MODE = @BUILD_MODE@
BYTESEX = @BYTESEX@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CC_VERSION = @CC_VERSION@
CFLAGS = @CFLAGS@
-CLEARFILEBUF = @CLEARFILEBUF@
CODESTACK = @CODESTACK@
CONFIG_DATE = @CONFIG_DATE@
CONFIG_MODE = @CONFIG_MODE@
@@ -453,7 +454,6 @@ CXXDEPMODE = @CXXDEPMODE@
CXXFLAGS = @CXXFLAGS@
CXX_VERSION = @CXX_VERSION@
CYGPATH_W = @CYGPATH_W@
-DEBUG_PKG = @DEBUG_PKG@
DEFAULT_API_VERSION = @DEFAULT_API_VERSION@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
@@ -515,8 +515,8 @@ INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
-INSTRUMENT = @INSTRUMENT@
INSTRUMENT_LIBRARY = @INSTRUMENT_LIBRARY@
+INTERNAL_DEBUG_OUTPUT = @INTERNAL_DEBUG_OUTPUT@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
@@ -527,11 +527,11 @@ LL_PATH = @LL_PATH@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
LT_STATIC_EXEC = @LT_STATIC_EXEC@
-LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MEMORYALLOCSANITYCHECK = @MEMORYALLOCSANITYCHECK@
+METADATATRACEFILE = @METADATATRACEFILE@
MKDIR_P = @MKDIR_P@
MPE = @MPE@
NM = @NM@
@@ -539,6 +539,7 @@ NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJECT_NAMELEN_DEFAULT_F = @OBJECT_NAMELEN_DEFAULT_F@
OBJEXT = @OBJEXT@
+OPTIMIZATION = @OPTIMIZATION@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
@@ -562,6 +563,7 @@ PAC_FORTRAN_NATIVE_REAL_KIND = @PAC_FORTRAN_NATIVE_REAL_KIND@
PAC_FORTRAN_NATIVE_REAL_SIZEOF = @PAC_FORTRAN_NATIVE_REAL_SIZEOF@
PARALLEL = @PARALLEL@
PATH_SEPARATOR = @PATH_SEPARATOR@
+PROFILING = @PROFILING@
RANLIB = @RANLIB@
ROOT = @ROOT@
RUNPARALLEL = @RUNPARALLEL@
@@ -577,6 +579,7 @@ STATIC_EXEC = @STATIC_EXEC@
STATIC_SHARED = @STATIC_SHARED@
STRICT_FORMAT_CHECKS = @STRICT_FORMAT_CHECKS@
STRIP = @STRIP@
+SYMBOLS = @SYMBOLS@
TESTPARALLEL = @TESTPARALLEL@
THREADSAFE = @THREADSAFE@
TIME = @TIME@