summaryrefslogtreecommitdiffstats
path: root/c++
diff options
context:
space:
mode:
Diffstat (limited to 'c++')
-rw-r--r--c++/src/H5File.cpp19
-rw-r--r--c++/src/H5File.h7
-rw-r--r--c++/src/H5IdComponent.cpp66
-rw-r--r--c++/src/H5IdComponent.h6
-rw-r--r--c++/src/H5PropList.cpp2
-rw-r--r--c++/test/tfile.cpp105
6 files changed, 174 insertions, 31 deletions
diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp
index fcf4e1c..cd97025 100644
--- a/c++/src/H5File.cpp
+++ b/c++/src/H5File.cpp
@@ -352,6 +352,25 @@ FileAccPropList H5File::getAccessPlist() const
}
//--------------------------------------------------------------------------
+// Function: H5File::getFileInfo
+///\brief Retrieves the general information of this file.
+///
+///\exception H5::FileIException
+///\par Description
+/// The retrieved information may include information about
+/// superblock extension, free space management, and shared object
+// Programmer Binh-Minh Ribler - February 2017
+//--------------------------------------------------------------------------
+void H5File::getFileInfo(H5F_info2_t& file_info) const
+{
+ herr_t ret_value = H5Fget_info2(id, &file_info);
+ if (ret_value < 0)
+ {
+ throw FileIException("H5File::getFileInfo", "H5Fget_info2 failed");
+ }
+}
+
+//--------------------------------------------------------------------------
// Function: H5File::getFreeSpace
///\brief Returns the amount of free space in the file.
///\return Amount of free space
diff --git a/c++/src/H5File.h b/c++/src/H5File.h
index dca6c67..495b4d0 100644
--- a/c++/src/H5File.h
+++ b/c++/src/H5File.h
@@ -51,8 +51,8 @@ class H5_DLLCPP H5File : public Group {
// Gets the creation property list of this file.
FileCreatPropList getCreatePlist() const;
- // Retrieves the file size of an opened file.
- hsize_t getFileSize() const;
+ // Gets general information about this file.
+ void getFileInfo(H5F_info2_t& file_info) const;
// Returns the amount of free space in the file.
hssize_t getFreeSpace() const;
@@ -70,6 +70,9 @@ class H5_DLLCPP H5File : public Group {
void getVFDHandle(const FileAccPropList& fapl, void **file_handle) const;
//void getVFDHandle(FileAccPropList& fapl, void **file_handle) const; // removed from 1.8.18 and 1.10.1
+ // Returns the file size of the HDF5 file.
+ hsize_t getFileSize() const;
+
// Determines if a file, specified by its name, is in HDF5 format
static bool isHdf5(const char* name );
static bool isHdf5(const H5std_string& name );
diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp
index f3d916a..ae60c5e 100644
--- a/c++/src/H5IdComponent.cpp
+++ b/c++/src/H5IdComponent.cpp
@@ -162,6 +162,72 @@ H5I_type_t IdComponent::getHDFObjType() const
}
//--------------------------------------------------------------------------
+// Function: getNumMembers (static)
+///\brief Returns the number of members of the given type.
+///\return Number of members
+///\Description
+/// If there is no member of the given type, getNumMembers will
+/// return 0. Valid types are:
+/// \li \c H5I_FILE (= 1)
+/// \li \c H5I_GROUP
+/// \li \c H5I_DATATYPE
+/// \li \c H5I_DATASPACE
+/// \li \c H5I_DATASET
+/// \li \c H5I_ATTR
+/// \li \c H5I_REFERENCE
+/// \li \c H5I_VFL
+/// \li \c H5I_GENPROP_CLS
+/// \li \c H5I_GENPROP_LST
+/// \li \c H5I_ERROR_CLASS
+/// \li \c H5I_ERROR_MSG
+/// \li \c H5I_ERROR_STACK
+// Programmer Binh-Minh Ribler - Feb, 2017
+//--------------------------------------------------------------------------
+hsize_t IdComponent::getNumMembers(H5I_type_t type)
+{
+ hsize_t nmembers = 0;
+ herr_t ret_value = H5Inmembers(type, &nmembers);
+ if (ret_value < 0)
+ throw IdComponentException("getNumMembers", "H5Inmembers failed");
+ else
+ return(nmembers);
+}
+
+//--------------------------------------------------------------------------
+// Function: typeExists (static)
+///\brief Queries if a given type is currently registered with the
+/// library.
+///\return true if the given type exists, and false, otherwise.
+///\Description
+/// Valid types are:
+/// \li \c H5I_FILE (= 1)
+/// \li \c H5I_GROUP
+/// \li \c H5I_DATATYPE
+/// \li \c H5I_DATASPACE
+/// \li \c H5I_DATASET
+/// \li \c H5I_ATTR
+/// \li \c H5I_REFERENCE
+/// \li \c H5I_VFL
+/// \li \c H5I_GENPROP_CLS
+/// \li \c H5I_GENPROP_LST
+/// \li \c H5I_ERROR_CLASS
+/// \li \c H5I_ERROR_MSG
+/// \li \c H5I_ERROR_STACK
+// Programmer Binh-Minh Ribler - Feb, 2017
+//--------------------------------------------------------------------------
+bool IdComponent::typeExists(H5I_type_t type)
+{
+ // Call C function
+ htri_t ret_value = H5Itype_exists(type);
+ if (ret_value > 0)
+ return true;
+ else if (ret_value == 0)
+ return false;
+ else // Raise exception when H5Itype_exists returns a negative value
+ throw IdComponentException("typeExists", "H5Itype_exists failed");
+}
+
+//--------------------------------------------------------------------------
// Function: IdComponent::operator=
///\brief Assignment operator.
///\param rhs - IN: Reference to the existing object
diff --git a/c++/src/H5IdComponent.h b/c++/src/H5IdComponent.h
index d3d9b9f..70522dc 100644
--- a/c++/src/H5IdComponent.h
+++ b/c++/src/H5IdComponent.h
@@ -48,6 +48,12 @@ class H5_DLLCPP IdComponent {
// Returns an HDF5 object type of this object.
H5I_type_t getHDFObjType() const;
+ // Returns the number of members in a type.
+ static hsize_t getNumMembers(H5I_type_t type);
+
+ // Determines if an type exists.
+ static bool typeExists(H5I_type_t type);
+
// Assignment operator.
IdComponent& operator=( const IdComponent& rhs );
diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp
index f0eb847..1564a93 100644
--- a/c++/src/H5PropList.cpp
+++ b/c++/src/H5PropList.cpp
@@ -347,7 +347,7 @@ hid_t PropList::getClass() const
//--------------------------------------------------------------------------
// Function: PropList::propExist
-///\brief Query the existance of a property in a property object.
+///\brief Queries the existence of a property in a property object.
///\param name - IN: Name of property to check for - \c char pointer
///\return true if the property exists in the property object, and
/// false, otherwise.
diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp
index 920e3a7..934d6e6 100644
--- a/c++/test/tfile.cpp
+++ b/c++/test/tfile.cpp
@@ -49,6 +49,7 @@ const size_t F2_OFFSET_SIZE = 8;
const size_t F2_LENGTH_SIZE = 8;
const unsigned F2_SYM_LEAF_K = 8;
const unsigned F2_SYM_INTERN_K = 32;
+const unsigned F2_ISTORE = 64;
const H5std_string FILE2("tfile2.h5");
const hsize_t F3_USERBLOCK_SIZE = (hsize_t)0;
@@ -505,7 +506,6 @@ static void test_file_name()
{
issue_fail_msg("test_file_name()", __LINE__, __FILE__, E.getCDetailMsg());
}
-
} // test_file_name()
@@ -514,8 +514,8 @@ const int ATTR1_DIM1 = 3;
const H5std_string FILE5("tfattrs.h5");
const H5std_string FATTR1_NAME ("file attribute 1");
const H5std_string FATTR2_NAME ("file attribute 2");
-int fattr_data[ATTR1_DIM1]={512,-234,98123}; /* Test data for file attribute */
-int dattr_data[ATTR1_DIM1]={256,-123,1000}; /* Test data for dataset attribute */
+int fattr_data[ATTR1_DIM1]={512,-234,98123}; // Test data for file attribute
+int dattr_data[ATTR1_DIM1]={256,-123,1000}; // Test data for dataset attribute
static void test_file_attribute()
{
@@ -618,6 +618,7 @@ static void test_file_attribute()
issue_fail_msg("test_file_attribute()", __LINE__, __FILE__, E.getCDetailMsg());
}
} // test_file_attribute()
+
const H5std_string FILE6("tfile5.h5");
const H5std_string ROOTGROUP("/");
@@ -796,11 +797,13 @@ static void test_commonfg()
} /* end test_commonfg() */
const H5std_string FILE7("tfile7.h5");
+
/*-------------------------------------------------------------------------
- * Function: test_filespace_info
+ * Function: test_file_info
*
- * Purpose: Verify that setting and retrieving the file space strategy
- * and free space section threshold work correctly.
+ * Purpose: Verify that various properties in a file creation property
+ * lists are stored correctly in the file and can be retrieved
+ * when the file is re-opened.
*
* Return: None
*
@@ -809,12 +812,11 @@ const H5std_string FILE7("tfile7.h5");
*
*-------------------------------------------------------------------------
*/
-static void test_filespace_info()
+static void test_file_info()
{
// Output message about test being performed
- SUBTEST("File space information");
+ SUBTEST("File general information");
- hid_t fapl_id = h5_fileaccess(); // in h5test.c, returns a file access template
hsize_t in_threshold = 2; // Free space section threshold to set */
hsize_t out_threshold = 0; // Free space section threshold to get */
// File space handling strategy
@@ -823,29 +825,82 @@ static void test_filespace_info()
H5F_file_space_type_t out_strategy = H5F_FILE_SPACE_DEFAULT;
try {
- // Use the file access template id to create a file access prop.
- // list object to pass in H5File::H5File
- FileAccPropList fapl(fapl_id);
+ // Create a file using default properties.
+ H5File tempfile(FILE7, H5F_ACC_TRUNC);
+
+ // Get the file's version information.
+ H5F_info2_t finfo;
+ tempfile.getFileInfo(finfo);
+ verify_val(finfo.super.version, 0, "H5File::getFileInfo", __LINE__, __FILE__);
+ verify_val(finfo.free.version, 0, "H5File::getFileInfo", __LINE__, __FILE__);
+ verify_val(finfo.sohm.version, 0, "H5File::getFileInfo", __LINE__, __FILE__);
+
+ // Close the file.
+ tempfile.close();
- /* Create file-creation proplist */
+ // Create file creation property list.
FileCreatPropList fcpl;
- /* Set file space strategy and free space section threshold */
+ // Set various file information.
+ fcpl.setUserblock(F2_USERBLOCK_SIZE);
+ fcpl.setSizes(F2_OFFSET_SIZE, F2_LENGTH_SIZE);
+ fcpl.setSymk(F2_SYM_INTERN_K, F2_SYM_LEAF_K);
+ fcpl.setIstorek(F2_ISTORE);
fcpl.setFileSpace(in_strategy, in_threshold);
- // Create a file using default properties.
+ // Creating a file with the non-default file creation property list
+ // should create a version 1 superblock
+
+ // Create file with custom file creation property list.
H5File file7(FILE7, H5F_ACC_TRUNC, fcpl);
- /* Close the file */
+ // Close the file creation property list.
+ fcpl.close();
+
+ // Get the file's version information.
+ file7.getFileInfo(finfo);
+ verify_val(finfo.super.version, 2, "H5File::getFileInfo", __LINE__, __FILE__);
+ verify_val(finfo.free.version, 0, "H5File::getFileInfo", __LINE__, __FILE__);
+ verify_val(finfo.sohm.version, 0, "H5File::getFileInfo", __LINE__, __FILE__);
+
+ // Close the file.
file7.close();
- /* Re-open the file */
- file7.openFile(FILE7, H5F_ACC_RDWR, fapl);
+ // Re-open the file.
+ file7.openFile(FILE7, H5F_ACC_RDONLY);
- /* Get the file's creation property */
+ // Get the file's creation property list.
FileCreatPropList fcpl2 = file7.getCreatePlist();
- /* Get and verify the file space info from the creation property list */
+ // Get the file's version information.
+ file7.getFileInfo(finfo);
+ verify_val(finfo.super.version, 2, "H5File::getFileInfo", __LINE__, __FILE__);
+ verify_val(finfo.free.version, 0, "H5File::getFileInfo", __LINE__, __FILE__);
+ verify_val(finfo.sohm.version, 0, "H5File::getFileInfo", __LINE__, __FILE__);
+
+ // Retrieve the property values & check them.
+ hsize_t userblock = fcpl2.getUserblock();
+ verify_val(userblock, F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__);
+
+ size_t off_size = 0, len_size = 0;
+ fcpl2.getSizes(off_size, len_size);
+ verify_val(off_size, F2_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__);
+ verify_val(len_size, F2_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__);
+
+ unsigned sym_ik = 0, sym_lk = 0;
+ fcpl2.getSymk(sym_ik, sym_lk);
+ verify_val(sym_ik, F2_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__);
+ verify_val(sym_lk, F2_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__);
+
+ unsigned istore_ik = fcpl2.getIstorek();
+ verify_val(istore_ik, F2_ISTORE, "FileCreatPropList::getIstorek", __LINE__, __FILE__);
+
+ /* ret=H5Pget_shared_mesg_nindexes(fcpl2,&nindexes);
+ CHECK(ret, FAIL, "H5Pget_shared_mesg_nindexes");
+ VERIFY(nindexes, MISC11_NINDEXES, "H5Pget_shared_mesg_nindexes");
+ */
+
+ // Get and verify the file space info from the creation property list */
out_strategy = fcpl2.getFileSpaceStrategy();
verify_val(static_cast<unsigned>(out_strategy), static_cast<unsigned>(in_strategy), "FileCreatPropList::getFileSpaceStrategy", __LINE__, __FILE__);
@@ -854,17 +909,11 @@ static void test_filespace_info()
PASSED();
} // end of try block
-
catch (Exception& E)
{
issue_fail_msg("test_filespace_info()", __LINE__, __FILE__, E.getCDetailMsg());
}
- // Close file access template.
- herr_t ret = H5Pclose(fapl_id);
- if (ret < 0)
- issue_fail_msg("test_filespace_info()", __LINE__, __FILE__, "H5Pclose failed");
-
-} /* test_filespace_info() */
+} /* test_file_info() */
/*-------------------------------------------------------------------------
* Function: test_file
@@ -893,7 +942,7 @@ void test_file()
test_file_attribute(); // Test file attribute feature
test_libver_bounds(); // Test format version
test_commonfg(); // Test H5File as a root group
- test_filespace_info(); // Test file space info
+ test_file_info(); // Test various file info
} // test_file()