diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2004-08-20 04:29:58 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2004-08-20 04:29:58 (GMT) |
commit | 4a04b0c05c608de05c69c33a6dced509d04cde09 (patch) | |
tree | 55484a35e37d81d1128a05c8c004d17a7ac2826a /c++ | |
parent | 226df4069427644a4a53087e8303a5685a07533c (diff) | |
download | hdf5-4a04b0c05c608de05c69c33a6dced509d04cde09.zip hdf5-4a04b0c05c608de05c69c33a6dced509d04cde09.tar.gz hdf5-4a04b0c05c608de05c69c33a6dced509d04cde09.tar.bz2 |
[svn-r9127] Purpose: Adding wrapper for new C API and other updates
Description:
Added wrappers for H5Fget_name:
H5File::getFileName
H5Object::getFileName
Moved some functions from Group into the base class CommonFG for
H5File too.
Platforms tested:
SunOS 5.7 (arabica)
Linux 2.4 (eirene)
Diffstat (limited to 'c++')
-rw-r--r-- | c++/src/H5CommonFG.cpp | 125 | ||||
-rw-r--r-- | c++/src/H5CommonFG.h | 20 | ||||
-rw-r--r-- | c++/src/H5File.cpp | 117 | ||||
-rw-r--r-- | c++/src/H5File.h | 62 | ||||
-rw-r--r-- | c++/src/H5IdComponent.cpp | 84 | ||||
-rw-r--r-- | c++/src/H5IdComponent.h | 66 | ||||
-rw-r--r-- | c++/src/H5Object.cpp | 25 | ||||
-rw-r--r-- | c++/src/H5Object.h | 24 |
8 files changed, 356 insertions, 167 deletions
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp index e3e7616..05da7bd 100644 --- a/c++/src/H5CommonFG.cpp +++ b/c++/src/H5CommonFG.cpp @@ -33,7 +33,7 @@ // There are a few comments that are common to most of the functions // defined in this file so they are listed here. -// - getLocId is called by all functions, which call a C API, to get +// - getLocId is called by all functions, that call a C API, to get // the location id, which can be either a file id or a group id. // This function is pure virtual and it's up to H5File and Group // to call the right getId() - although, as the structure of the @@ -555,7 +555,7 @@ hid_t CommonFG::p_open_data_type( const char* name ) const //-------------------------------------------------------------------------- DataType CommonFG::openDataType( const char* name ) const { - DataType data_type( p_open_data_type( name )); + DataType data_type(p_open_data_type(name)); return( data_type ); } @@ -581,8 +581,8 @@ DataType CommonFG::openDataType( const string& name ) const //-------------------------------------------------------------------------- EnumType CommonFG::openEnumType( const char* name ) const { - EnumType enum_type( p_open_data_type( name )); - return( enum_type ); + EnumType enum_type(p_open_data_type(name)); + return(enum_type); } //-------------------------------------------------------------------------- @@ -607,8 +607,8 @@ EnumType CommonFG::openEnumType( const string& name ) const //-------------------------------------------------------------------------- CompType CommonFG::openCompType( const char* name ) const { - CompType comp_type( p_open_data_type( name )); - return( comp_type ); + CompType comp_type(p_open_data_type(name)); + return(comp_type); } //-------------------------------------------------------------------------- @@ -633,8 +633,8 @@ CompType CommonFG::openCompType( const string& name ) const //-------------------------------------------------------------------------- IntType CommonFG::openIntType( const char* name ) const { - IntType int_type( p_open_data_type( name )); - return( int_type ); + IntType int_type(p_open_data_type(name)); + return(int_type); } //-------------------------------------------------------------------------- @@ -659,8 +659,8 @@ IntType CommonFG::openIntType( const string& name ) const //-------------------------------------------------------------------------- FloatType CommonFG::openFloatType( const char* name ) const { - FloatType float_type( p_open_data_type( name )); - return( float_type ); + FloatType float_type(p_open_data_type(name)); + return(float_type); } //-------------------------------------------------------------------------- @@ -685,8 +685,8 @@ FloatType CommonFG::openFloatType( const string& name ) const //-------------------------------------------------------------------------- StrType CommonFG::openStrType( const char* name ) const { - StrType str_type( p_open_data_type( name )); - return( str_type ); + StrType str_type(p_open_data_type(name)); + return(str_type); } //-------------------------------------------------------------------------- @@ -704,9 +704,9 @@ StrType CommonFG::openStrType( const string& name ) const //-------------------------------------------------------------------------- // Function: CommonFG::iterateElems ///\brief Iterates a user's function over the entries of a group. -///\param name - IN: Name of group to iterate over -///\param idx - IN/OUT: Starting (IN) and ending (OUT) entry indices -///\param op - IN: User's function to operate on each entry +///\param name - IN : Name of group to iterate over +///\param idx - IN/OUT: Starting (IN) and ending (OUT) entry indices +///\param op - IN : User's function to operate on each entry ///\param op_data - IN/OUT: Data associated with the operation ///\return The return value of the first operator that returns non-zero, /// or zero if all members were processed with no operator @@ -737,6 +737,101 @@ int CommonFG::iterateElems( const string& name, int *idx, H5G_iterate_t op , voi } //-------------------------------------------------------------------------- +// Function: CommonFG::getNumObjs +///\brief Returns the number of objects in this group. +///\return Number of objects +///\exception H5::FileIException or H5::GroupIException +// Programmer Binh-Minh Ribler - January, 2003 +//-------------------------------------------------------------------------- +hsize_t CommonFG::getNumObjs() const +{ + hsize_t num_objs; + herr_t ret_value = H5Gget_num_objs(getLocId(), &num_objs); + if(ret_value < 0) + { + throwException("getNumObjs", "H5Gget_num_objs failed"); + } + return (num_objs); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::getObjnameByIdx +///\brief Retrieves the name of an object in this group, given the +/// object's index. +///\param idx - IN: Transient index of the object +///\param name - IN/OUT: Retrieved name of the object +///\param size - IN: Length to retrieve +///\return Actual size of the object name or 0, if object has no name +///\exception H5::FileIException or H5::GroupIException +///\par Description +/// The value of idx can be any nonnegative number less than the +/// total number of objects in the group, which is returned by +/// the function \c CommonFG::getNumObjs. Note that this is a +/// transient index; thus, an object may have a different index +/// each time the group is opened. +// Programmer Binh-Minh Ribler - January, 2003 +//-------------------------------------------------------------------------- +ssize_t CommonFG::getObjnameByIdx(hsize_t idx, string& name, size_t size) const +{ + char* name_C = new char[size]; + ssize_t name_len = H5Gget_objname_by_idx(getLocId(), idx, name_C, size); + if(name_len < 0) + { + throwException("getObjnameByIdx", "H5Gget_objname_by_idx failed"); + } + name = string( name_C ); + delete [] name_C; + return (name_len); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::getObjTypeByIdx +///\brief Returns the type of an object in this group, given the +/// object's index. +///\param idx - IN: Transient index of the object +///\return Object type +///\exception H5::FileIException or H5::GroupIException +// Programmer Binh-Minh Ribler - January, 2003 +//-------------------------------------------------------------------------- +H5G_obj_t CommonFG::getObjTypeByIdx(hsize_t idx) const +{ + H5G_obj_t obj_type = H5Gget_objtype_by_idx(getLocId(), idx); + if (obj_type == H5G_UNKNOWN) + { + throwException("getObjTypeByIdx", "H5Gget_objtype_by_idx failed"); + } + return (obj_type); +} + +//-------------------------------------------------------------------------- +// Function: CommonFG::getObjTypeByIdx +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function because it also provides +/// the returned object type in text. +///\param idx - IN: Transient index of the object +///\param type_name - IN: Object type in text +///\return Object type +///\exception H5::FileIException or H5::GroupIException +// Programmer Binh-Minh Ribler - January, 2003 +//-------------------------------------------------------------------------- +H5G_obj_t CommonFG::getObjTypeByIdx(hsize_t idx, string& type_name) const +{ + H5G_obj_t obj_type = H5Gget_objtype_by_idx(getLocId(), idx); + switch (obj_type) + { + case H5G_LINK: type_name = string("symbolic link"); break; + case H5G_GROUP: type_name = string("group"); break; + case H5G_DATASET: type_name = string("dataset"); break; + case H5G_TYPE: type_name = string("datatype"); break; + case H5G_UNKNOWN: + default: + { + throwException("getObjTypeByIdx", "H5Gget_objtype_by_idx failed"); + } + } + return (obj_type); +} +//-------------------------------------------------------------------------- // Function: CommonFG default constructor ///\brief Default constructor. // Programmer Binh-Minh Ribler - 2000 diff --git a/c++/src/H5CommonFG.h b/c++/src/H5CommonFG.h index 99ff874..1ede66b 100644 --- a/c++/src/H5CommonFG.h +++ b/c++/src/H5CommonFG.h @@ -28,11 +28,13 @@ class Group; class H5File; class H5_DLLCPP CommonFG { public: - // Creates a new group at this location which can be a file or another group. + // Creates a new group at this location which can be a file + // or another group. Group createGroup(const char* name, size_t size_hint = 0) const; Group createGroup(const string& name, size_t size_hint = 0) const; - // Opens an existing group in a location which can be a file or another group. + // Opens an existing group in a location which can be a file + // or another group. Group openGroup(const char* name) const; Group openGroup(const string& name) const; @@ -44,10 +46,6 @@ class H5_DLLCPP CommonFG { DataSet openDataSet(const char* name) const; DataSet openDataSet(const string& name) const; - // Removes the specified name at this location. - void unlink(const char* name) const; - void unlink(const string& name) const; - // Retrieves comment for the HDF5 object specified by its name. string getComment(const char* name, size_t bufsize) const; string getComment(const string& name, size_t bufsize) const; @@ -87,6 +85,10 @@ class H5_DLLCPP CommonFG { void link(H5G_link_t link_type, const char* curr_name, const char* new_name) const; void link(H5G_link_t link_type, const string& curr_name, const string& new_name) const; + // Removes the specified name at this location. + void unlink(const char* name) const; + void unlink(const string& name) const; + // Mounts the file 'child' onto this location. void mount(const char* name, H5File& child, PropList& plist) const; void mount(const string& name, H5File& child, PropList& plist) const; @@ -123,11 +125,11 @@ class H5_DLLCPP CommonFG { StrType openStrType(const char* name) const; StrType openStrType(const string& name) const; - /// For subclasses, H5File and Group, to return the correct - /// object id, i.e. file or group id. + /// For subclasses, H5File and Group, to return the correct + /// object id, i.e. file or group id. virtual hid_t getLocId() const = 0; - /// For H5File and Group to throw appropriate exception. + /// For subclasses, H5File and Group, to throw appropriate exception. virtual void throwException(const string func_name, const string msg) const = 0; // Default constructor. diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp index bac8499..afc692b 100644 --- a/c++/src/H5File.cpp +++ b/c++/src/H5File.cpp @@ -41,10 +41,8 @@ namespace H5 { #endif //-------------------------------------------------------------------------- -// Function Default constructor -///\brief Default constructor - Creates a stub hdf5 file object. -///\par Description -/// The id of this hdf5 file is set to 0. +// Function H5File default constructor +///\brief Default constructor: creates a stub H5File object. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- H5File::H5File() : IdComponent() {} @@ -52,8 +50,8 @@ H5File::H5File() : IdComponent() {} //-------------------------------------------------------------------------- // Function: H5File overloaded constructor ///\brief Creates or opens an HDF5 file depending on the parameter flags. -///\param name - IN: Name of the file -///\param flags - IN: File access flags +///\param name - IN: Name of the file +///\param flags - IN: File access flags ///\param create_plist - IN: File creation property list, used when /// modifying default file meta-data. Default to /// FileCreatPropList::DEFAULT @@ -76,28 +74,27 @@ H5File::H5File() : IdComponent() {} /// http://hdf.ncsa.uiuc.edu/HDF5/doc/RM_H5F.html#File-Create // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -H5File::H5File( const string& name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : IdComponent() +H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : IdComponent() { - p_get_file( name.c_str(), flags, create_plist, access_plist ); + p_get_file(name, flags, create_plist, access_plist); } //-------------------------------------------------------------------------- // Function: H5File overloaded constructor ///\brief This is another overloaded constructor. It differs from the /// above constructor only in the type of the \a name argument. -///\param name - IN: Name of the file +///\param name - IN: Name of the file - \c std::string ///\param flags - IN: File access flags ///\param create_plist - IN: File creation property list, used when /// modifying default file meta-data. Default to /// FileCreatPropList::DEFAULT ///\param access_plist - IN: File access property list. Default to /// FileCreatPropList::DEFAULT -///\param name - IN: Name of the file - \c std::string // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : IdComponent() +H5File::H5File( const string& name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : IdComponent() { - p_get_file( name, flags, create_plist, access_plist ); + p_get_file(name.c_str(), flags, create_plist, access_plist); } //-------------------------------------------------------------------------- @@ -105,7 +102,7 @@ H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& c // constructors taking a string or a char* // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -void H5File::p_get_file( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) +void H5File::p_get_file(const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist) { // These bits only set for creation, so if any of them are set, // create the file. @@ -133,9 +130,9 @@ void H5File::p_get_file( const char* name, unsigned int flags, const FileCreatPr } //-------------------------------------------------------------------------- -// Function: Copy Constructor -///\brief Copy Constructor: Makes a copy of the original -/// H5File object +// Function: H5File copy constructor +///\brief Copy constructor: makes a copy of the original +/// H5File object. ///\param original - IN: H5File instance to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- @@ -143,7 +140,7 @@ H5File::H5File( const H5File& original ) : IdComponent( original ) {} //-------------------------------------------------------------------------- // Function: H5File::isHdf5 -///\brief Determines whether a file in HDF5 format +///\brief Determines whether a file in HDF5 format. ///\param name - IN: Name of the file ///\return true if the file is in HDF5 format, and false, otherwise ///\exception H5::FileIException @@ -163,11 +160,12 @@ bool H5File::isHdf5(const char* name ) throw FileIException("H5File::isHdf5", "H5Fis_hdf5 returned negative value"); } } + //-------------------------------------------------------------------------- // Function: H5File::isHdf5 ///\brief This is an overloaded member function, provided for convenience. /// It takes an \c std::string for \a name. -///\param name - IN: Name of the file +///\param name - IN: Name of the file - \c std::string // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- bool H5File::isHdf5(const string& name ) @@ -176,15 +174,15 @@ bool H5File::isHdf5(const string& name ) } //-------------------------------------------------------------------------- -// Function: H5File::reopen -///\brief Reopens this file +// Function: H5File::reOpen +///\brief Reopens this file. ///\exception H5::FileIException // Description // If this object has represented another HDF5 file, the previous // HDF5 file need to be closed first. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -void H5File::reopen() +void H5File::reOpen() { // reset the identifier of this H5File - send 'this' in so that // H5Fclose can be called appropriately @@ -192,14 +190,28 @@ void H5File::reopen() decRefCount(); } catch (Exception close_error) { - throw FileIException("H5File::reopen", close_error.getDetailMsg()); + throw FileIException("H5File::reOpen", close_error.getDetailMsg()); } // call C routine to reopen the file - Note: not sure about this // does id need to be closed later? which id to be the parameter? id = H5Freopen( id ); if( id <= 0 ) // Raise exception when H5Freopen returns a neg value - throw FileIException("H5File::reopen", "H5Freopen failed"); + throw FileIException("H5File::reOpen", "H5Freopen failed"); +} + +//-------------------------------------------------------------------------- +// Function: H5File::reopen +///\brief Reopens this file. +///\exception H5::FileIException +///\par Description +/// This function will be replaced by the above function \c reOpen +/// in future releases. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +void H5File::reopen() +{ + H5File::reOpen(); } //-------------------------------------------------------------------------- @@ -397,6 +409,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 @@ -405,8 +429,7 @@ void H5File::getVFDHandle(void **file_handle) const ///\return A reference ///\exception H5::ReferenceIException ///\par Description -/// Note that, for H5File, name must be an absolute path to the -/// object in the file. +/// Note that name must be an absolute path to the object in the file. // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- void* H5File::Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type) const @@ -439,13 +462,13 @@ void* H5File::Reference(const char* name) const //-------------------------------------------------------------------------- // Function: H5File::getObjType ///\brief Retrieves the type of object that an object reference points to. -///\param ref - IN: Reference to query -///\param ref_type - IN: Type of reference to query +///\param ref - IN: Reference to query +///\param ref_type - IN: Type of reference to query ///\return Object type, which can be one of the following: -/// \li \c H5G_LINK Object is a symbolic link. -/// \li \c H5G_GROUP Object is a group. -/// \li \c H5G_DATASET Object is a dataset. -/// \li \c H5G_TYPE Object is a named datatype +/// \li \c H5G_LINK - Object is a symbolic link. +/// \li \c H5G_GROUP - Object is a group. +/// \li \c H5G_DATASET - Object is a dataset. +/// \li \c H5G_TYPE - Object is a named datatype ///\exception H5::ReferenceIException // Programmer Binh-Minh Ribler - May, 2004 //-------------------------------------------------------------------------- @@ -470,23 +493,10 @@ DataSpace H5File::getRegion(void *ref, H5R_type_t ref_type) const } //-------------------------------------------------------------------------- -// Function: H5File::getLocId -// Purpose: Get the id of this file -// Description -// This function is a redefinition of CommonFG::getLocId. It -// is used by CommonFG member functions to get the file id. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -hid_t H5File::getLocId() const -{ - return( getId() ); -} - -//-------------------------------------------------------------------------- // Function: H5File::getFileSize -///\brief Retrieves the file size of the HDF5 file. -///\exception H5::FileIException +///\brief Returns the file size of the HDF5 file. ///\return File size +///\exception H5::FileIException ///\par Description /// This function is called after an existing file is opened in /// order to learn the true size of the underlying file. @@ -500,7 +510,20 @@ hsize_t H5File::getFileSize() const { throw FileIException("H5File::getFileSize", "H5Fget_filesize failed"); } - return(file_size); + return (file_size); +} + +//-------------------------------------------------------------------------- +// Function: H5File::getLocId +// Purpose: Get the id of this file +// Description +// This function is a redefinition of CommonFG::getLocId. It +// is used by CommonFG member functions to get the file id. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +hid_t H5File::getLocId() const +{ + return( getId() ); } //-------------------------------------------------------------------------- diff --git a/c++/src/H5File.h b/c++/src/H5File.h index 3db277d..ddc24d8 100644 --- a/c++/src/H5File.h +++ b/c++/src/H5File.h @@ -22,22 +22,25 @@ namespace H5 { class H5_DLLCPP H5File : public IdComponent, public CommonFG { public: - // Default constructor - H5File(); - - // copy constructor: makes a copy of the original H5File object. - H5File(const H5File& original ); - // Creates or opens an HDF5 file. - H5File( const string& name, unsigned int flags, + H5File( const char* name, unsigned int flags, const FileCreatPropList& create_plist = FileCreatPropList::DEFAULT, const FileAccPropList& access_plist = FileAccPropList::DEFAULT ); - H5File( const char* name, unsigned int flags, + H5File( const string& name, unsigned int flags, const FileCreatPropList& create_plist = FileCreatPropList::DEFAULT, const FileAccPropList& access_plist = FileAccPropList::DEFAULT ); - // Gets the file id - virtual hid_t getLocId() const; + // Gets the access property list of this file. + FileAccPropList getAccessPlist() const; + + // Gets the creation property list of this file. + FileCreatPropList getCreatePlist() const; + + // Gets the name of this file. + string getFileName() const; + + // Retrieves the file size of an opened file. + hsize_t getFileSize() const; // Returns the amount of free space in the file. hssize_t getFreeSpace() const; @@ -51,41 +54,42 @@ class H5_DLLCPP H5File : public IdComponent, public CommonFG { // and datatypes) in the same file. void getObjIDs(unsigned types, int max_objs, hid_t *oid_list) const; + // Retrieves the type of object that an object reference points to. + H5G_obj_t getObjType(void *ref, H5R_type_t ref_type) const; + + // Retrieves a dataspace with the region pointed to selected. + DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const; + // Returns the pointer to the file handle of the low-level file driver. void getVFDHandle(FileAccPropList& fapl, void **file_handle) const; void getVFDHandle(void **file_handle) const; // Determines if a file, specified by its name, is in HDF5 format - static bool isHdf5(const string& name ); static bool isHdf5(const char* name ); + static bool isHdf5(const string& name ); - // Creates a reference to a named Hdf5 object in this object. - void* Reference(const char* name) const; + // Reopens this file. + void reOpen(); // added for better name + void reopen(); // Creates a reference to a named Hdf5 object or to a dataset region // in this object. void* Reference(const char* name, DataSpace& dataspace, H5R_type_t ref_type = H5R_DATASET_REGION) const; - // Retrieves the type of object that an object reference points to. - H5G_obj_t getObjType(void *ref, H5R_type_t ref_type) const; - - // Retrieves a dataspace with the region pointed to selected. - DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const; - - // Retrieves the file size of an opened file. - hsize_t getFileSize() const; + // Creates a reference to a named Hdf5 object in this object. + void* Reference(const char* name) const; - // Reopens this file. - void reopen(); + // Throw file exception. + virtual void throwException(const string func_name, const string msg) const; - // Gets the creation property list of this file. - FileCreatPropList getCreatePlist() const; + // Gets the file id + virtual hid_t getLocId() const; - // Gets the access property list of this file. - FileAccPropList getAccessPlist() const; + // Default constructor + H5File(); - // Throw file exception. - virtual void throwException(const string func_name, const string msg) const; + // Copy constructor: makes a copy of the original H5File object. + H5File(const H5File& original); // H5File destructor. virtual ~H5File(); diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp index 7ccb7ff..4d7841c 100644 --- a/c++/src/H5IdComponent.cpp +++ b/c++/src/H5IdComponent.cpp @@ -24,25 +24,13 @@ namespace H5 { #endif //-------------------------------------------------------------------------- -// Function: IdComponent default constructor - private -///\brief Default constructor. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -IdComponent::IdComponent() : id( -1 ) -{ -} - -//-------------------------------------------------------------------------- // Function: IdComponent overloaded constructor ///\brief Creates an IdComponent object using the id of an existing object. ///\param h5_id - IN: Id of an existing object ///\exception H5::DataTypeIException // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- - -IdComponent::IdComponent( const hid_t h5_id ) : id( h5_id ) -{ -} +IdComponent::IdComponent(const hid_t h5_id) : id(h5_id) {} //-------------------------------------------------------------------------- // Function: IdComponent copy constructor @@ -91,15 +79,16 @@ int IdComponent::getCounter() { return( H5Iget_ref(id)); } ///\exception H5::IdComponentException when attempt to close the HDF5 /// object fails // Description -// Reset the identifier of this object so that the HDF5 id can -// be properly closed. Copy the id from rhs to this object, -// then increment the reference counter of the id to indicate -// that another object is referencing it. +// The underlaying reference counting in the C library ensures +// that the current valid id of this object is properly closed. +// Copy the id from rhs to this object, then increment the +// reference counter of the id to indicate that another object +// is referencing it. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- IdComponent& IdComponent::operator=( const IdComponent& rhs ) { - // reset the identifier of this object, call appropriate H5Xclose + // handling references to this id decRefCount(); // copy the data members from the rhs object @@ -117,17 +106,17 @@ IdComponent& IdComponent::operator=( const IdComponent& rhs ) ///\exception H5::IdComponentException when the attempt to close the HDF5 /// object fails // Description: -// Reset the current id of this object so that the HDF5 -// id can be appropriately closed. If only this object references -// its id, its reference counter will be deleted. A new -// reference counter is created for the new HDF5 object id. +// The underlaying reference counting in the C library ensures +// that the current valid id of this object is properly closed. +// Then the object's id is reset to the new id. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void IdComponent::setId( hid_t new_id ) { - // reset the identifier of this object, call appropriate H5Xclose + // handling references to this id decRefCount(); + // reset object's id to the given id id = new_id; } @@ -177,6 +166,53 @@ IdComponent::~IdComponent() { // Implementation of protected functions for HDF5 Reference Interface. // +#ifndef DOXYGEN_SHOULD_SKIP_THIS +//-------------------------------------------------------------------------- +// Function: IdComponent default constructor - private +///\brief Default constructor. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +IdComponent::IdComponent() : id(-1) {} + +//-------------------------------------------------------------------------- +// 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::p_reference (protected) // Purpose Creates a reference to an HDF5 object or a dataset region. @@ -247,6 +283,8 @@ hid_t IdComponent::p_get_region(void *ref, H5R_type_t ref_type) const return(space_id); } +#endif // DOXYGEN_SHOULD_SKIP_THIS + #ifndef H5_NO_NAMESPACE } #endif diff --git a/c++/src/H5IdComponent.h b/c++/src/H5IdComponent.h index 1f6a7be..45dc2a5 100644 --- a/c++/src/H5IdComponent.h +++ b/c++/src/H5IdComponent.h @@ -16,8 +16,7 @@ #ifndef _IdComponent_H #define _IdComponent_H -// IdComponent provides a mechanism to handle -// reference counting for an identifier of any HDF5 object. +// IdComponent represents an HDF5 object that has an identifier. #ifndef H5_NO_NAMESPACE namespace H5 { @@ -25,54 +24,61 @@ namespace H5 { class H5_DLLCPP IdComponent { public: - // Parent classes must reset the current IdComponent copy - // before setting new id to control reference count - void setId( hid_t new_id ); - - // Creates an object to hold an HDF5 identifier - IdComponent( const hid_t h5_id ); - - // Copy constructor: makes copy of the original IdComponent object. - IdComponent( const IdComponent& original ); - - // Gets the value of IdComponent's data member - virtual hid_t getId () const; - - // Increment reference counter + // Increment reference counter. void incRefCount(); - // Decrement reference counter + // Decrement reference counter. void decRefCount(); - // Get the reference counter to this identifier + // Get the reference counter to this identifier. int getCounter(); - // Assignment operator + // Assignment operator. IdComponent& operator=( const IdComponent& rhs ); void reset(); - void resetId(); + + // Sets the identifier of this object to a new value. + void setId( hid_t new_id ); + + // Creates an object to hold an HDF5 identifier. + IdComponent( const hid_t h5_id ); + + // Copy constructor: makes copy of the original IdComponent object. + IdComponent( const IdComponent& original ); + + // Gets the value of IdComponent's data member. + virtual hid_t getId () const; // Destructor virtual ~IdComponent(); protected: +#ifndef DOXYGEN_SHOULD_SKIP_THIS hid_t id; // HDF5 object id - // Default constructor + // Default constructor. IdComponent(); - // Gets the id of the H5 file in which the given object is located. - hid_t p_get_file_id(); + // Gets the name of the file, in which an HDF5 object belongs. +#ifdef H5_NO_STD + string p_get_file_name() const; +#else + std::string p_get_file_name() const; +#endif // H5_NO_STD + + // Gets the id of the H5 file in which the given object is located. + hid_t p_get_file_id(); + + // Creates a reference to an HDF5 object or a dataset region. + void* p_reference(const char* name, hid_t space_id, H5R_type_t ref_type) const; - // Creates a reference to an HDF5 object or a dataset region. - void* p_reference(const char* name, hid_t space_id, H5R_type_t ref_type) const; - - // Retrieves the type of object that an object reference points to. - H5G_obj_t p_get_obj_type(void *ref, H5R_type_t ref_type) const; + // Retrieves the type of object that an object reference points to. + H5G_obj_t p_get_obj_type(void *ref, H5R_type_t ref_type) const; - // Retrieves a dataspace with the region pointed to selected. - hid_t p_get_region(void *ref, H5R_type_t ref_type) const; + // Retrieves a dataspace with the region pointed to selected. + hid_t p_get_region(void *ref, H5R_type_t ref_type) const; +#endif // DOXYGEN_SHOULD_SKIP_THIS }; // end class IdComponent diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index 127c315..9c8f5f4 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -30,6 +30,7 @@ namespace H5 { #endif +#ifndef DOXYGEN_SHOULD_SKIP_THIS // userAttrOpWrpr simply interfaces between the user's function and the // C library function H5Aiterate; used to resolve the different prototype // problem. May be moved to Iterator later. @@ -48,21 +49,23 @@ extern "C" herr_t userAttrOpWrpr( hid_t loc_id, const char* attr_name, void* op_ //-------------------------------------------------------------------------- // Function: H5Object default constructor (protected) // Description -// The id is set to 0 here but subclass constructor will set -// it to a valid HDF5 id. +// The id is set by IdComponent() but subclass constructor will +// set it to a valid HDF5 id. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- H5Object::H5Object() : IdComponent() {} //-------------------------------------------------------------------------- // Function: H5Object overloaded constructor (protected) -// Purpose Creates an H5Object object using the id of an existing H5 +// Purpose Creates an H5Object object using the id of an existing HDF5 // object. -// Parameters object_id - IN: Id of an existing H5 object +// Parameters object_id - IN: Id of an existing HDF5 object // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- H5Object::H5Object( const hid_t object_id ) : IdComponent( object_id ) {} +#endif // DOXYGEN_SHOULD_SKIP_THIS + //-------------------------------------------------------------------------- // Function: H5Object copy constructor ///\brief Copy constructor: makes a copy of the original H5Object @@ -220,7 +223,7 @@ int H5Object::iterateAttrs( attr_operator_t user_op, unsigned * idx, void *op_da //-------------------------------------------------------------------------- // Function: H5Object::getNumAttrs -///\brief Returns the number of attributes attached to this H5 object. +///\brief Returns the number of attributes attached to this HDF5 object. ///\return Number of attributes ///\exception H5::AttributeIException // Programmer Binh-Minh Ribler - 2000 @@ -287,6 +290,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 d527250..fdc6c76 100644 --- a/c++/src/H5Object.h +++ b/c++/src/H5Object.h @@ -27,6 +27,7 @@ namespace H5 { #endif +#ifndef DOXYGEN_SHOULD_SKIP_THIS class H5_DLLCPP H5Object; // forward declaration for UserData4Aiterate // Define the operator function pointer for H5Aiterate(). @@ -41,17 +42,12 @@ class UserData4Aiterate { // user data for attribute iteration void* opData; H5Object* object; }; +#endif // DOXYGEN_SHOULD_SKIP_THIS // The above part is being moved into Iterator, but not completed class H5_DLLCPP H5Object : public IdComponent { public: - // Copy constructor: makes copy of an H5Object object. - H5Object( const H5Object& original ); - - // Flushes all buffers associated with this object to disk - void flush( H5F_scope_t scope ) const; - // Creates an attribute for a group, dataset, or named datatype. // PropList is currently not used, so always be default. Attribute createAttribute( const char* name, const DataType& type, const DataSpace& space, const PropList& create_plist = PropList::DEFAULT ) const; @@ -64,26 +60,36 @@ class H5_DLLCPP H5Object : public IdComponent { // Opens an attribute given its index. Attribute openAttribute( const unsigned int idx ) const; - // Iterate user's function over the attributes of this object - int iterateAttrs( attr_operator_t user_op, unsigned* idx = NULL, void* op_data = NULL ); + // Flushes all buffers associated with this object to disk + void flush( H5F_scope_t scope ) const; + + // Gets the name of the file, in which this HDF5 object belongs. + string getFileName() const; // Determines the number of attributes attached to this object. int getNumAttrs() const; + // Iterate user's function over the attributes of this object + int iterateAttrs( attr_operator_t user_op, unsigned* idx = NULL, void* op_data = NULL ); + // Removes the named attribute from this object. void removeAttr( const char* name ) const; void removeAttr( const string& name ) const; + // Copy constructor: makes copy of an H5Object object. + H5Object(const H5Object& original); + // Noop destructor. virtual ~H5Object(); protected: - +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Default constructor H5Object(); // Creates a copy of an existing object giving the object id H5Object( const hid_t object_id ); +#endif // DOXYGEN_SHOULD_SKIP_THIS }; /* end class H5Object */ |