diff options
Diffstat (limited to 'c++')
-rw-r--r-- | c++/src/H5File.cpp | 12 | ||||
-rw-r--r-- | c++/src/H5File.h | 3 | ||||
-rw-r--r-- | c++/src/H5IdComponent.cpp | 39 | ||||
-rw-r--r-- | c++/src/H5IdComponent.h | 3 | ||||
-rw-r--r-- | c++/src/H5Object.cpp | 14 | ||||
-rw-r--r-- | c++/src/H5Object.h | 3 |
6 files changed, 74 insertions, 0 deletions
diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp index e3c98ff..3962fc3 100644 --- a/c++/src/H5File.cpp +++ b/c++/src/H5File.cpp @@ -401,6 +401,18 @@ void H5File::getVFDHandle(void **file_handle) const } //-------------------------------------------------------------------------- +// Function: H5File::getFileName +///\brief Gets the name of this file. +///\return File name +///\exception H5::IdComponentException +// Programmer Binh-Minh Ribler - Jul, 2004 +//-------------------------------------------------------------------------- +string H5File::getFileName() const +{ + return(p_get_file_name()); +} + +//-------------------------------------------------------------------------- // Function: H5File::Reference ///\brief Creates a reference to an Hdf5 object or a dataset region. ///\param name - IN: Name of the object to be referenced diff --git a/c++/src/H5File.h b/c++/src/H5File.h index 900681e..2e0eeec 100644 --- a/c++/src/H5File.h +++ b/c++/src/H5File.h @@ -59,6 +59,9 @@ class H5_DLLCPP H5File : public IdComponent, public CommonFG { static bool isHdf5(const string& name ); static bool isHdf5(const char* name ); + // Gets the name of this file. + string getFileName() const; + // Creates a reference to a named Hdf5 object in this object. void* Reference(const char* name) const; diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp index ee83acc..e8b85c0 100644 --- a/c++/src/H5IdComponent.cpp +++ b/c++/src/H5IdComponent.cpp @@ -173,6 +173,45 @@ void IdComponent::reset () } //-------------------------------------------------------------------------- +// Function: IdComponent::p_get_file_name +// Purpose: Gets the name of the file, in which this object belongs. +// Exception: H5::IdComponentException +// Description: +// This function is protected so that the user applications can +// only have access to its code via allowable classes, namely, +// H5File and H5Object subclasses. +// Programmer Binh-Minh Ribler - Jul, 2004 +//-------------------------------------------------------------------------- +string IdComponent::p_get_file_name() const +{ + // Preliminary call to H5Fget_name to get the length of the file name + ssize_t name_size = H5Fget_name(id, NULL, 0); + + // If H5Aget_name returns a negative value, raise an exception, + if( name_size < 0 ) + { + throw IdComponentException("IdComponent::p_get_file_name", + "H5Fget_name failed"); + } + + // Call H5Fget_name again to get the actual file name + char* name_C = new char[name_size+1]; // temporary C-string for C API + name_size = H5Fget_name(id, name_C, name_size+1); + + // Check for failure again + if( name_size < 0 ) + { + throw IdComponentException("IdComponent::p_get_file_name", + "H5Fget_name failed"); + } + + // Convert the C file name and return + string file_name(name_C); + delete name_C; + return(file_name); +} + +//-------------------------------------------------------------------------- // Function: IdComponent destructor ///\brief Noop destructor. // Programmer Binh-Minh Ribler - 2000 diff --git a/c++/src/H5IdComponent.h b/c++/src/H5IdComponent.h index fedca0e..73305ef 100644 --- a/c++/src/H5IdComponent.h +++ b/c++/src/H5IdComponent.h @@ -72,6 +72,9 @@ class H5_DLLCPP IdComponent { // Default constructor IdComponent(); + // Gets the name of the file, in which an HDF5 object belongs. + std::string p_get_file_name() const; + // Gets the id of the H5 file in which the given object is located. hid_t p_get_file_id(); diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index e3dc2bb..76d9b6c 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -21,6 +21,8 @@ #include "H5Idtemplates.h" #include "H5PropList.h" #include "H5Object.h" +#include "H5DcreatProp.h" +#include "H5CommonFG.h" #include "H5DataType.h" #include "H5DataSpace.h" #include "H5AbstractDs.h" @@ -287,6 +289,18 @@ void H5Object::flush(H5F_scope_t scope ) const } //-------------------------------------------------------------------------- +// Function: H5Object::getFileName +///\brief Gets the name of the file, in which this HDF5 object belongs. +///\return File name +///\exception H5::IdComponentException +// Programmer Binh-Minh Ribler - Jul, 2004 +//-------------------------------------------------------------------------- +string H5Object::getFileName() const +{ + return(p_get_file_name()); +} + +//-------------------------------------------------------------------------- // Function: H5Object destructor ///\brief Noop destructor. // Programmer Binh-Minh Ribler - 2000 diff --git a/c++/src/H5Object.h b/c++/src/H5Object.h index 10d6d61..1ba8929 100644 --- a/c++/src/H5Object.h +++ b/c++/src/H5Object.h @@ -74,6 +74,9 @@ class H5_DLLCPP H5Object : public IdComponent { void removeAttr( const char* name ) const; void removeAttr( const string& name ) const; + // Gets the name of the file, in which this HDF5 object belongs. + string getFileName() const; + // Noop destructor virtual ~H5Object(); |