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++/src/H5IdComponent.cpp | |
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++/src/H5IdComponent.cpp')
-rw-r--r-- | c++/src/H5IdComponent.cpp | 84 |
1 files changed, 61 insertions, 23 deletions
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 |