diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2013-09-29 04:34:31 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2013-09-29 04:34:31 (GMT) |
commit | 5478de764594d5c30bf8cd53076892f0aa60543c (patch) | |
tree | 558d9e524e5f2e84026ebdfeb9960a5b8962c06d /c++ | |
parent | 252ed47f9b0333a112a49a5b23a1cc4a5e108b1e (diff) | |
download | hdf5-5478de764594d5c30bf8cd53076892f0aa60543c.zip hdf5-5478de764594d5c30bf8cd53076892f0aa60543c.tar.gz hdf5-5478de764594d5c30bf8cd53076892f0aa60543c.tar.bz2 |
[svn-r24216] Purpose: Merged changes from trunk
Description from trunk, r22836
In this bug, H5File doesn't have the ability to create attribute. The
following changes will provide that functionality and several others that
were also missing:
- Added an abstract class H5Location in between IdComponent and H5Object.
- New class structure of IdComponent, H5Location, H5Object, H5File
IdComponent
|
H5Location
/ \
H5Object H5File
- Wrappers in H5Object were moved to H5Location because the related C
functions take either file, group, dataset, or named datatype ID.
- Added wrapper for H5Rget_obj_type2
- Added tests for file attributes and H5Rget_obj_type2 wrapper
Description from trunk, r22845
Fixed miscellaneous inconsistencies and typos, which also took
care of the failure in Packet Table test on daily test today.
Description from trunk, r24143
Fixed comments, documentation, and mis-matched DOXYGEN_SHOULD_SKIP_THIS pairs.
Description from trunk, r24188
- The failure in daily test was caused by missing initialization of member
"id" in a few constructors. This is now fixed.
- Added two overloaded H5Location::setComment
- Improved some error reporting in H5Location
- Improved error reporting in tests
Description from trunk, r24189
Changed header guards from single underscore to double underscore.
Platforms tested:
SunOS 5.11 (emu)
Linux/32 2.6 (jam)
Linux/64 2.6 (koala)/PGI compilers
Diffstat (limited to 'c++')
51 files changed, 2100 insertions, 1610 deletions
diff --git a/c++/src/H5AbstractDs.h b/c++/src/H5AbstractDs.h index c5ffa36..e1e78e9 100644 --- a/c++/src/H5AbstractDs.h +++ b/c++/src/H5AbstractDs.h @@ -19,8 +19,8 @@ // Attribute and DataSet. It also inherits from H5Object and passes down // the services that H5Object provides. -#ifndef _AbstractDs_H -#define _AbstractDs_H +#ifndef __AbstractDs_H +#define __AbstractDs_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -51,18 +51,17 @@ class H5_DLLCPP AbstractDs { StrType getStrType() const; VarLenType getVarLenType() const; - // Gets the size in memory of this abstract dataset. + ///\brief Gets the size in memory of this abstract dataset. virtual size_t getInMemDataSize() const = 0; - // Gets the dataspace of this abstract dataset - pure virtual. + ///\brief Gets the dataspace of this abstract dataset - pure virtual. virtual DataSpace getSpace() const = 0; // Gets the class of the datatype that is used by this abstract // dataset. H5T_class_t getTypeClass() const; - // Returns the amount of storage size required for this abstract - // dataset - pure virtual. + ///\brief Returns the amount of storage size required - pure virtual. virtual hsize_t getStorageSize() const = 0; // Returns this class name - pure virtual. @@ -88,4 +87,4 @@ class H5_DLLCPP AbstractDs { #ifndef H5_NO_NAMESPACE } #endif -#endif // _AbstractDs_H +#endif // __AbstractDs_H diff --git a/c++/src/H5ArrayType.h b/c++/src/H5ArrayType.h index 0eb744c..d2e3c29 100644 --- a/c++/src/H5ArrayType.h +++ b/c++/src/H5ArrayType.h @@ -17,8 +17,8 @@ // Class ArrayType inherits from DataType and provides wrappers for the // HDF5 C's Array Datatypes. -#ifndef _H5ArrayType_H -#define _H5ArrayType_H +#ifndef __H5ArrayType_H +#define __H5ArrayType_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -36,7 +36,7 @@ class H5_DLLCPP ArrayType : public DataType { // Returns the sizes of dimensions of this array datatype. int getArrayDims(hsize_t* dims); - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("ArrayType"); } // Copy constructor: makes copy of the original object. @@ -59,4 +59,4 @@ class H5_DLLCPP ArrayType : public DataType { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5ArrayType_H diff --git a/c++/src/H5AtomType.cpp b/c++/src/H5AtomType.cpp index 975cad6..09f762f 100644 --- a/c++/src/H5AtomType.cpp +++ b/c++/src/H5AtomType.cpp @@ -45,7 +45,6 @@ AtomType::AtomType() : DataType() {} // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- AtomType::AtomType( const hid_t existing_id ) : DataType( existing_id ) {} -#endif // DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: AtomType copy constructor @@ -53,6 +52,7 @@ AtomType::AtomType( const hid_t existing_id ) : DataType( existing_id ) {} // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- AtomType::AtomType( const AtomType& original ) : DataType( original ) {} +#endif // DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: AtomType::setSize @@ -285,12 +285,14 @@ void AtomType::setPad( H5T_pad_t lsb, H5T_pad_t msb ) const } } +#ifndef DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: AtomType destructor ///\brief Noop destructor. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- AtomType::~AtomType() {} +#endif // DOXYGEN_SHOULD_SKIP_THIS #ifndef H5_NO_NAMESPACE } // end namespace diff --git a/c++/src/H5AtomType.h b/c++/src/H5AtomType.h index 580b710..e8d6513 100644 --- a/c++/src/H5AtomType.h +++ b/c++/src/H5AtomType.h @@ -19,8 +19,8 @@ // subclasses. It also inherits from DataType and passes down the // services that are common to all the datatypes. -#ifndef _H5AtomType_H -#define _H5AtomType_H +#ifndef __H5AtomType_H +#define __H5AtomType_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -57,14 +57,16 @@ class H5_DLLCPP AtomType : public DataType { // Sets the total size for an atomic datatype. void setSize( size_t size ) const; - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("AtomType"); } +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Copy constructor - makes copy of the original object AtomType( const AtomType& original ); // Noop destructor virtual ~AtomType(); +#endif // DOXYGEN_SHOULD_SKIP_THIS protected: #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -78,4 +80,4 @@ class H5_DLLCPP AtomType : public DataType { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5AtomType_H diff --git a/c++/src/H5Attribute.cpp b/c++/src/H5Attribute.cpp index 6c14269..34bf256 100644 --- a/c++/src/H5Attribute.cpp +++ b/c++/src/H5Attribute.cpp @@ -44,6 +44,7 @@ namespace H5 { #endif // H5_NO_STD #endif +class H5_DLLCPP H5Object; // forward declaration for UserData4Aiterate //-------------------------------------------------------------------------- // Function: Attribute default constructor ///\brief Default constructor: Creates a stub attribute @@ -411,7 +412,8 @@ void Attribute::flush(H5F_scope_t scope) const //-------------------------------------------------------------------------- // Function: Attribute::getId -// Purpose: Get the id of this attribute +///\brief Get the id of this attribute +///\return Attribute identifier // Description: // Class hierarchy is revised to address bugzilla 1068. Class // AbstractDS and Attribute are moved out of H5Object. In diff --git a/c++/src/H5Attribute.h b/c++/src/H5Attribute.h index cafc264..f9637fd 100644 --- a/c++/src/H5Attribute.h +++ b/c++/src/H5Attribute.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5Attribute_H -#define _H5Attribute_H +#ifndef __H5Attribute_H +#define __H5Attribute_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -55,7 +55,7 @@ class H5_DLLCPP Attribute : public AbstractDs, public IdComponent { // attribute to disk. void flush( H5F_scope_t scope ) const; - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("Attribute"); } // Creates a copy of an existing attribute using the attribute id @@ -99,4 +99,4 @@ class H5_DLLCPP Attribute : public AbstractDs, public IdComponent { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5Attribute_H diff --git a/c++/src/H5Classes.h b/c++/src/H5Classes.h index f691548..de7cf4a 100644 --- a/c++/src/H5Classes.h +++ b/c++/src/H5Classes.h @@ -14,14 +14,15 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5Classes_H -#define _H5Classes_H +#ifndef __H5Classes_H +#define __H5Classes_H #ifndef H5_NO_NAMESPACE namespace H5 { #endif class Exception; class IdComponent; + class H5Location; class H5Object; class PropList; class FileCreatPropList; @@ -48,4 +49,4 @@ namespace H5 { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5Classes_H diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp index b3889a0..3bf4b4f 100644 --- a/c++/src/H5CommonFG.cpp +++ b/c++/src/H5CommonFG.cpp @@ -460,135 +460,6 @@ H5std_string CommonFG::getLinkval( const H5std_string& name, size_t size ) const } //-------------------------------------------------------------------------- -// Function: CommonFG::setComment -///\brief Sets or resets the comment for an object specified by its name. -///\param name - IN: Name of the object -///\param comment - IN: New comment -///\exception H5::FileIException or H5::GroupIException -///\par Description -/// If \a comment is an empty string or a null pointer, the comment -/// message is removed from the object. -/// Comments should be relatively short, null-terminated, ASCII -/// strings. They can be attached to any object that has an -/// object header, e.g., data sets, groups, named data types, -/// and data spaces, but not symbolic links. -// Programmer Binh-Minh Ribler - 2000 -// Modification -// 2007: QAK modified to use H5O APIs; however the first parameter is -// no longer just file or group, this function should be moved -// to another class to accommodate attribute, dataset, and named -// datatype. - BMR -//-------------------------------------------------------------------------- -void CommonFG::setComment( const char* name, const char* comment ) const -{ - herr_t ret_value = H5Oset_comment_by_name( getLocId(), name, comment, H5P_DEFAULT ); - if( ret_value < 0 ) - throwException("setComment", "H5Oset_comment_by_name failed"); -} - -//-------------------------------------------------------------------------- -// Function: CommonFG::setComment -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes an -/// \c H5std_string for \a name and \a comment. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -void CommonFG::setComment( const H5std_string& name, const H5std_string& comment ) const -{ - setComment( name.c_str(), comment.c_str() ); -} - -//-------------------------------------------------------------------------- -// Function: CommonFG::removeComment -///\brief Removes the comment from an object specified by its name. -///\param name - IN: Name of the object -///\exception H5::FileIException or H5::GroupIException -// Programmer Binh-Minh Ribler - May 2005 -// 2007: QAK modified to use H5O APIs; however the first parameter is -// no longer just file or group, this function should be moved -// to another class to accommodate attribute, dataset, and named -// datatype. - BMR -//-------------------------------------------------------------------------- -void CommonFG::removeComment(const char* name) const -{ - herr_t ret_value = H5Oset_comment_by_name(getLocId(), name, NULL, H5P_DEFAULT); - if( ret_value < 0 ) - throwException("removeComment", "H5Oset_comment_by_name failed"); -} - -//-------------------------------------------------------------------------- -// Function: CommonFG::removeComment -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes an -/// \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - May 2005 -//-------------------------------------------------------------------------- -void CommonFG::removeComment(const H5std_string& name) const -{ - removeComment (name.c_str()); -} - -//-------------------------------------------------------------------------- -// Function: CommonFG::getComment -///\brief Retrieves comment for the specified object and its comment's -/// length. -///\param name - IN: Name of the object -///\param bufsize - IN: Length of the comment to retrieve -///\return Comment string -///\exception H5::FileIException or H5::GroupIException -// Programmer Binh-Minh Ribler - 2000 -// 2007: QAK modified to use H5O APIs; however the first parameter is -// no longer just file or group, this function should be moved -// to another class to accommodate attribute, dataset, and named -// datatype. - BMR -//-------------------------------------------------------------------------- -H5std_string CommonFG::getComment( const char* name, size_t bufsize ) const -{ - // bufsize is default to 256 - // temporary variable - hid_t loc_id = getLocId(); // temporary variable - - // temporary C-string for the object's comment; bufsize already including - // null character - char* comment_C = new char[bufsize]; - ssize_t ret_value = H5Oget_comment_by_name(loc_id, name, comment_C, bufsize, H5P_DEFAULT); - - // if the actual length of the comment is longer than bufsize and bufsize - // was the default value, i.e., not given by the user, then call - // H5Oget_comment_by_name again with the correct value. - // If the call to H5Oget_comment_by_name returned an error, skip this block - // and throw an exception below. - if (ret_value >= 0 && (size_t)ret_value > bufsize && bufsize == 256) - { - size_t new_size = ret_value; - delete []comment_C; - comment_C = new char[new_size]; // new_size including null terminator - ret_value = H5Oget_comment_by_name(loc_id, name, comment_C, new_size, H5P_DEFAULT); - } - - // if H5Oget_comment_by_name returns SUCCEED, return the string comment, - // otherwise, throw an exception - if( ret_value < 0 ) - throwException("getComment", "H5Oget_comment_by_name failed"); - - H5std_string comment = H5std_string(comment_C); - delete []comment_C; - return (comment); -} - -//-------------------------------------------------------------------------- -// Function: CommonFG::getComment -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes an -/// \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -H5std_string CommonFG::getComment( const H5std_string& name, size_t bufsize ) const -{ - return( getComment( name.c_str(), bufsize )); -} - -//-------------------------------------------------------------------------- // Function: CommonFG::mount ///\brief Mounts the file \a child onto this group. ///\param name - IN: Name of the group @@ -1136,6 +1007,7 @@ H5G_obj_t CommonFG::getObjTypeByIdx(hsize_t idx, H5std_string& type_name) const } #endif /* H5_NO_DEPRECATED_SYMBOLS */ +#ifndef DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: CommonFG default constructor ///\brief Default constructor. @@ -1149,6 +1021,7 @@ CommonFG::CommonFG() {} // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- CommonFG::~CommonFG() {} +#endif // DOXYGEN_SHOULD_SKIP_THIS #ifndef H5_NO_NAMESPACE } diff --git a/c++/src/H5CommonFG.h b/c++/src/H5CommonFG.h index 4f32d21..1748d1d 100644 --- a/c++/src/H5CommonFG.h +++ b/c++/src/H5CommonFG.h @@ -18,8 +18,8 @@ // common services that are provided by H5File and Group. The file or // group in the context of this class is referred to as 'location'. -#ifndef _CommonFG_H -#define _CommonFG_H +#ifndef __CommonFG_H +#define __CommonFG_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -49,18 +49,6 @@ class H5_DLLCPP CommonFG { DataSet openDataSet(const char* name) const; DataSet openDataSet(const H5std_string& name) const; - // Retrieves comment for the HDF5 object specified by its name. - H5std_string getComment(const char* name, size_t bufsize=256) const; - H5std_string getComment(const H5std_string& name, size_t bufsize=256) const; - - // Removes the comment for the HDF5 object specified by its name. - void removeComment(const char* name) const; - void removeComment(const H5std_string& name) const; - - // Sets the comment for an HDF5 object specified by its name. - void setComment(const char* name, const char* comment) const; - void setComment(const H5std_string& name, const H5std_string& comment) const; - // Returns the value of a symbolic link. H5std_string getLinkval(const char* link_name, size_t size=0) const; H5std_string getLinkval(const H5std_string& link_name, size_t size=0) const; @@ -152,7 +140,6 @@ class H5_DLLCPP CommonFG { /// object id, i.e. file or group id. virtual hid_t getLocId() const = 0; -#endif // DOXYGEN_SHOULD_SKIP_THIS /// For subclasses, H5File and Group, to throw appropriate exception. virtual void throwException(const H5std_string& func_name, const H5std_string& msg) const = 0; @@ -162,11 +149,12 @@ class H5_DLLCPP CommonFG { // Noop destructor. virtual ~CommonFG(); +#endif // DOXYGEN_SHOULD_SKIP_THIS }; // end of CommonFG declaration #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __CommonFG_H diff --git a/c++/src/H5CompType.h b/c++/src/H5CompType.h index 2336bd1..16ae839 100644 --- a/c++/src/H5CompType.h +++ b/c++/src/H5CompType.h @@ -17,8 +17,8 @@ // Class CompType inherits from DataType and provides accesses to a compound // datatype. -#ifndef _H5CompType_H -#define _H5CompType_H +#ifndef __H5CompType_H +#define __H5CompType_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -97,7 +97,7 @@ class H5_DLLCPP CompType : public DataType { // Recursively removes padding from within this compound datatype. void pack() const; - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("CompType"); } // Noop destructor. @@ -111,4 +111,4 @@ class H5_DLLCPP CompType : public DataType { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5CompType_H diff --git a/c++/src/H5Cpp.h b/c++/src/H5Cpp.h index 75d82ba..044108b 100644 --- a/c++/src/H5Cpp.h +++ b/c++/src/H5Cpp.h @@ -14,14 +14,15 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5CPP_H -#define _H5CPP_H +#ifndef __H5Cpp_H +#define __H5Cpp_H #include "H5Include.h" #include "H5Exception.h" #include "H5IdComponent.h" #include "H5DataSpace.h" #include "H5PropList.h" +#include "H5Location.h" #include "H5Object.h" #include "H5AbstractDs.h" #include "H5Attribute.h" @@ -55,4 +56,4 @@ #define HOFFSET(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) #endif -#endif +#endif // __H5Cpp_H diff --git a/c++/src/H5CppDoc.h b/c++/src/H5CppDoc.h index ab3fa79..baeca64 100644 --- a/c++/src/H5CppDoc.h +++ b/c++/src/H5CppDoc.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5CPPDOC_H -#define _H5CPPDOC_H +#ifndef __H5CppDoc_H +#define __H5CppDoc_H //------------------------------------------------------------------------- // The following section will be used to generate the 'Mainpage' @@ -88,4 +88,4 @@ /// This example shows how to work with groups. ///\example h5group.cpp -#endif +#endif // __H5CppDoc_H diff --git a/c++/src/H5DataSet.cpp b/c++/src/H5DataSet.cpp index f7aaa72..1a26045 100644 --- a/c++/src/H5DataSet.cpp +++ b/c++/src/H5DataSet.cpp @@ -79,57 +79,29 @@ DataSet::DataSet(const DataSet& original) : AbstractDs(original), H5Object(origi //-------------------------------------------------------------------------- // Function: DataSet overload constructor - dereference -///\brief Given a reference, ref, to an hdf5 dataset, creates a +///\brief Given a reference, ref, to an hdf5 location, creates a /// DataSet object -///\param obj - IN: Dataset reference object is in or location of +///\param loc - IN: Dataset reference object is in or location of /// object that the dataset is located within. ///\param ref - IN: Reference pointer ///\param ref_type - IN: Reference type - default to H5R_OBJECT ///\exception H5::DataSetIException ///\par Description -/// \c obj can be DataSet, Group, H5File, or named DataType, that +/// \c loc can be DataSet, Group, H5File, or named DataType, that /// is a datatype that has been named by DataType::commit. // Programmer Binh-Minh Ribler - Oct, 2006 // Modification // Jul, 2008 // Added for application convenience. //-------------------------------------------------------------------------- -DataSet::DataSet(H5Object& obj, const void* ref, H5R_type_t ref_type) : AbstractDs(), H5Object() +DataSet::DataSet(const H5Location& loc, const void* ref, H5R_type_t ref_type) : AbstractDs(), H5Object(), id(0) { - try { - id = p_dereference(obj.getId(), ref, ref_type); - } catch (ReferenceException deref_error) { - throw ReferenceException("DataSet constructor - located by object", - deref_error.getDetailMsg()); - } + id = H5Location::p_dereference(loc.getId(), ref, ref_type, "constructor - by dereferenced"); } //-------------------------------------------------------------------------- // Function: DataSet overload constructor - dereference -///\brief Given a reference, ref, to an hdf5 dataset, creates a -/// DataSet object -///\param h5file - IN: Location referenced object is in -///\param ref - IN: Reference pointer -///\param ref_type - IN: Reference type - default to H5R_OBJECT -///\exception H5::DataSetIException -// Programmer Binh-Minh Ribler - Oct, 2006 -// Modification -// Jul, 2008 -// Added for application convenience. -//-------------------------------------------------------------------------- -DataSet::DataSet(H5File& h5file, const void* ref, H5R_type_t ref_type) : AbstractDs(), H5Object() -{ - try { - id = p_dereference(h5file.getId(), ref, ref_type); - } catch (ReferenceException deref_error) { - throw ReferenceException("DataSet constructor - located by HDF5 file", - deref_error.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: DataSet overload constructor - dereference -///\brief Given a reference, ref, to an hdf5 dataset, creates a +///\brief Given a reference, ref, to an hdf5 attribute, creates a /// DataSet object ///\param attr - IN: Specifying location where the referenced object is in ///\param ref - IN: Reference pointer @@ -140,14 +112,9 @@ DataSet::DataSet(H5File& h5file, const void* ref, H5R_type_t ref_type) : Abstrac // Jul, 2008 // Added for application convenience. //-------------------------------------------------------------------------- -DataSet::DataSet(Attribute& attr, const void* ref, H5R_type_t ref_type) : AbstractDs(), H5Object() +DataSet::DataSet(const Attribute& attr, const void* ref, H5R_type_t ref_type) : AbstractDs(), H5Object(), id(0) { - try { - id = p_dereference(attr.getId(), ref, ref_type); - } catch (ReferenceException deref_error) { - throw ReferenceException("DataSet constructor - located by attribute", - deref_error.getDetailMsg()); - } + id = H5Location::p_dereference(attr.getId(), ref, ref_type, "constructor - by dereference"); } //-------------------------------------------------------------------------- @@ -430,7 +397,7 @@ void DataSet::read( void* buf, const DataType& mem_type, const DataSpace& mem_sp // Function: DataSet::read ///\brief This is an overloaded member function, provided for convenience. /// It takes a reference to a \c H5std_string for the buffer. -///\param buf - IN: Buffer for read data +///\param strg - IN: Buffer for read data string ///\param mem_type - IN: Memory datatype ///\param mem_space - IN: Memory dataspace ///\param file_space - IN: Dataset's dataspace in the file @@ -644,57 +611,10 @@ void DataSet::fillMemBuf(void *buf, DataType& buf_type, DataSpace& space) } } -#ifndef H5_NO_DEPRECATED_SYMBOLS -//-------------------------------------------------------------------------- -// Function: DataSet::getObjType -///\brief Retrieves the type of object that an object reference points to. -///\param ref_type - IN: Type of reference to query, valid values are: -/// \li \c H5R_OBJECT - Reference is an object reference. -/// \li \c H5R_DATASET_REGION - Reference is a dataset region reference. -///\param ref - IN: Reference to query -///\return An object type, which can be one of the following: -/// \li \c H5G_LINK (0) - Object is a symbolic link. -/// \li \c H5G_GROUP (1) - Object is a group. -/// \li \c H5G_DATASET (2) - Object is a dataset. -/// \li \c H5G_TYPE (3) - Object is a named datatype -///\exception H5::DataSetIException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -H5G_obj_t DataSet::getObjType(void *ref, H5R_type_t ref_type) const -{ - try { - return(p_get_obj_type(ref, ref_type)); - } - catch (IdComponentException E) { - throw DataSetIException("DataSet::getObjType", E.getDetailMsg()); - } -} -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - -//-------------------------------------------------------------------------- -// Function: DataSet::getRegion -///\brief Retrieves a dataspace with the region pointed to selected. -///\param ref - IN: Reference to get region of -///\param ref_type - IN: Type of reference to get region of - default -/// to H5R_DATASET_REGION -///\return DataSpace instance -///\exception H5::DataSetIException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -DataSpace DataSet::getRegion(void *ref, H5R_type_t ref_type) const -{ - try { - DataSpace dataspace(p_get_region(ref, ref_type)); - return(dataspace); - } - catch (IdComponentException E) { - throw DataSetIException("DataSet::getRegion", E.getDetailMsg()); - } -} - //-------------------------------------------------------------------------- // Function: DataSet::getId ///\brief Get the id of this dataset. +///\return DataSet identifier // Description: // Class hierarchy is revised to address bugzilla 1068. Class // AbstractDs and Attribute are moved out of H5Object. In @@ -774,8 +694,9 @@ void DataSet::p_read_variable_len(const hid_t mem_type_id, const hid_t mem_space HDfree(strg_C); } +#ifndef DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- -// Function: DataSet::p_setId (private) +// Function: DataSet::p_setId (protected) ///\brief Sets the identifier of this dataset to a new value. /// ///\exception H5::IdComponentException when the attempt to close the HDF5 @@ -797,10 +718,8 @@ void DataSet::p_setId(const hid_t new_id) } // reset object's id to the given id id = new_id; - - // increment the reference counter of the new id - //incRefCount(); } +#endif // DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: DataSet::close diff --git a/c++/src/H5DataSet.h b/c++/src/H5DataSet.h index 5c5f995..8fdc47e 100644 --- a/c++/src/H5DataSet.h +++ b/c++/src/H5DataSet.h @@ -16,8 +16,8 @@ // Class DataSet inherits from AbstractDs and provides accesses to a dataset. -#ifndef _H5DataSet_H -#define _H5DataSet_H +#ifndef __H5DataSet_H +#define __H5DataSet_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -76,21 +76,12 @@ class H5_DLLCPP DataSet : public H5Object, public AbstractDs { // Iterates the selected elements in the specified dataspace - not implemented in C++ style yet int iterateElems( void* buf, const DataType& type, const DataSpace& space, H5D_operator_t op, void* op_data = NULL ); -#ifndef H5_NO_DEPRECATED_SYMBOLS - // Retrieves the type of object that an object reference points to. - H5G_obj_t getObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const; -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - - // Retrieves a dataspace with the region pointed to selected. - DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const; - - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("DataSet"); } // Creates a dataset by way of dereference. - DataSet(H5Object& obj, const void* ref, H5R_type_t ref_type = H5R_OBJECT); - DataSet(H5File& h5file, const void* ref, H5R_type_t ref_type = H5R_OBJECT); - DataSet(Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT); + DataSet(const H5Location& loc, const void* ref, H5R_type_t ref_type = H5R_OBJECT); + DataSet(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT); // Default constructor. DataSet(); @@ -110,7 +101,6 @@ class H5_DLLCPP DataSet : public H5Object, public AbstractDs { private: hid_t id; // HDF5 dataset id -#ifndef DOXYGEN_SHOULD_SKIP_THIS // This function contains the common code that is used by // getTypeClass and various API functions getXxxType // defined in AbstractDs for generic datatype and specific @@ -122,6 +112,7 @@ class H5_DLLCPP DataSet : public H5Object, public AbstractDs { void p_read_variable_len(const hid_t mem_type_id, const hid_t mem_space_id, const hid_t file_space_id, const hid_t xfer_plist_id, H5std_string& strg) const; protected: +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Sets the dataset id. virtual void p_setId(const hid_t new_id); #endif // DOXYGEN_SHOULD_SKIP_THIS @@ -129,4 +120,4 @@ class H5_DLLCPP DataSet : public H5Object, public AbstractDs { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5DataSet_H diff --git a/c++/src/H5DataSpace.cpp b/c++/src/H5DataSpace.cpp index 755ca5b..059c812 100644 --- a/c++/src/H5DataSpace.cpp +++ b/c++/src/H5DataSpace.cpp @@ -446,7 +446,7 @@ void DataSpace::getSelectBounds ( hsize_t* start, hsize_t* end ) const } //-------------------------------------------------------------------------- -// Function: DataSpace::H5Sselect_elements +// Function: DataSpace::selectElements ///\brief Selects array elements to be included in the selection for /// this dataspace. ///\param op - IN: Operator specifying how the new selection is to be @@ -556,7 +556,8 @@ void DataSpace::selectHyperslab( H5S_seloper_t op, const hsize_t *count, const h //-------------------------------------------------------------------------- // Function: DataSpace::getId -// Purpose: Get the id of this attribute +///\brief Get the id of this dataspace +///\return Dataspace identifier // Modification: // May 2008 - BMR // Class hierarchy is revised to address bugzilla 1068. Class @@ -570,6 +571,7 @@ hid_t DataSpace::getId() const return(id); } +#ifndef DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: DataSpace::p_setId ///\brief Sets the identifier of this object to a new value. @@ -594,6 +596,7 @@ void DataSpace::p_setId(const hid_t new_id) // reset object's id to the given id id = new_id; } +#endif // DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: DataSpace::close diff --git a/c++/src/H5DataSpace.h b/c++/src/H5DataSpace.h index 0d4ab68..1ea7188 100644 --- a/c++/src/H5DataSpace.h +++ b/c++/src/H5DataSpace.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5DataSpace_H -#define _H5DataSpace_H +#ifndef __H5DataSpace_H +#define __H5DataSpace_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -103,7 +103,7 @@ class H5_DLLCPP DataSpace : public IdComponent { // Sets or resets the size of this dataspace. void setExtentSimple( int rank, const hsize_t *current_size, const hsize_t *maximum_size = NULL ) const; - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("DataSpace"); } // Creates a DataSpace object using an existing dataspace id. @@ -122,10 +122,13 @@ class H5_DLLCPP DataSpace : public IdComponent { hid_t id; // HDF5 dataspace id protected: +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Sets the dataspace id. virtual void p_setId(const hid_t new_id); +#endif // DOXYGEN_SHOULD_SKIP_THIS + }; #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5DataSpace_H diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index 3edb163..3d147c6 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -49,6 +49,13 @@ namespace H5 { #endif //-------------------------------------------------------------------------- +// Function: DataType default constructor +///\brief Default constructor: Creates a stub datatype +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +DataType::DataType() : H5Object(), id(0) {} + +//-------------------------------------------------------------------------- // Function: DataType overloaded constructor ///\brief Creates a datatype using an existing datatype's id ///\param existing_id - IN: Id of the existing datatype @@ -88,32 +95,6 @@ DataType::DataType( const H5T_class_t type_class, size_t size ) : H5Object() // Function: DataType overload constructor - dereference ///\brief Given a reference, ref, to an hdf5 group, creates a /// DataType object -///\param obj - IN: Specifying location referenced object is in -///\param ref - IN: Reference pointer -///\param ref_type - IN: Reference type - default to H5R_OBJECT -///\exception H5::ReferenceException -///\par Description -/// \c obj can be DataSet, Group, or named DataType, that -/// is a datatype that has been named by DataType::commit. -// Programmer Binh-Minh Ribler - Oct, 2006 -// Modification -// Jul, 2008 -// Added for application convenience. -//-------------------------------------------------------------------------- -DataType::DataType(H5Object& obj, const void* ref, H5R_type_t ref_type) : H5Object() -{ - try { - id = p_dereference(obj.getId(), ref, ref_type); - } catch (ReferenceException deref_error) { - throw ReferenceException("DataType constructor - located by an H5Object", - deref_error.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: DataType overload constructor - dereference -///\brief Given a reference, ref, to an hdf5 group, creates a -/// DataType object ///\param h5file - IN: Location referenced object is in ///\param ref - IN: Reference pointer ///\param ref_type - IN: Reference type - default to H5R_OBJECT @@ -123,14 +104,9 @@ DataType::DataType(H5Object& obj, const void* ref, H5R_type_t ref_type) : H5Obje // Jul, 2008 // Added for application convenience. //-------------------------------------------------------------------------- -DataType::DataType(H5File& h5file, const void* ref, H5R_type_t ref_type) : H5Object() +DataType::DataType(const H5Location& loc, const void* ref, H5R_type_t ref_type) : H5Object(), id(0) { - try { - id = p_dereference(h5file.getId(), ref, ref_type); - } catch (ReferenceException deref_error) { - throw ReferenceException("DataType constructor - located by an H5File", - deref_error.getDetailMsg()); - } + id = H5Location::p_dereference(loc.getId(), ref, ref_type, "constructor - by dereference"); } //-------------------------------------------------------------------------- @@ -146,24 +122,12 @@ DataType::DataType(H5File& h5file, const void* ref, H5R_type_t ref_type) : H5Obj // Jul, 2008 // Added for application convenience. //-------------------------------------------------------------------------- -DataType::DataType(Attribute& attr, const void* ref, H5R_type_t ref_type) : H5Object() +DataType::DataType(const Attribute& attr, const void* ref, H5R_type_t ref_type) : H5Object(), id(0) { - try { - id = p_dereference(attr.getId(), ref, ref_type); - } catch (ReferenceException deref_error) { - throw ReferenceException("DataType constructor - located by an Attribute", - deref_error.getDetailMsg()); - } + id = H5Location::p_dereference(attr.getId(), ref, ref_type, "constructor - by dereference"); } //-------------------------------------------------------------------------- -// Function: DataType default constructor -///\brief Default constructor: Creates a stub datatype -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -DataType::DataType() : H5Object(), id(0) {} - -//-------------------------------------------------------------------------- // Function: DataType copy constructor ///\brief Copy constructor: makes a copy of the original DataType object. // Programmer Binh-Minh Ribler - 2000 @@ -679,54 +643,10 @@ bool DataType::isVariableStr() const } } -#ifndef H5_NO_DEPRECATED_SYMBOLS -//-------------------------------------------------------------------------- -// Function: DataType::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 -///\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 -///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -H5G_obj_t DataType::getObjType(void *ref, H5R_type_t ref_type) const -{ - try { - return(p_get_obj_type(ref, ref_type)); - } - catch (IdComponentException E) { - throw DataTypeIException(inMemFunc("getObjType"), E.getDetailMsg()); - } -} -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - -//-------------------------------------------------------------------------- -// Function: DataType::getRegion -///\brief Retrieves a dataspace with the region pointed to selected. -///\param ref - IN: Reference to get region of -///\param ref_type - IN: Type of reference to get region of - default -///\return DataSpace instance -///\exception H5::DataTypeIException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -DataSpace DataType::getRegion(void *ref, H5R_type_t ref_type) const -{ - try { - DataSpace dataspace(p_get_region(ref, ref_type)); - return(dataspace); - } - catch (IdComponentException E) { - throw DataTypeIException(inMemFunc("getRegion"), E.getDetailMsg()); - } -} - //-------------------------------------------------------------------------- // Function: DataType::getId -// Purpose: Get the id of this attribute +///\brief Get the id of this datatype +///\return Datatype identifier // Modification: // May 2008 - BMR // Class hierarchy is revised to address bugzilla 1068. Class @@ -740,6 +660,7 @@ hid_t DataType::getId() const return(id); } +#ifndef DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: DataType::p_setId ///\brief Sets the identifier of this object to a new value. @@ -764,6 +685,7 @@ void DataType::p_setId(const hid_t new_id) // reset object's id to the given id id = new_id; } +#endif // DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: DataType::close diff --git a/c++/src/H5DataType.h b/c++/src/H5DataType.h index 53709c7..4071a2c 100644 --- a/c++/src/H5DataType.h +++ b/c++/src/H5DataType.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5DataType_H -#define _H5DataType_H +#ifndef __H5DataType_H +#define __H5DataType_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -30,9 +30,8 @@ class H5_DLLCPP DataType : public H5Object { DataType( const DataType& original ); // Creates a datatype by way of dereference. - DataType(H5Object& obj, const void* ref, H5R_type_t ref_type = H5R_OBJECT); - DataType(H5File& h5file, const void* ref, H5R_type_t ref_type = H5R_OBJECT); - DataType(Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT); + DataType(const H5Location& loc, const void* ref, H5R_type_t ref_type = H5R_OBJECT); + DataType(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT); // Closes this datatype. virtual void close(); @@ -101,15 +100,7 @@ class H5_DLLCPP DataType : public H5Object { // Checks whether this datatype is a variable-length string. bool isVariableStr() const; -#ifndef H5_NO_DEPRECATED_SYMBOLS - // Retrieves the type of object that an object reference points to. - H5G_obj_t getObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const; -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - - // Retrieves a dataspace with the region pointed to selected. - DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const; - - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("DataType"); } // Creates a copy of an existing DataType using its id @@ -125,10 +116,12 @@ class H5_DLLCPP DataType : public H5Object { virtual ~DataType(); protected: +#ifndef DOXYGEN_SHOULD_SKIP_THIS hid_t id; // HDF5 datatype id // Sets the datatype id. virtual void p_setId(const hid_t new_id); +#endif // DOXYGEN_SHOULD_SKIP_THIS private: void p_commit(hid_t loc_id, const char* name); @@ -136,4 +129,4 @@ class H5_DLLCPP DataType : public H5Object { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5DataType_H diff --git a/c++/src/H5DcreatProp.h b/c++/src/H5DcreatProp.h index 6eadfec..385bc61 100644 --- a/c++/src/H5DcreatProp.h +++ b/c++/src/H5DcreatProp.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5DSCreatPropList_H -#define _H5DSCreatPropList_H +#ifndef __H5DSCreatPropList_H +#define __H5DSCreatPropList_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -107,7 +107,7 @@ class H5_DLLCPP DSetCreatPropList : public PropList { // Sets SZIP compression method. void setSzip(unsigned int options_mask, unsigned int pixels_per_block) const; - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("DSetCreatPropList"); } // Copy constructor: creates a copy of a DSetCreatPropList object. @@ -123,4 +123,4 @@ class H5_DLLCPP DSetCreatPropList : public PropList { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5DSCreatPropList_H diff --git a/c++/src/H5DxferProp.h b/c++/src/H5DxferProp.h index 90fca0a..723603c 100644 --- a/c++/src/H5DxferProp.h +++ b/c++/src/H5DxferProp.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5DSetMemXferPropList_H -#define _H5DSetMemXferPropList_H +#ifndef __H5DSetMemXferPropList_H +#define __H5DSetMemXferPropList_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -102,4 +102,4 @@ class H5_DLLCPP DSetMemXferPropList : public PropList { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5DSetMemXferPropList_H diff --git a/c++/src/H5EnumType.h b/c++/src/H5EnumType.h index 4505c40..71e36c3 100644 --- a/c++/src/H5EnumType.h +++ b/c++/src/H5EnumType.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5EnumType_H -#define _H5EnumType_H +#ifndef __H5EnumType_H +#define __H5EnumType_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -57,7 +57,7 @@ class H5_DLLCPP EnumType : public DataType { void valueOf( const char* name, void *value ) const; void valueOf( const H5std_string& name, void *value ) const; - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("EnumType"); } // Default constructor @@ -74,4 +74,4 @@ class H5_DLLCPP EnumType : public DataType { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5EnumType_H diff --git a/c++/src/H5Exception.h b/c++/src/H5Exception.h index b4af2ba..8b12abc 100644 --- a/c++/src/H5Exception.h +++ b/c++/src/H5Exception.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5Exception_H -#define _H5Exception_H +#ifndef __H5Exception_H +#define __H5Exception_H #include <string> @@ -161,4 +161,4 @@ class H5_DLLCPP IdComponentException : public Exception { } #endif -#endif // _H5Exception_H +#endif // __H5Exception_H diff --git a/c++/src/H5FaccProp.h b/c++/src/H5FaccProp.h index 354eaf7..040b3e9 100644 --- a/c++/src/H5FaccProp.h +++ b/c++/src/H5FaccProp.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5FileAccPropList_H -#define _H5FileAccPropList_H +#ifndef __H5FileAccPropList_H +#define __H5FileAccPropList_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -123,7 +123,7 @@ class H5_DLLCPP FileAccPropList : public PropList { // Returns garbage collecting references setting. unsigned getGcReferences() const; - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("FileAccPropList"); } // Copy constructor: creates a copy of a FileAccPropList object. @@ -139,4 +139,4 @@ class H5_DLLCPP FileAccPropList : public PropList { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5FileAccPropList_H diff --git a/c++/src/H5FcreatProp.h b/c++/src/H5FcreatProp.h index 2e2af70..de7d414 100644 --- a/c++/src/H5FcreatProp.h +++ b/c++/src/H5FcreatProp.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5FileCreatPropList_H -#define _H5FileCreatPropList_H +#ifndef __H5FileCreatPropList_H +#define __H5FileCreatPropList_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -60,7 +60,7 @@ class H5_DLLCPP FileCreatPropList : public PropList { // indexing chunked datasets. void setIstorek( unsigned ik ) const; - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("FileCreatPropList"); } // Copy constructor: creates a copy of a FileCreatPropList object. @@ -76,4 +76,4 @@ class H5_DLLCPP FileCreatPropList : public PropList { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5FileCreatPropList_H diff --git a/c++/src/H5File.cpp b/c++/src/H5File.cpp index 6e85428..48c3513 100644 --- a/c++/src/H5File.cpp +++ b/c++/src/H5File.cpp @@ -50,7 +50,7 @@ namespace H5 { ///\brief Default constructor: creates a stub H5File object. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -H5File::H5File() : IdComponent(), id(0) {} +H5File::H5File() : H5Location(), id(0) {} //-------------------------------------------------------------------------- // Function: H5File overloaded constructor @@ -82,7 +82,7 @@ H5File::H5File() : IdComponent(), id(0) {} // to catch then re-throw it. -BMR 2013/03/21 // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : IdComponent(0) +H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : H5Location(), id(0) { try { p_get_file(name, flags, create_plist, access_plist); @@ -107,7 +107,7 @@ H5File::H5File( const char* name, unsigned int flags, const FileCreatPropList& c // to catch then re-throw it. -BMR 2013/03/21 // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -H5File::H5File( const H5std_string& name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : IdComponent(0) +H5File::H5File( const H5std_string& name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ) : H5Location(), id(0) { try { p_get_file(name.c_str(), flags, create_plist, access_plist); @@ -116,6 +116,7 @@ H5File::H5File( const H5std_string& name, unsigned int flags, const FileCreatPro } } +#ifndef DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // This function is private and contains common code between the // constructors taking a string or a char* @@ -146,6 +147,7 @@ void H5File::p_get_file(const char* name, unsigned int flags, const FileCreatPro } } } +#endif // DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: H5File copy constructor @@ -154,34 +156,15 @@ void H5File::p_get_file(const char* name, unsigned int flags, const FileCreatPro ///\param original - IN: H5File instance to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -H5File::H5File(const H5File& original) : IdComponent(original) +H5File::H5File(const H5File& original) : H5Location(original) { id = original.getId(); incRefCount(); // increment number of references to this id } //-------------------------------------------------------------------------- -// Function: H5File::flush -///\brief Flushes all buffers associated with a file to disk. -///\param scope - IN: Specifies the scope of the flushing action, -/// which can be either of these values: -/// \li \c H5F_SCOPE_GLOBAL - Flushes the entire virtual file -/// \li \c H5F_SCOPE_LOCAL - Flushes only the specified file -///\exception H5::FileIException -// Programmer Binh-Minh Ribler - Dec. 2005 -//-------------------------------------------------------------------------- -void H5File::flush(H5F_scope_t scope) const -{ - herr_t ret_value = H5Fflush( id, scope ); - if( ret_value < 0 ) - { - throw FileIException("H5File::flush", "H5Fflush failed"); - } -} - -//-------------------------------------------------------------------------- // Function: H5File::isHdf5 (static) -///\brief Determines whether a file in HDF5 format. +///\brief Determines whether a file in HDF5 format. (Static) ///\param name - IN: Name of the file ///\return true if the file is in HDF5 format, and false, otherwise ///\exception H5::FileIException @@ -205,7 +188,7 @@ bool H5File::isHdf5(const char* name) //-------------------------------------------------------------------------- // Function: H5File::isHdf5 (static) ///\brief This is an overloaded member function, provided for convenience. -/// It takes an \c H5std_string for \a name. +/// It takes an \c H5std_string for \a name. (Static) ///\param name - IN: Name of the file - \c H5std_string // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- @@ -283,8 +266,8 @@ void H5File::reOpen() 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? + // call C routine to reopen the file - Note: not sure about this, + // which id to be the parameter when closing? id = H5Freopen( id ); if( id < 0 ) // Raise exception when H5Freopen returns a neg value throw FileIException("H5File::reOpen", "H5Freopen failed"); @@ -292,12 +275,10 @@ void H5File::reOpen() //-------------------------------------------------------------------------- // 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. +// Purpose: Reopens this file. +// Exception H5::FileIException +// Description +// This function is replaced by the above function reOpen. // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- void H5File::reopen() @@ -504,70 +485,6 @@ void H5File::getVFDHandle(void **file_handle) const } //-------------------------------------------------------------------------- -// Function: H5File::getFileName -///\brief Gets the name of this file. -///\return File name -///\exception H5::FileIException -// Programmer Binh-Minh Ribler - Jul, 2004 -//-------------------------------------------------------------------------- -H5std_string H5File::getFileName() const -{ - try { - return(p_get_file_name()); - } - catch (IdComponentException E) { - throw FileIException("H5File::getFileName", E.getDetailMsg()); - } -} - -#ifndef H5_NO_DEPRECATED_SYMBOLS -//-------------------------------------------------------------------------- -// 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, valid values are: -/// \li \c H5R_OBJECT - Reference is an object reference -/// \li \c H5R_DATASET_REGION - Reference is a dataset region reference -///\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 -///\exception H5::FileIException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -H5G_obj_t H5File::getObjType(void *ref, H5R_type_t ref_type) const -{ - try { - return(p_get_obj_type(ref, ref_type)); - } - catch (IdComponentException E) { - throw FileIException("H5File::getObjType", E.getDetailMsg()); - } -} -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - -//-------------------------------------------------------------------------- -// Function: H5File::getRegion -///\brief Retrieves a dataspace with the region pointed to selected. -///\param ref - IN: Reference to get region of -///\param ref_type - IN: Type of reference to get region of - default -///\return DataSpace instance -///\exception H5::FileIException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -DataSpace H5File::getRegion(void *ref, H5R_type_t ref_type) const -{ - try { - DataSpace dataspace(p_get_region(ref, ref_type)); - return(dataspace); - } - catch (IdComponentException E) { - throw FileIException("H5File::getRegion", E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- // Function: H5File::getFileSize ///\brief Returns the file size of the HDF5 file. ///\return File size @@ -589,134 +506,6 @@ hsize_t H5File::getFileSize() const } //-------------------------------------------------------------------------- -// Function: H5File::p_reference (protected) -// Purpose Creates a reference to an HDF5 object or a dataset region. -// Parameters -// name - IN: Name of the object to be referenced -// dataspace - IN: Dataspace with selection -// ref_type - IN: Type of reference; default to \c H5R_DATASET_REGION -// Exception H5::IdComponentException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void H5File::p_reference(void* ref, const char* name, hid_t space_id, H5R_type_t ref_type) const -{ - herr_t ret_value = H5Rcreate(ref, getId(), name, ref_type, space_id); - if (ret_value < 0) - { - throw IdComponentException("", "H5Rcreate failed"); - } -} - -//-------------------------------------------------------------------------- -// Function: H5File::reference -///\brief Creates a reference to an HDF5 object or a dataset region. -///\param ref - IN: Reference pointer -///\param name - IN: Name of the object to be referenced -///\param dataspace - IN: Dataspace with selection -///\param ref_type - IN: Type of reference to query, valid values are: -/// \li \c H5R_OBJECT - Reference is an object reference -/// \li \c H5R_DATASET_REGION - Reference is a dataset region -/// reference - this is the default -///\exception H5::IdComponentException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void H5File::reference(void* ref, const char* name, const DataSpace& dataspace, H5R_type_t ref_type) const -{ - try { - p_reference(ref, name, dataspace.getId(), ref_type); - } - catch (IdComponentException E) { - throw IdComponentException("H5File::reference", E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: H5File::reference -///\brief This is an overloaded function, provided for your convenience. -/// It differs from the above function in that it only creates -/// a reference to an HDF5 object, not to a dataset region. -///\param ref - IN: Reference pointer -///\param name - IN: Name of the object to be referenced - \c char pointer -///\exception H5::IdComponentException -///\par Description -// This function passes H5R_OBJECT and -1 to the protected -// function for it to pass to the C API H5Rcreate -// to create a reference to the named object. -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void H5File::reference(void* ref, const char* name) const -{ - try { - p_reference(ref, name, -1, H5R_OBJECT); - } - catch (IdComponentException E) { - throw IdComponentException("H5File::reference", E.getDetailMsg()); - } -} -//-------------------------------------------------------------------------- -// Function: H5File::reference -///\brief This is an overloaded function, provided for your convenience. -/// It differs from the above function in that it takes an -/// \c H5std_string for the object's name. -///\param ref - IN: Reference pointer -///\param name - IN: Name of the object to be referenced - \c H5std_string -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void H5File::reference(void* ref, const H5std_string& name) const -{ - reference(ref, name.c_str()); -} - -#ifndef H5_NO_DEPRECATED_SYMBOLS -//-------------------------------------------------------------------------- -// Function: H5File::p_get_obj_type (protected) -// Purpose Retrieves the type of object that an object reference points to. -// Parameters -// ref - IN: Reference to query -// ref_type - IN: Type of reference to query -// Return An object type, which can be one of the following: -// H5G_LINK Object is a symbolic link. -// H5G_GROUP Object is a group. -// H5G_DATASET Object is a dataset. -// H5G_TYPE Object is a named datatype -// Exception H5::IdComponentException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -H5G_obj_t H5File::p_get_obj_type(void *ref, H5R_type_t ref_type) const -{ - H5G_obj_t obj_type = H5Rget_obj_type1(getId(), ref_type, ref); - - if (obj_type == H5G_UNKNOWN) - { - throw IdComponentException("", "H5Rget_obj_type failed"); - } - return(obj_type); -} -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - - -//-------------------------------------------------------------------------- -// Function: H5File::p_get_region (protected) -// Purpose Retrieves a dataspace with the region pointed to selected. -// Parameters -// ref_type - IN: Type of reference to get region of - default -// to H5R_DATASET_REGION -// ref - IN: Reference to get region of -// Return Dataspace id -// Exception H5::IdComponentException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -hid_t H5File::p_get_region(void *ref, H5R_type_t ref_type) const -{ - hid_t space_id = H5Rget_region(getId(), ref_type, ref); - if (space_id < 0) - { - throw IdComponentException("", "H5Rget_region failed"); - } - return(space_id); -} - -//-------------------------------------------------------------------------- // Function: H5File::getLocId // Purpose: Get the id of this file // Description @@ -731,7 +520,8 @@ hid_t H5File::getLocId() const //-------------------------------------------------------------------------- // Function: H5File::getId -// Purpose: Get the id of this attribute +///\brief Get the id of this file +///\return File identifier // Modification: // May 2008 - BMR // Class hierarchy is revised to address bugzilla 1068. Class @@ -745,8 +535,9 @@ hid_t H5File::getId() const return(id); } +#ifndef DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- -// Function: H5File::p_setId +// Function: H5File::p_setId (protected) ///\brief Sets the identifier of this object to a new value. /// ///\exception H5::IdComponentException when the attempt to close the HDF5 @@ -769,6 +560,7 @@ void H5File::p_setId(const hid_t new_id) // reset object's id to the given id id = new_id; } +#endif // DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: H5File::close diff --git a/c++/src/H5File.h b/c++/src/H5File.h index d87dc08..830dda0 100644 --- a/c++/src/H5File.h +++ b/c++/src/H5File.h @@ -14,14 +14,14 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5File_H -#define _H5File_H +#ifndef __H5File_H +#define __H5File_H #ifndef H5_NO_NAMESPACE namespace H5 { #endif -class H5_DLLCPP H5File : public IdComponent, public CommonFG { +class H5_DLLCPP H5File : public H5Location, public CommonFG { public: // Creates or opens an HDF5 file. H5File( const char* name, unsigned int flags, @@ -40,18 +40,12 @@ class H5_DLLCPP H5File : public IdComponent, public CommonFG { // Close this file. virtual void close(); - // Flushes all buffers associated with this file to disk - void flush(H5F_scope_t scope) 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. - H5std_string getFileName() const; - // Retrieves the file size of an opened file. hsize_t getFileSize() const; @@ -67,14 +61,6 @@ class H5_DLLCPP H5File : public IdComponent, public CommonFG { // and datatypes) in the same file. void getObjIDs(unsigned types, size_t max_objs, hid_t *oid_list) const; -#ifndef H5_NO_DEPRECATED_SYMBOLS - // Retrieves the type of object that an object reference points to. - H5G_obj_t getObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const; -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - - // 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; @@ -87,14 +73,7 @@ class H5_DLLCPP H5File : public IdComponent, public CommonFG { 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(void* ref, const char* name, const DataSpace& dataspace, - H5R_type_t ref_type = H5R_DATASET_REGION) const; - void reference(void* ref, const char* name) const; - void reference(void* ref, const H5std_string& name) const; - - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("H5File"); } // Throw file exception. @@ -118,24 +97,12 @@ class H5_DLLCPP H5File : public IdComponent, public CommonFG { private: hid_t id; // HDF5 file id -#ifndef DOXYGEN_SHOULD_SKIP_THIS - // This function is private and contains common code between the // constructors taking a string or a char* void p_get_file( const char* name, unsigned int flags, const FileCreatPropList& create_plist, const FileAccPropList& access_plist ); - // Creates a reference to an HDF5 object or a dataset region. - void p_reference(void* ref, const char* name, hid_t space_id, H5R_type_t ref_type) const; - -#ifndef H5_NO_DEPRECATED_SYMBOLS - // 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; -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - - // Retrieves a dataspace with the region pointed to selected. - hid_t p_get_region(void *ref, H5R_type_t ref_type) const; - protected: +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Sets the HDF5 file id. virtual void p_setId(const hid_t new_id); @@ -145,4 +112,4 @@ class H5_DLLCPP H5File : public IdComponent, public CommonFG { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5File_H diff --git a/c++/src/H5FloatType.h b/c++/src/H5FloatType.h index 08e5db1..13074ba 100644 --- a/c++/src/H5FloatType.h +++ b/c++/src/H5FloatType.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5FloatType_H -#define _H5FloatType_H +#ifndef __H5FloatType_H +#define __H5FloatType_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -23,10 +23,10 @@ namespace H5 { class H5_DLLCPP FloatType : public AtomType { public: - // Creates a floating-point type using a predefined type + // Creates a floating-point type using a predefined type. FloatType( const PredType& pred_type ); - // Gets the floating-point datatype of the specified dataset + // Gets the floating-point datatype of the specified dataset. FloatType( const DataSet& dataset ); // Retrieves the exponent bias of a floating-point type. @@ -53,13 +53,13 @@ class H5_DLLCPP FloatType : public AtomType { // Sets the mantissa normalization of a floating-point datatype. void setNorm( H5T_norm_t norm ) const; - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("FloatType"); } // Default constructor FloatType(); - // Creates a floating-point datatype using an existing id + // Creates a floating-point datatype using an existing id. FloatType( const hid_t existing_id ); // Copy constructor: makes a copy of the original FloatType object. @@ -71,4 +71,4 @@ class H5_DLLCPP FloatType : public AtomType { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5FloatType_H diff --git a/c++/src/H5Group.cpp b/c++/src/H5Group.cpp index 6ec2dbb..d0231e3 100644 --- a/c++/src/H5Group.cpp +++ b/c++/src/H5Group.cpp @@ -99,33 +99,9 @@ Group::Group(const hid_t existing_id) : H5Object() /// is a datatype that has been named by DataType::commit. // Programmer Binh-Minh Ribler - Oct, 2006 //-------------------------------------------------------------------------- -Group::Group(H5Object& obj, const void* ref, H5R_type_t ref_type) : H5Object() +Group::Group(const H5Location& loc, const void* ref, H5R_type_t ref_type) : H5Object(), id(0) { - try { - id = p_dereference(obj.getId(), ref, ref_type); - } catch (ReferenceException deref_error) { - throw ReferenceException("Group constructor - located by an H5Object", - deref_error.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: Group overload constructor - dereference -///\brief Given a reference, ref, to an hdf5 group, creates a Group object -///\param h5file - IN: Location referenced object is in -///\param ref - IN: Reference pointer -///\param ref_type - IN: Reference type - default to H5R_OBJECT -///\exception H5::ReferenceException -// Programmer Binh-Minh Ribler - Oct, 2006 -//-------------------------------------------------------------------------- -Group::Group(H5File& h5file, const void* ref, H5R_type_t ref_type) : H5Object() -{ - try { - id = p_dereference(h5file.getId(), ref, ref_type); - } catch (ReferenceException deref_error) { - throw ReferenceException("Group constructor - located by an H5File", - deref_error.getDetailMsg()); - } + id = H5Location::p_dereference(loc.getId(), ref, ref_type, "constructor - by dereference"); } //-------------------------------------------------------------------------- @@ -137,66 +113,15 @@ Group::Group(H5File& h5file, const void* ref, H5R_type_t ref_type) : H5Object() ///\exception H5::ReferenceException // Programmer Binh-Minh Ribler - Oct, 2006 //-------------------------------------------------------------------------- -Group::Group(Attribute& attr, const void* ref, H5R_type_t ref_type) : H5Object() -{ - try { - id = p_dereference(attr.getId(), ref, ref_type); - } catch (ReferenceException deref_error) { - throw ReferenceException("Group constructor - located by an Attribute", - deref_error.getDetailMsg()); - } -} - -#ifndef H5_NO_DEPRECATED_SYMBOLS -//-------------------------------------------------------------------------- -// Function: Group::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, valid values are: -/// \li \c H5R_OBJECT - Reference is an object reference. -/// \li \c H5R_DATASET_REGION - Reference is a dataset region reference. -///\return An object type, which can be one of the following: -/// \li \c H5G_LINK (0) - Object is a symbolic link. -/// \li \c H5G_GROUP (1) - Object is a group. -/// \li \c H5G_DATASET (2) - Object is a dataset. -/// \li \c H5G_TYPE (3) - Object is a named datatype -///\exception H5::GroupIException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -H5G_obj_t Group::getObjType(void *ref, H5R_type_t ref_type) const -{ - try { - return(p_get_obj_type(ref, ref_type)); - } - catch (IdComponentException E) { - throw GroupIException("Group::getObjType", E.getDetailMsg()); - } -} -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - -//-------------------------------------------------------------------------- -// Function: Group::getRegion -///\brief Retrieves a dataspace with the region pointed to selected. -///\param ref - IN: Reference to get region of -///\param ref_type - IN: Type of reference to get region of - default -///\return DataSpace instance -///\exception H5::GroupIException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -DataSpace Group::getRegion(void *ref, H5R_type_t ref_type) const +Group::Group(const Attribute& attr, const void* ref, H5R_type_t ref_type) : H5Object(), id(0) { - try { - DataSpace dataspace(p_get_region(ref, ref_type)); - return(dataspace); - } - catch (IdComponentException E) { - throw GroupIException("Group::getRegion", E.getDetailMsg()); - } + id = H5Location::p_dereference(attr.getId(), ref, ref_type, "constructor - by dereference"); } //-------------------------------------------------------------------------- // Function: Group::getId -// Purpose: Get the id of this attribute +///\brief Get the id of this group +///\return Group identifier // Modification: // May 2008 - BMR // Class hierarchy is revised to address bugzilla 1068. Class @@ -210,6 +135,7 @@ hid_t Group::getId() const return(id); } +#ifndef DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: Group::p_setId ///\brief Sets the identifier of this object to a new value. @@ -234,6 +160,7 @@ void Group::p_setId(const hid_t new_id) // reset object's id to the given id id = new_id; } +#endif // DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: Group::close diff --git a/c++/src/H5Group.h b/c++/src/H5Group.h index 094b4a7..e3f1ddb 100644 --- a/c++/src/H5Group.h +++ b/c++/src/H5Group.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5Group_H -#define _H5Group_H +#ifndef __H5Group_H +#define __H5Group_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -26,15 +26,7 @@ class H5_DLLCPP Group : public H5Object, public CommonFG { // Close this group. virtual void close(); -#ifndef H5_NO_DEPRECATED_SYMBOLS - // Retrieves the type of object that an object reference points to. - H5G_obj_t getObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const; -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - - // Retrieves a dataspace with the region pointed to selected. - DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const; - - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("Group"); } // Throw group exception. @@ -44,9 +36,8 @@ class H5_DLLCPP Group : public H5Object, public CommonFG { virtual hid_t getLocId() const; // Creates a group by way of dereference. - Group(H5Object& obj, const void* ref, H5R_type_t ref_type = H5R_OBJECT); - Group(H5File& h5file, const void* ref, H5R_type_t ref_type = H5R_OBJECT); - Group(Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT); + Group(const H5Location& loc, const void* ref, H5R_type_t ref_type = H5R_OBJECT); + Group(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT); // default constructor Group(); @@ -67,10 +58,12 @@ class H5_DLLCPP Group : public H5Object, public CommonFG { hid_t id; // HDF5 group id protected: +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Sets the group id. virtual void p_setId(const hid_t new_id); +#endif // DOXYGEN_SHOULD_SKIP_THIS }; #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5Group_H diff --git a/c++/src/H5IdComponent.cpp b/c++/src/H5IdComponent.cpp index 9f96277..c60d05c 100644 --- a/c++/src/H5IdComponent.cpp +++ b/c++/src/H5IdComponent.cpp @@ -144,6 +144,8 @@ int IdComponent::getCounter() const //-------------------------------------------------------------------------- H5I_type_t IdComponent::getHDFObjType(const hid_t obj_id) { + if (obj_id == 0) + return H5I_BADID; // invalid H5I_type_t id_type = H5Iget_type(obj_id); if (id_type <= H5I_BADID || id_type >= H5I_NTYPES) return H5I_BADID; // invalid @@ -269,7 +271,7 @@ IdComponent::IdComponent() {} // 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. +// Attribute and H5Location subclasses. // Programmer Binh-Minh Ribler - Jul, 2004 //-------------------------------------------------------------------------- H5std_string IdComponent::p_get_file_name() const @@ -314,6 +316,9 @@ H5std_string IdComponent::p_get_file_name() const //-------------------------------------------------------------------------- bool IdComponent::p_valid_id(const hid_t obj_id) { + if (obj_id == 0) + return false; + H5I_type_t id_type = H5Iget_type(obj_id); if (id_type <= H5I_BADID || id_type >= H5I_NTYPES) return false; @@ -321,6 +326,14 @@ bool IdComponent::p_valid_id(const hid_t obj_id) return true; } +// Notes about IdComponent::id +// May 2008 - BMR +// Class hierarchy is revised to address bugzilla 1068... +// ...member IdComponent::id is moved into subclasses, and +// IdComponent::getId now becomes pure virtual function. +// (reasons: 1. encountered problems when adding H5Location; +// 2. Scott Meyers, item 33) + #endif // DOXYGEN_SHOULD_SKIP_THIS #ifndef H5_NO_NAMESPACE diff --git a/c++/src/H5IdComponent.h b/c++/src/H5IdComponent.h index 7dc1da3..5a61947 100644 --- a/c++/src/H5IdComponent.h +++ b/c++/src/H5IdComponent.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _IdComponent_H -#define _IdComponent_H +#ifndef __IdComponent_H +#define __IdComponent_H // IdComponent represents an HDF5 object that has an identifier. @@ -44,8 +44,10 @@ class H5_DLLCPP IdComponent { // Assignment operator. IdComponent& operator=( const IdComponent& rhs ); +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Gets the identifier of this object. virtual hid_t getId () const = 0; +#endif // DOXYGEN_SHOULD_SKIP_THIS // Sets the identifier of this object to a new value. void setId(const hid_t new_id); @@ -96,4 +98,4 @@ class H5_DLLCPP IdComponent { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __IdComponent_H diff --git a/c++/src/H5IntType.h b/c++/src/H5IntType.h index 3557c04..02efb64 100644 --- a/c++/src/H5IntType.h +++ b/c++/src/H5IntType.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5IntType_H -#define _H5IntType_H +#ifndef __H5IntType_H +#define __H5IntType_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -35,7 +35,7 @@ class H5_DLLCPP IntType : public AtomType { // Sets the sign proprety for an integer type. void setSign( H5T_sign_t sign ) const; - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("IntType"); } // Default constructor @@ -53,4 +53,4 @@ class H5_DLLCPP IntType : public AtomType { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5IntType_H diff --git a/c++/src/H5Library.h b/c++/src/H5Library.h index a3e1c99..c92a943 100644 --- a/c++/src/H5Library.h +++ b/c++/src/H5Library.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5Library_H -#define _H5Library_H +#ifndef __H5Library_H +#define __H5Library_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -67,4 +67,4 @@ class H5_DLLCPP H5Library { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5Library_H diff --git a/c++/src/H5Location.cpp b/c++/src/H5Location.cpp new file mode 100644 index 0000000..a527712 --- /dev/null +++ b/c++/src/H5Location.cpp @@ -0,0 +1,832 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include <string> + +#include "H5Include.h" +#include "H5Exception.h" +#include "H5IdComponent.h" +#include "H5PropList.h" +#include "H5Location.h" +#include "H5Object.h" +#include "H5DcreatProp.h" +#include "H5DxferProp.h" +#include "H5FaccProp.h" +#include "H5FcreatProp.h" +#include "H5CommonFG.h" +#include "H5DataType.h" +#include "H5DataSpace.h" +#include "H5AbstractDs.h" +#include "H5File.h" +#include "H5DataSet.h" +#include "H5Attribute.h" + +#ifndef H5_NO_NAMESPACE +namespace H5 { +#endif + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +// userAttrOpWrpr simply interfaces between the user's function and the +// C library function H5Aiterate2; used to resolve the different prototype +// problem. May be moved to Iterator later. +extern "C" herr_t userAttrOpWrpr(hid_t loc_id, const char *attr_name, + const H5A_info_t *ainfo, void *op_data) +{ + H5std_string s_attr_name = H5std_string( attr_name ); +#ifdef NO_STATIC_CAST + UserData4Aiterate* myData = (UserData4Aiterate *) op_data; +#else + UserData4Aiterate* myData = static_cast <UserData4Aiterate *> (op_data); +#endif + myData->op( *myData->location, s_attr_name, myData->opData ); + return 0; +} + +//-------------------------------------------------------------------------- +// Function: H5Location default constructor (protected) +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +H5Location::H5Location() : IdComponent() {} + +//-------------------------------------------------------------------------- +// Function: H5Location overloaded constructor (protected) +// Purpose Creates an H5Location object using the id of an existing HDF5 +// object. +// Parameters object_id - IN: Id of an existing HDF5 object +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +H5Location::H5Location(const hid_t object_id) : IdComponent(object_id) {} + +//-------------------------------------------------------------------------- +// Function: H5Location copy constructor +///\brief Copy constructor: makes a copy of the original H5Location +/// instance. +///\param original - IN: H5Location instance to copy +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +H5Location::H5Location( const H5Location& original ) : IdComponent( original ) {} + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +//-------------------------------------------------------------------------- +// Function: H5Location::createAttribute +///\brief Creates an attribute for a group, dataset, or named datatype. +///\param name - IN: Name of the attribute +///\param data_type - IN: Datatype for the attribute +///\param data_space - IN: Dataspace for the attribute - only simple +/// dataspaces are allowed at this time +///\param create_plist - IN: Creation property list - default to +/// PropList::DEFAULT +///\return Attribute instance +///\exception H5::AttributeIException +///\par Description +/// The attribute name specified in \a name must be unique. +/// Attempting to create an attribute with the same name as an +/// existing attribute will raise an exception, leaving the +/// pre-existing attribute intact. To overwrite an existing +/// attribute with a new attribute of the same name, first +/// delete the existing one with \c H5Location::removeAttr, then +/// recreate it with this function. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +Attribute H5Location::createAttribute( const char* name, const DataType& data_type, const DataSpace& data_space, const PropList& create_plist ) const +{ + hid_t type_id = data_type.getId(); + hid_t space_id = data_space.getId(); + hid_t plist_id = create_plist.getId(); + hid_t attr_id = H5Acreate2(getId(), name, type_id, space_id, plist_id, H5P_DEFAULT ); + + // If the attribute id is valid, create and return the Attribute object + if( attr_id > 0 ) + { + Attribute attr( attr_id ); + return( attr ); + } + else + throw AttributeIException(inMemFunc("createAttribute"), "H5Acreate2 failed"); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::createAttribute +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes +/// a reference to an \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +Attribute H5Location::createAttribute( const H5std_string& name, const DataType& data_type, const DataSpace& data_space, const PropList& create_plist ) const +{ + return( createAttribute( name.c_str(), data_type, data_space, create_plist )); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::openAttribute +///\brief Opens an attribute given its name. +///\param name - IN: Name of the attribute +///\return Attribute instance +///\exception H5::AttributeIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +Attribute H5Location::openAttribute( const char* name ) const +{ + hid_t attr_id = H5Aopen(getId(), name, H5P_DEFAULT); + if( attr_id > 0 ) + { + Attribute attr( attr_id ); + return( attr ); + } + else + { + throw AttributeIException(inMemFunc("openAttribute"), "H5Aopen failed"); + } +} + +//-------------------------------------------------------------------------- +// Function: H5Location::openAttribute +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes +/// a reference to an \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +Attribute H5Location::openAttribute( const H5std_string& name ) const +{ + return( openAttribute( name.c_str()) ); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::openAttribute +///\brief Opens an attribute given its index. +///\param idx - IN: Index of the attribute, a 0-based, non-negative integer +///\return Attribute instance +///\exception H5::AttributeIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +Attribute H5Location::openAttribute( const unsigned int idx ) const +{ + hid_t attr_id = H5Aopen_by_idx(getId(), ".", H5_INDEX_CRT_ORDER, + H5_ITER_INC, (hsize_t)idx, H5P_DEFAULT, H5P_DEFAULT); + if( attr_id > 0 ) + { + Attribute attr( attr_id ); + return( attr ); + } + else + { + throw AttributeIException(inMemFunc("openAttribute"), "H5Aopen_by_idx failed"); + } +} + +//-------------------------------------------------------------------------- +// Function: H5Location::iterateAttrs +///\brief Iterates a user's function over all the attributes of an H5 +/// object, which may be a group, dataset or named datatype. +///\param user_op - IN: User's function to operate on each attribute +///\param _idx - IN/OUT: Starting (IN) and ending (OUT) attribute indices +///\param op_data - IN: User's data to pass to user's operator function +///\return Returned value of the last operator if it was non-zero, or +/// zero if all attributes were processed +///\exception H5::AttributeIException +///\par Description +/// The signature of user_op is +/// void (*)(H5::H5Location&, H5std_string, void*). +/// For information, please refer to the C layer Reference Manual +/// at: +/// http://www.hdfgroup.org/HDF5/doc/RM/RM_H5A.html#Annot-Iterate +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +int H5Location::iterateAttrs( attr_operator_t user_op, unsigned *_idx, void *op_data ) +{ + // store the user's function and data + UserData4Aiterate* userData = new UserData4Aiterate; + userData->opData = op_data; + userData->op = user_op; + userData->location = this; + + // call the C library routine H5Aiterate2 to iterate the attributes + hsize_t idx = _idx ? (hsize_t)*_idx : 0; + int ret_value = H5Aiterate2(getId(), H5_INDEX_NAME, H5_ITER_INC, &idx, + userAttrOpWrpr, (void *) userData); + + // release memory + delete userData; + + if( ret_value >= 0 ) { + /* Pass back update index value to calling code */ + if (_idx) + *_idx = (unsigned)idx; + + return( ret_value ); + } + else // raise exception when H5Aiterate returns a negative value + throw AttributeIException(inMemFunc("iterateAttrs"), "H5Aiterate2 failed"); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::getNumAttrs +///\brief Returns the number of attributes attached to this HDF5 object. +///\return Number of attributes +///\exception H5::AttributeIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +int H5Location::getNumAttrs() const +{ + H5O_info_t oinfo; /* Object info */ + + if(H5Oget_info(getId(), &oinfo) < 0) + throw AttributeIException(inMemFunc("getNumAttrs"), "H5Oget_info failed"); + else + return( (int)oinfo.num_attrs ); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::removeAttr +///\brief Removes the named attribute from this object. +///\param name - IN: Name of the attribute to be removed +///\exception H5::AttributeIException +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +void H5Location::removeAttr( const char* name ) const +{ + herr_t ret_value = H5Adelete(getId(), name); + if( ret_value < 0 ) + throw AttributeIException(inMemFunc("removeAttr"), "H5Adelete failed"); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::removeAttr +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes +/// a reference to an \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +void H5Location::removeAttr( const H5std_string& name ) const +{ + removeAttr( name.c_str() ); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::renameAttr +///\brief Renames the named attribute from this object. +///\param oldname - IN: Name of the attribute to be renamed +///\param newname - IN: New name ame of the attribute +///\exception H5::AttributeIException +// Programmer Binh-Minh Ribler - Mar, 2005 +//-------------------------------------------------------------------------- +void H5Location::renameAttr(const char* oldname, const char* newname) const +{ + herr_t ret_value = H5Arename(getId(), oldname, newname); + if (ret_value < 0) + throw AttributeIException(inMemFunc("renameAttr"), "H5Arename failed"); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::renameAttr +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes +/// a reference to an \c H5std_string for the names. +// Programmer Binh-Minh Ribler - Mar, 2005 +//-------------------------------------------------------------------------- +void H5Location::renameAttr(const H5std_string& oldname, const H5std_string& newname) const +{ + renameAttr (oldname.c_str(), newname.c_str()); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::flush +///\brief Flushes all buffers associated with a location to disk. +///\param scope - IN: Specifies the scope of the flushing action, +/// which can be either of these values: +/// \li \c H5F_SCOPE_GLOBAL - Flushes the entire virtual file +/// \li \c H5F_SCOPE_LOCAL - Flushes only the specified file +///\exception H5::Exception +///\par Description +/// This location is used to identify the file to be flushed. +// Programmer Binh-Minh Ribler - 2012 +// Modification +// Sep 2012 - BMR +// Moved from H5File/H5Object +//-------------------------------------------------------------------------- +void H5Location::flush(H5F_scope_t scope) const +{ + herr_t ret_value = H5Fflush(getId(), scope); + if( ret_value < 0 ) + { + throw Exception(inMemFunc("flush"), "H5Fflush failed"); + } +} + +//-------------------------------------------------------------------------- +// Function: H5Location::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 +//-------------------------------------------------------------------------- +H5std_string H5Location::getFileName() const +{ + try { + return(p_get_file_name()); + } + catch (IdComponentException E) { + throw FileIException(inMemFunc("getFileName"), E.getDetailMsg()); + } +} + +//-------------------------------------------------------------------------- +// Function: H5Location::setComment +///\brief Sets or resets the comment for an object specified by its name. +///\param name - IN: Name of the object +///\param comment - IN: New comment +///\exception H5::Exception +///\par Description +/// If \a comment is an empty string or a null pointer, the comment +/// message is removed from the object. +/// Comments should be relatively short, null-terminated, ASCII +/// strings. They can be attached to any object that has an +/// object header, e.g., data sets, groups, named data types, +/// and data spaces, but not symbolic links. +// Programmer Binh-Minh Ribler - 2000 (moved from CommonFG, Sep 2013) +// Modification +// 2007: QAK modified to use H5O APIs; however the first parameter is +// no longer just file or group, this function should be moved +// to another class to accommodate attribute, dataset, and named +// datatype. - BMR +//-------------------------------------------------------------------------- +void H5Location::setComment(const char* name, const char* comment) const +{ + herr_t ret_value = H5Oset_comment_by_name(getId(), name, comment, H5P_DEFAULT); + if( ret_value < 0 ) + throw Exception(inMemFunc("setComment"), "H5Oset_comment_by_name failed"); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::setComment +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a name and \a comment. +// Programmer Binh-Minh Ribler - 2000 (moved from CommonFG, Sep 2013) +//-------------------------------------------------------------------------- +void H5Location::setComment(const H5std_string& name, const H5std_string& comment) const +{ + setComment(name.c_str(), comment.c_str()); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::setComment +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it doesn't take +/// an object name. +// Programmer Binh-Minh Ribler - Sep 2013 +// Modification +//-------------------------------------------------------------------------- +void H5Location::setComment(const char* comment) const +{ + herr_t ret_value = H5Oset_comment_by_name(getId(), ".", comment, H5P_DEFAULT); + if( ret_value < 0 ) + throw Exception(inMemFunc("setComment"), "H5Oset_comment_by_name failed"); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::setComment +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a comment. +// Programmer Binh-Minh Ribler - Sep 2013 +//-------------------------------------------------------------------------- +void H5Location::setComment(const H5std_string& comment) const +{ + setComment(comment.c_str()); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::removeComment +///\brief Removes the comment from an object specified by its name. +///\param name - IN: Name of the object +///\exception H5::Exception +// Programmer Binh-Minh Ribler - May 2005 (moved from CommonFG, Sep 2013) +// 2007: QAK modified to use H5O APIs; however the first parameter is +// no longer just file or group, this function should be moved +// to another class to accommodate attribute, dataset, and named +// datatype. - BMR +//-------------------------------------------------------------------------- +void H5Location::removeComment(const char* name) const +{ + herr_t ret_value = H5Oset_comment_by_name(getId(), name, NULL, H5P_DEFAULT); + if( ret_value < 0 ) + throw Exception(inMemFunc("removeComment"), "H5Oset_comment_by_name failed"); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::removeComment +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - May 2005 (moved from CommonFG, Sep 2013) +//-------------------------------------------------------------------------- +void H5Location::removeComment(const H5std_string& name) const +{ + removeComment (name.c_str()); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::getComment +///\brief Retrieves comment for the specified object and its comment's +/// length. +///\param name - IN: Name of the object +///\param bufsize - IN: Length of the comment to retrieve +///\return Comment string +///\exception H5::Exception +// Programmer Binh-Minh Ribler - 2000 (moved from CommonFG, Sep 2013) +// 2007: QAK modified to use H5O APIs; however the first parameter is +// no longer just file or group, this function should be moved +// to another class to accommodate attribute, dataset, and named +// datatype. - BMR +//-------------------------------------------------------------------------- +H5std_string H5Location::getComment(const char* name, size_t bufsize) const +{ + // bufsize is default to 256 + // temporary variable + hid_t loc_id = getId(); // temporary variable + + // temporary C-string for the object's comment; bufsize already including + // null character + char* comment_C = new char[bufsize]; + ssize_t ret_value = H5Oget_comment_by_name(loc_id, name, comment_C, bufsize, H5P_DEFAULT); + + // if the actual length of the comment is longer than bufsize and bufsize + // was the default value, i.e., not given by the user, then call + // H5Oget_comment_by_name again with the correct value. + // If the call to H5Oget_comment_by_name returned an error, skip this block + // and throw an exception below. + if (ret_value >= 0 && (size_t)ret_value > bufsize && bufsize == 256) + { + size_t new_size = ret_value; + delete []comment_C; + comment_C = new char[new_size]; // new_size including null terminator + ret_value = H5Oget_comment_by_name(loc_id, name, comment_C, new_size, H5P_DEFAULT); + } + + // if H5Oget_comment_by_name returns SUCCEED, return the string comment, + // otherwise, throw an exception + if (ret_value < 0) { + delete []comment_C; + throw Exception(inMemFunc("getComment"), "H5Oget_comment_by_name failed"); + } + + H5std_string comment = H5std_string(comment_C); + delete []comment_C; + return (comment); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::getComment +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a name. +// Programmer Binh-Minh Ribler - 2000 (moved from CommonFG, Sep 2013) +//-------------------------------------------------------------------------- +H5std_string H5Location::getComment(const H5std_string& name, size_t bufsize) const +{ + return(getComment(name.c_str(), bufsize)); +} +#ifndef DOXYGEN_SHOULD_SKIP_THIS + +//-------------------------------------------------------------------------- +// Function: H5Location::p_reference (protected) +// Purpose Creates a reference to an HDF5 object or a dataset region. +// Parameters +// name - IN: Name of the object to be referenced +// dataspace - IN: Dataspace with selection +// ref_type - IN: Type of reference; default to \c H5R_DATASET_REGION +// Exception H5::IdComponentException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void H5Location::p_reference(void* ref, const char* name, hid_t space_id, H5R_type_t ref_type) const +{ + herr_t ret_value = H5Rcreate(ref, getId(), name, ref_type, space_id); + if (ret_value < 0) + { + throw ReferenceException(inMemFunc("reference"), "H5Rcreate failed"); + } +} + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +//-------------------------------------------------------------------------- +// Function: H5Location::reference +///\brief Creates a reference to an HDF5 object or a dataset region. +///\param ref - IN: Reference pointer +///\param name - IN: Name of the object to be referenced +///\param dataspace - IN: Dataspace with selection +///\param ref_type - IN: Type of reference to query, valid values are: +/// \li \c H5R_OBJECT - Reference is an object reference. +/// \li \c H5R_DATASET_REGION - Reference is a dataset region +/// reference. (default) +///\exception H5::ReferenceException +///\notes This method is more suitable for a dataset region reference. +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void H5Location::reference(void* ref, const char* name, const DataSpace& dataspace, H5R_type_t ref_type) const +{ + try { + p_reference(ref, name, dataspace.getId(), ref_type); + } + catch (ReferenceException E) { + throw ReferenceException(inMemFunc("reference"), E.getDetailMsg()); + } +} + +//-------------------------------------------------------------------------- +// Function: H5Location::reference +///\brief This is an overloaded member function, provided for convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for \a name. +///\param ref - IN: Reference pointer +///\param name - IN: Name of the object to be referenced +///\param dataspace - IN: Dataspace with selection +///\param ref_type - IN: Type of reference to query, valid values are: +/// \li \c H5R_OBJECT - Reference is an object reference. +/// \li \c H5R_DATASET_REGION - Reference is a dataset region +/// reference. (default) +///\exception H5::ReferenceException +///\notes This method is more suitable for a dataset region reference. +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void H5Location::reference(void* ref, const H5std_string& name, const DataSpace& dataspace, H5R_type_t ref_type) const +{ + try { + p_reference(ref, name.c_str(), dataspace.getId(), ref_type); + } + catch (ReferenceException E) { + throw ReferenceException(inMemFunc("reference"), E.getDetailMsg()); + } +} + +//-------------------------------------------------------------------------- +// Function: H5Location::reference +///\brief This is an overloaded function, provided for your convenience. +/// It differs from the above function in that it does not take +/// a DataSpace object and the reference type must be specified. +///\param ref - IN: Reference pointer +///\param name - IN: Name of the object to be referenced +///\param ref_type - IN: Type of reference to query, valid values are: +/// \li \c H5R_OBJECT - Reference is an object reference (default) +/// \li \c H5R_DATASET_REGION - Reference is a dataset region +///\exception H5::ReferenceException +///\notes This method is more suitable for an object reference. +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void H5Location::reference(void* ref, const char* name, H5R_type_t ref_type) const +{ + try { + p_reference(ref, name, -1, ref_type); + } + catch (ReferenceException E) { + throw ReferenceException(inMemFunc("reference"), E.getDetailMsg()); + } +} + +//-------------------------------------------------------------------------- +// Function: H5Location::reference +///\brief This is an overloaded function, provided for your convenience. +/// It differs from the above function in that it takes an +/// \c H5std_string for the object's name. +///\param ref - IN: Reference pointer +///\param name - IN: Name of the object to be referenced - \c H5std_string +///\param ref_type - IN: Type of reference to query, valid values are: +/// \li \c H5R_OBJECT - Reference is an object reference (default) +/// \li \c H5R_DATASET_REGION - Reference is a dataset region +///\notes This method is more suitable for an object reference. +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +void H5Location::reference(void* ref, const H5std_string& name, H5R_type_t ref_type) const +{ + reference(ref, name.c_str(), ref_type); +} + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +//-------------------------------------------------------------------------- +// Function: H5Location::p_dereference (protected) +// Purpose Dereference a ref into an hdf5 object. +// Parameters +// loc_id - IN: An hdf5 identifier specifying the location of the +// referenced object +// ref - IN: Reference pointer +// ref_type - IN: Reference type +// Exception H5::ReferenceException +// Programmer Binh-Minh Ribler - Oct, 2006 +// Modification +// May 2008 - BMR +// Moved from IdComponent. +//-------------------------------------------------------------------------- +hid_t H5Location::p_dereference(hid_t loc_id, const void* ref, H5R_type_t ref_type, const char* from_func) +{ + hid_t temp_id = H5Rdereference(loc_id, ref_type, ref); + if (temp_id < 0) + { + throw ReferenceException(inMemFunc(from_func), "H5Rdereference failed"); + } + + return(temp_id); +} +#endif // DOXYGEN_SHOULD_SKIP_THIS + +//-------------------------------------------------------------------------- +// Function: H5Location::dereference +///\brief Dereferences a reference into an HDF5 object, given an HDF5 object. +///\param obj - IN: Object specifying the location of the referenced object +///\param ref - IN: Reference pointer +///\param ref_type - IN: Reference type +///\exception H5::ReferenceException +// Programmer Binh-Minh Ribler - Oct, 2006 +// Modification +// May, 2008 +// Corrected missing parameters. - BMR +//-------------------------------------------------------------------------- +void H5Location::dereference(const H5Location& loc, const void* ref, H5R_type_t ref_type) +{ + p_setId(p_dereference(loc.getId(), ref, ref_type, "dereference")); +} + +//-------------------------------------------------------------------------- +// Function: H5Location::dereference +///\brief Dereferences a reference into an HDF5 object, given an attribute. +///\param attr - IN: Attribute specifying the location of the referenced object +///\param ref - IN: Reference pointer +///\param ref_type - IN: Reference type +///\exception H5::ReferenceException +// Programmer Binh-Minh Ribler - Oct, 2006 +// Modification +// May, 2008 +// Corrected missing parameters. - BMR +//-------------------------------------------------------------------------- +void H5Location::dereference(const Attribute& attr, const void* ref, H5R_type_t ref_type) +{ + p_setId(p_dereference(attr.getId(), ref, ref_type, "dereference")); +} + +#ifndef H5_NO_DEPRECATED_SYMBOLS +//-------------------------------------------------------------------------- +// Function: H5Location::getObjType +///\brief Retrieves the type of object that an object reference points to. +///\param ref_type - IN: Type of reference to query, valid values are: +/// \li \c H5R_OBJECT - Reference is an object reference. +/// \li \c H5R_DATASET_REGION - Reference is a dataset region reference. +///\param ref - IN: Reference to query +///\return An object type, which can be one of the following: +/// \li \c H5G_UNKNOWN - A failure occurs. (-1) +/// \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_UDLINK - Object is a user-defined link. +///\exception H5::ReferenceException +// Programmer Binh-Minh Ribler - May, 2004 +// Modification +// Sep 2012: Moved up from H5File, Group, DataSet, and DataType +//-------------------------------------------------------------------------- +H5G_obj_t H5Location::getObjType(void *ref, H5R_type_t ref_type) const +{ + try { + return(p_get_obj_type(ref, ref_type)); + } + catch (ReferenceException E) { + throw ReferenceException(inMemFunc("getObjType"), E.getDetailMsg()); + } +} + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +//-------------------------------------------------------------------------- +// Function: H5Location::p_get_obj_type (protected) +// Purpose Retrieves the type of object that an object reference points to. +// Parameters +// ref - IN: Reference to query +// ref_type - IN: Type of reference to query +// Return An object type, which can be one of the following: +// H5G_UNKNOWN \tFailure occurs (-1) +// H5G_GROUP \tObject is a group. +// H5G_DATASET \tObject is a dataset. +// H5G_TYPE Object \tis a named datatype. +// H5G_LINK \tObject is a symbolic link. +// H5G_UDLINK \tObject is a user-defined link. +// Exception H5::ReferenceException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +H5G_obj_t H5Location::p_get_obj_type(void *ref, H5R_type_t ref_type) const +{ + H5G_obj_t obj_type = H5Rget_obj_type1(getId(), ref_type, ref); + + if (obj_type == H5G_UNKNOWN) + { + throw ReferenceException(inMemFunc("getObjType"), "H5Rget_obj_type1 failed"); + } + return(obj_type); +} +#endif // DOXYGEN_SHOULD_SKIP_THIS +#endif /* H5_NO_DEPRECATED_SYMBOLS */ + +//-------------------------------------------------------------------------- +// Function: H5Location::getRefObjType +///\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, valid values are: +/// \li \c H5R_OBJECT - Reference is an object reference. +/// \li \c H5R_DATASET_REGION - Reference is a dataset region reference. +///\return An object type, which can be one of the following: +/// \li \c H5O_TYPE_UNKNOWN - Unknown object type (-1) +/// \li \c H5O_TYPE_GROUP - Object is a group +/// \li \c H5O_TYPE_DATASET - Object is a dataset +/// \li \c H5O_TYPE_NAMED_DATATYPE - Object is a named datatype +/// \li \c H5O_TYPE_NTYPES - Number of different object types +///\exception H5::ReferenceException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +H5O_type_t H5Location::getRefObjType(void *ref, H5R_type_t ref_type) const +{ + try { + return(p_get_ref_obj_type(ref, ref_type)); + } + catch (ReferenceException E) { + throw ReferenceException(inMemFunc("getRefObjType"), E.getDetailMsg()); + } +} + +#ifndef DOXYGEN_SHOULD_SKIP_THIS +//-------------------------------------------------------------------------- +// Function: H5Location::p_get_ref_obj_type (protected) +// Purpose Retrieves the type of object that an object reference points to. +// Parameters +// ref - IN: Reference to query +// ref_type - IN: Type of reference to query +// Return An object type, which can be one of the following: +// H5O_TYPE_UNKNOWN - Unknown object type (-1) +// H5O_TYPE_GROUP - Object is a group +// H5O_TYPE_DATASET - Object is a dataset +// H5O_TYPE_NAMED_DATATYPE - Object is a named datatype +// H5O_TYPE_NTYPES - Number of object types +// Exception H5::ReferenceException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +H5O_type_t H5Location::p_get_ref_obj_type(void *ref, H5R_type_t ref_type) const +{ + H5O_type_t obj_type = H5O_TYPE_UNKNOWN; + herr_t ret_value = H5Rget_obj_type2(getId(), ref_type, ref, &obj_type); + + if (obj_type == H5O_TYPE_UNKNOWN || obj_type >= H5O_TYPE_NTYPES) + { + throw ReferenceException(inMemFunc("getRefObjType"), "H5Rget_obj_type2 failed"); + } + return(obj_type); +} + + +//-------------------------------------------------------------------------- +// Function: H5Location::getRegion +///\brief Retrieves a dataspace with the region pointed to selected. +///\param ref - IN: Reference to get region of +///\param ref_type - IN: Type of reference to get region of - default +// to H5R_DATASET_REGION +///\return DataSpace object +///\exception H5::ReferenceException +// Programmer Binh-Minh Ribler - May, 2004 +//-------------------------------------------------------------------------- +DataSpace H5Location::getRegion(void *ref, H5R_type_t ref_type) const +{ + hid_t space_id = H5Rget_region(getId(), ref_type, ref); + if (space_id < 0) + { + throw ReferenceException(inMemFunc("getRegion"), "H5Rget_region failed"); + } + try { + DataSpace dataspace(space_id); + return(dataspace); + } + catch (DataSpaceIException E) { + throw ReferenceException(inMemFunc("getRegion"), E.getDetailMsg()); + } +} + + +//-------------------------------------------------------------------------- +// Function: H5Location destructor +///\brief Noop destructor. +// Programmer Binh-Minh Ribler - 2000 +//-------------------------------------------------------------------------- +H5Location::~H5Location() {} + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +#ifndef H5_NO_NAMESPACE +} // end namespace +#endif diff --git a/c++/src/H5Location.h b/c++/src/H5Location.h new file mode 100644 index 0000000..3aadd50 --- /dev/null +++ b/c++/src/H5Location.h @@ -0,0 +1,167 @@ +// C++ informative line for the emacs editor: -*- C++ -*- +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Copyright by The HDF Group. * + * Copyright by the Board of Trustees of the University of Illinois. * + * All rights reserved. * + * * + * This file is part of HDF5. The full HDF5 copyright notice, including * + * terms governing use, modification, and redistribution, is contained in * + * the files COPYING and Copyright.html. COPYING can be found at the root * + * of the source code distribution tree; Copyright.html can be found at the * + * root level of an installed copy of the electronic HDF5 document set and * + * is linked from the top-level documents page. It can also be found at * + * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * + * access to either file, you may request a copy from help@hdfgroup.org. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef __H5Location_H +#define __H5Location_H + +#include "H5Classes.h" // constains forward class declarations + +// H5Location is an abstract class. It provides a collection of wrappers +// of C functions which take location IDs. Most of these were in H5Object +// but are now moved here for H5File's access. + +#ifndef H5_NO_NAMESPACE +namespace H5 { +#endif + +class H5_DLLCPP H5Location; // forward declaration for UserData4Aiterate + +// Define the operator function pointer for H5Aiterate(). +typedef void (*attr_operator_t)( H5Location& loc/*in*/, + const H5std_string attr_name/*in*/, + void *operator_data/*in,out*/); + +class UserData4Aiterate { // user data for attribute iteration + public: + attr_operator_t op; + void* opData; + H5Location* location; +}; + +// An H5Location can be a file, group, dataset, or committed datatype. + +class H5_DLLCPP H5Location : public IdComponent { + public: + // Creates an attribute for the specified object at this location + // 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; + Attribute createAttribute( const H5std_string& name, const DataType& type, const DataSpace& space, const PropList& create_plist = PropList::DEFAULT ) const; + + // Given its name, opens the attribute that belongs to an object at + // this location. + Attribute openAttribute( const char* name ) const; + Attribute openAttribute( const H5std_string& name ) const; + + // Given its index, opens the attribute that belongs to an object at + // this location. + Attribute openAttribute( const unsigned int idx ) const; + + // Flushes all buffers associated with this location to disk. + void flush( H5F_scope_t scope ) const; + + // Gets the name of the file, specified by this location. + H5std_string getFileName() const; + + // Determines the number of attributes at this location. + int getNumAttrs() const; + +#ifndef H5_NO_DEPRECATED_SYMBOLS + // Retrieves the type of object that an object reference points to. + H5G_obj_t getObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const; +#endif /* H5_NO_DEPRECATED_SYMBOLS */ + + // Retrieves the type of object that an object reference points to. + H5O_type_t getRefObjType(void *ref, H5R_type_t ref_type = H5R_OBJECT) const; + // Note: getRefObjType deprecates getObjType, but getObjType's name is + // misleading, so getRefObjType is used in the new function instead. + + // Iterate user's function over the attributes at this location. + int iterateAttrs(attr_operator_t user_op, unsigned* idx = NULL, void* op_data = NULL); + + // Checks whether the named attribute exists at this location. + bool attrExists(const char* name) const; + bool attrExists(const H5std_string& name) const; + + // Renames the named attribute to a new name. + void renameAttr(const char* oldname, const char* newname) const; + void renameAttr(const H5std_string& oldname, const H5std_string& newname) const; + + // Removes the named attribute from this location. + void removeAttr(const char* name) const; + void removeAttr(const H5std_string& name) const; + + // Sets the comment for an HDF5 object specified by its name. + void setComment(const char* name, const char* comment) const; + void setComment(const H5std_string& name, const H5std_string& comment) const; + void setComment(const char* comment) const; + void setComment(const H5std_string& comment) const; + + // Retrieves comment for the HDF5 object specified by its name. + H5std_string getComment(const char* name, size_t bufsize=256) const; + H5std_string getComment(const H5std_string& name, size_t bufsize=256) const; + + // Removes the comment for the HDF5 object specified by its name. + void removeComment(const char* name) const; + void removeComment(const H5std_string& name) const; + + // Creates a reference to a named object or to a dataset region + // in this object. + void reference(void* ref, const char* name, + H5R_type_t ref_type = H5R_OBJECT) const; + void reference(void* ref, const H5std_string& name, + H5R_type_t ref_type = H5R_OBJECT) const; + void reference(void* ref, const char* name, const DataSpace& dataspace, + H5R_type_t ref_type = H5R_DATASET_REGION) const; + void reference(void* ref, const H5std_string& name, const DataSpace& dataspace, + H5R_type_t ref_type = H5R_DATASET_REGION) const; + + // Open a referenced object whose location is specified by either + // a file, an HDF5 object, or an attribute. + void dereference(const H5Location& loc, const void* ref, H5R_type_t ref_type = H5R_OBJECT); + void dereference(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT); + + // Retrieves a dataspace with the region pointed to selected. + DataSpace getRegion(void *ref, H5R_type_t ref_type = H5R_DATASET_REGION) const; + + ///\brief Returns an identifier. (pure virtual) + virtual hid_t getId() const = 0; + + protected: +#ifndef DOXYGEN_SHOULD_SKIP_THIS + // Default constructor, + H5Location(); + + // Creates a copy of an existing object giving the location id. + H5Location(const hid_t loc_id); + + // Copy constructor. + H5Location(const H5Location& original); + + // Creates a reference to an HDF5 object or a dataset region. + void p_reference(void* ref, const char* name, hid_t space_id, H5R_type_t ref_type) const; + + // Dereferences a ref into an HDF5 id. + hid_t p_dereference(hid_t loc_id, const void* ref, H5R_type_t ref_type, const char* from_func); + +#ifndef H5_NO_DEPRECATED_SYMBOLS + // 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; +#endif /* H5_NO_DEPRECATED_SYMBOLS */ + + // Retrieves the type of object that an object reference points to. + H5O_type_t p_get_ref_obj_type(void *ref, H5R_type_t ref_type) const; + + // Noop destructor. + virtual ~H5Location(); + +#endif // DOXYGEN_SHOULD_SKIP_THIS + +}; /* end class H5Location */ + +#ifndef H5_NO_NAMESPACE +} +#endif +#endif // __H5Location_H diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index 225975b..1d96f2e 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -37,30 +37,11 @@ namespace H5 { #endif #ifndef DOXYGEN_SHOULD_SKIP_THIS -// userAttrOpWrpr simply interfaces between the user's function and the -// C library function H5Aiterate2; used to resolve the different prototype -// problem. May be moved to Iterator later. -extern "C" herr_t userAttrOpWrpr(hid_t loc_id, const char *attr_name, - const H5A_info_t *ainfo, void *op_data) -{ - H5std_string s_attr_name = H5std_string( attr_name ); -#ifdef NO_STATIC_CAST - UserData4Aiterate* myData = (UserData4Aiterate *) op_data; -#else - UserData4Aiterate* myData = static_cast <UserData4Aiterate *> (op_data); -#endif - myData->op( *myData->object, s_attr_name, myData->opData ); - return 0; -} - //-------------------------------------------------------------------------- // Function: H5Object default constructor (protected) -// Description -// 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(0) {} +H5Object::H5Object() : H5Location() {} //-------------------------------------------------------------------------- // Function: H5Object overloaded constructor (protected) @@ -69,9 +50,7 @@ H5Object::H5Object() : IdComponent(0) {} // 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 +H5Object::H5Object( const hid_t object_id ) : H5Location( object_id ) {} //-------------------------------------------------------------------------- // Function: H5Object copy constructor @@ -80,496 +59,7 @@ H5Object::H5Object( const hid_t object_id ) : IdComponent( object_id ) {} ///\param original - IN: H5Object instance to copy // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- -H5Object::H5Object( const H5Object& original ) : IdComponent( original ) {} - -//-------------------------------------------------------------------------- -// Function: H5Object::createAttribute -///\brief Creates an attribute for a group, dataset, or named datatype. -///\param name - IN: Name of the attribute -///\param data_type - IN: Datatype for the attribute -///\param data_space - IN: Dataspace for the attribute - only simple -/// dataspaces are allowed at this time -///\param create_plist - IN: Creation property list - default to -/// PropList::DEFAULT -///\return Attribute instance -///\exception H5::AttributeIException -///\par Description -/// The attribute name specified in \a name must be unique. -/// Attempting to create an attribute with the same name as an -/// existing attribute will raise an exception, leaving the -/// pre-existing attribute intact. To overwrite an existing -/// attribute with a new attribute of the same name, first -/// delete the existing one with \c H5Object::removeAttr, then -/// recreate it with this function. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -Attribute H5Object::createAttribute( const char* name, const DataType& data_type, const DataSpace& data_space, const PropList& create_plist ) const -{ - hid_t type_id = data_type.getId(); - hid_t space_id = data_space.getId(); - hid_t plist_id = create_plist.getId(); - hid_t attr_id = H5Acreate2(getId(), name, type_id, space_id, plist_id, H5P_DEFAULT ); - - // If the attribute id is valid, create and return the Attribute object - if( attr_id > 0 ) - { - Attribute attr( attr_id ); - return( attr ); - } - else - throw AttributeIException(inMemFunc("createAttribute"), "H5Acreate2 failed"); -} - -//-------------------------------------------------------------------------- -// Function: H5Object::createAttribute -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes -/// a reference to an \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -Attribute H5Object::createAttribute( const H5std_string& name, const DataType& data_type, const DataSpace& data_space, const PropList& create_plist ) const -{ - return( createAttribute( name.c_str(), data_type, data_space, create_plist )); -} - -//-------------------------------------------------------------------------- -// Function: H5Object::openAttribute -///\brief Opens an attribute given its name. -///\param name - IN: Name of the attribute -///\return Attribute instance -///\exception H5::AttributeIException -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -Attribute H5Object::openAttribute( const char* name ) const -{ - hid_t attr_id = H5Aopen(getId(), name, H5P_DEFAULT); - if( attr_id > 0 ) - { - Attribute attr( attr_id ); - return( attr ); - } - else - { - throw AttributeIException(inMemFunc("openAttribute"), "H5Aopen failed"); - } -} - -//-------------------------------------------------------------------------- -// Function: H5Object::openAttribute -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes -/// a reference to an \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -Attribute H5Object::openAttribute( const H5std_string& name ) const -{ - return( openAttribute( name.c_str()) ); -} - -//-------------------------------------------------------------------------- -// Function: H5Object::openAttribute -///\brief Opens an attribute given its index. -///\param idx - IN: Index of the attribute, a 0-based, non-negative integer -///\return Attribute instance -///\exception H5::AttributeIException -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -Attribute H5Object::openAttribute( const unsigned int idx ) const -{ - hid_t attr_id = H5Aopen_by_idx(getId(), ".", H5_INDEX_CRT_ORDER, - H5_ITER_INC, (hsize_t)idx, H5P_DEFAULT, H5P_DEFAULT); - if( attr_id > 0 ) - { - Attribute attr( attr_id ); - return( attr ); - } - else - { - throw AttributeIException(inMemFunc("openAttribute"), "H5Aopen_by_idx failed"); - } -} - -//-------------------------------------------------------------------------- -// Function: H5Object::iterateAttrs -///\brief Iterates a user's function over all the attributes of an H5 -/// object, which may be a group, dataset or named datatype. -///\param user_op - IN: User's function to operate on each attribute -///\param _idx - IN/OUT: Starting (IN) and ending (OUT) attribute indices -///\param op_data - IN: User's data to pass to user's operator function -///\return Returned value of the last operator if it was non-zero, or -/// zero if all attributes were processed -///\exception H5::AttributeIException -///\par Description -/// The signature of user_op is -/// void (*)(H5::H5Object&, H5std_string, void*). -/// For information, please refer to the C layer Reference Manual -/// at: -/// http://www.hdfgroup.org/HDF5/doc/RM/RM_H5A.html#Annot-Iterate -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -int H5Object::iterateAttrs( attr_operator_t user_op, unsigned *_idx, void *op_data ) -{ - // store the user's function and data - UserData4Aiterate* userData = new UserData4Aiterate; - userData->opData = op_data; - userData->op = user_op; - userData->object = this; - - // call the C library routine H5Aiterate2 to iterate the attributes - hsize_t idx = _idx ? (hsize_t)*_idx : 0; - int ret_value = H5Aiterate2(getId(), H5_INDEX_NAME, H5_ITER_INC, &idx, - userAttrOpWrpr, (void *) userData); - - // release memory - delete userData; - - if( ret_value >= 0 ) { - /* Pass back update index value to calling code */ - if (_idx) - *_idx = (unsigned)idx; - - return( ret_value ); - } - else // raise exception when H5Aiterate returns a negative value - throw AttributeIException(inMemFunc("iterateAttrs"), "H5Aiterate2 failed"); -} - -//-------------------------------------------------------------------------- -// Function: H5Object::getNumAttrs -///\brief Returns the number of attributes attached to this HDF5 object. -///\return Number of attributes -///\exception H5::AttributeIException -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -int H5Object::getNumAttrs() const -{ - H5O_info_t oinfo; /* Object info */ - - if(H5Oget_info(getId(), &oinfo) < 0) - throw AttributeIException(inMemFunc("getNumAttrs"), "H5Oget_info failed"); - else - return( (int)oinfo.num_attrs ); -} - -//-------------------------------------------------------------------------- -// Function: H5Object::removeAttr -///\brief Removes the named attribute from this object. -///\param name - IN: Name of the attribute to be removed -///\exception H5::AttributeIException -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -void H5Object::removeAttr( const char* name ) const -{ - herr_t ret_value = H5Adelete(getId(), name); - if( ret_value < 0 ) - throw AttributeIException(inMemFunc("removeAttr"), "H5Adelete failed"); -} - -//-------------------------------------------------------------------------- -// Function: H5Object::removeAttr -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes -/// a reference to an \c H5std_string for \a name. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -void H5Object::removeAttr( const H5std_string& name ) const -{ - removeAttr( name.c_str() ); -} - -//-------------------------------------------------------------------------- -// Function: H5Object::renameAttr -///\brief Renames the named attribute from this object. -///\param oldname - IN: Name of the attribute to be renamed -///\param newname - IN: New name ame of the attribute -///\exception H5::AttributeIException -// Programmer Binh-Minh Ribler - Mar, 2005 -//-------------------------------------------------------------------------- -void H5Object::renameAttr(const char* oldname, const char* newname) const -{ - herr_t ret_value = H5Arename(getId(), oldname, newname); - if (ret_value < 0) - throw AttributeIException(inMemFunc("renameAttr"), "H5Arename failed"); -} - -//-------------------------------------------------------------------------- -// Function: H5Object::renameAttr -///\brief This is an overloaded member function, provided for convenience. -/// It differs from the above function in that it takes -/// a reference to an \c H5std_string for the names. -// Programmer Binh-Minh Ribler - Mar, 2005 -//-------------------------------------------------------------------------- -void H5Object::renameAttr(const H5std_string& oldname, const H5std_string& newname) const -{ - renameAttr (oldname.c_str(), newname.c_str()); -} - -//-------------------------------------------------------------------------- -// Function: H5Object::flush -///\brief Flushes all buffers associated with a file to disk. -///\param scope - IN: Specifies the scope of the flushing action, -/// which can be either of these values: -/// \li \c H5F_SCOPE_GLOBAL - Flushes the entire virtual file -/// \li \c H5F_SCOPE_LOCAL - Flushes only the specified file -///\exception H5::AttributeIException -///\par Description -/// This object is used to identify the file to be flushed. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -void H5Object::flush(H5F_scope_t scope) const -{ - herr_t ret_value = H5Fflush(getId(), scope); - if( ret_value < 0 ) - { - throw FileIException(inMemFunc("flush"), "H5Fflush failed"); - } -} - -//-------------------------------------------------------------------------- -// 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 -//-------------------------------------------------------------------------- -H5std_string H5Object::getFileName() const -{ - try { - return(p_get_file_name()); - } - catch (IdComponentException E) { - throw FileIException(inMemFunc("getFileName"), E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: H5Object::p_reference (protected) -// Purpose Creates a reference to an HDF5 object or a dataset region. -// Parameters -// name - IN: Name of the object to be referenced -// dataspace - IN: Dataspace with selection -// ref_type - IN: Type of reference; default to \c H5R_DATASET_REGION -// Exception H5::IdComponentException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void H5Object::p_reference(void* ref, const char* name, hid_t space_id, H5R_type_t ref_type) const -{ - herr_t ret_value = H5Rcreate(ref, getId(), name, ref_type, space_id); - if (ret_value < 0) - { - throw IdComponentException("", "H5Rcreate failed"); - } -} - -//-------------------------------------------------------------------------- -// Function: H5Object::reference -///\brief Creates a reference to an HDF5 object or a dataset region. -///\param ref - IN: Reference pointer -///\param name - IN: Name of the object to be referenced -///\param dataspace - IN: Dataspace with selection -///\param ref_type - IN: Type of reference to query, valid values are: -/// \li \c H5R_OBJECT - Reference is an object reference. -/// \li \c H5R_DATASET_REGION - Reference is a dataset region -/// reference. - this is the default -///\exception H5::IdComponentException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void H5Object::reference(void* ref, const char* name, const DataSpace& dataspace, H5R_type_t ref_type) const -{ - try { - p_reference(ref, name, dataspace.getId(), ref_type); - } - catch (IdComponentException E) { - throw IdComponentException("H5Object::reference", E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: H5Object::reference -///\brief This is an overloaded function, provided for your convenience. -/// It differs from the above function in that it only creates -/// a reference to an HDF5 object, not to a dataset region. -///\param ref - IN: Reference pointer -///\param name - IN: Name of the object to be referenced - \c char pointer -///\exception H5::IdComponentException -///\par Description -// This function passes H5R_OBJECT and -1 to the protected -// function for it to pass to the C API H5Rcreate -// to create a reference to the named object. -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void H5Object::reference(void* ref, const char* name) const -{ - try { - p_reference(ref, name, -1, H5R_OBJECT); - } - catch (IdComponentException E) { - throw IdComponentException("H5Object::reference", E.getDetailMsg()); - } -} - -//-------------------------------------------------------------------------- -// Function: H5Object::reference -///\brief This is an overloaded function, provided for your convenience. -/// It differs from the above function in that it takes an -/// \c H5std_string for the object's name. -///\param ref - IN: Reference pointer -///\param name - IN: Name of the object to be referenced - \c H5std_string -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -void H5Object::reference(void* ref, const H5std_string& name) const -{ - reference(ref, name.c_str()); -} - -//-------------------------------------------------------------------------- -// Function: H5Object::p_dereference (protected) -// Purpose Dereference a ref into an hdf5 object. -// Parameters -// loc_id - IN: An hdf5 identifier specifying the location of the -// referenced object -// ref - IN: Reference pointer -// ref_type - IN: Reference type -// Exception H5::ReferenceException -// Programmer Binh-Minh Ribler - Oct, 2006 -// Modification -// May 2008 - BMR -// Moved from IdComponent. -//-------------------------------------------------------------------------- -hid_t H5Object::p_dereference(hid_t loc_id, const void* ref, H5R_type_t ref_type) -{ - hid_t temp_id; - temp_id = H5Rdereference(loc_id, ref_type, ref); - if (temp_id < 0) - { - throw ReferenceException("", "H5Rdereference failed"); - } - - // No failure, set id to the object - return(temp_id); -} - -//-------------------------------------------------------------------------- -// Function: H5Object::dereference -///\brief Dereferences a reference into an HDF5 object, given an HDF5 object. -///\param obj - IN: Object specifying the location of the referenced object -///\param ref - IN: Reference pointer -///\param ref_type - IN: Reference type -///\exception H5::ReferenceException -// Programmer Binh-Minh Ribler - Oct, 2006 -// Modification -// May, 2008 -// Corrected missing parameters. - BMR -//-------------------------------------------------------------------------- -void H5Object::dereference(H5Object& obj, const void* ref, H5R_type_t ref_type) -{ - hid_t temp_id; - try { - temp_id = p_dereference(obj.getId(), ref, ref_type); - } - catch (ReferenceException E) { - throw ReferenceException("H5Object::dereference - located by object", E.getDetailMsg()); - } - p_setId(temp_id); -} - -//-------------------------------------------------------------------------- -// Function: H5Object::dereference -///\brief Dereferences a reference into an HDF5 object, given an HDF5 file. -///\param h5file - IN: HDF5 file specifying the location of the referenced object -///\param ref - IN: Reference pointer -///\param ref_type - IN: Reference type -///\exception H5::ReferenceException -// Programmer Binh-Minh Ribler - Oct, 2006 -// Modification -// May, 2008 -// Corrected missing parameters. - BMR -//-------------------------------------------------------------------------- -void H5Object::dereference(H5File& h5file, const void* ref, H5R_type_t ref_type) -{ - hid_t temp_id; - try { - temp_id = p_dereference(h5file.getId(), ref, ref_type); - } - catch (ReferenceException E) { - throw ReferenceException("H5Object::dereference - located by file", E.getDetailMsg()); - } - p_setId(temp_id); -} - -//-------------------------------------------------------------------------- -// Function: H5Object::dereference -///\brief Dereferences a reference into an HDF5 object, given an attribute. -///\param attr - IN: Attribute specifying the location of the referenced object -///\param ref - IN: Reference pointer -///\param ref_type - IN: Reference type -///\exception H5::ReferenceException -// Programmer Binh-Minh Ribler - Oct, 2006 -// Modification -// May, 2008 -// Corrected missing parameters. - BMR -//-------------------------------------------------------------------------- -void H5Object::dereference(Attribute& attr, const void* ref, H5R_type_t ref_type) -{ - hid_t temp_id; - try { - temp_id = p_dereference(attr.getId(), ref, ref_type); - } - catch (ReferenceException E) { - throw ReferenceException("H5Object::dereference - located by attribute", E.getDetailMsg()); - } - p_setId(temp_id); -} - -#ifndef H5_NO_DEPRECATED_SYMBOLS -//-------------------------------------------------------------------------- -// Function: H5Object::p_get_obj_type (protected) -// Purpose Retrieves the type of object that an object reference points to. -// Parameters -// ref - IN: Reference to query -// ref_type - IN: Type of reference to query -// Return An object type, which can be one of the following: -// H5G_LINK Object is a symbolic link. -// H5G_GROUP Object is a group. -// H5G_DATASET Object is a dataset. -// H5G_TYPE Object is a named datatype -// Exception H5::IdComponentException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -H5G_obj_t H5Object::p_get_obj_type(void *ref, H5R_type_t ref_type) const -{ - H5G_obj_t obj_type = H5Rget_obj_type1(getId(), ref_type, ref); - - if (obj_type == H5G_UNKNOWN) - { - throw IdComponentException("", "H5Rget_obj_type failed"); - } - return(obj_type); -} -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - - -//-------------------------------------------------------------------------- -// Function: H5Object::p_get_region (protected) -// Purpose Retrieves a dataspace with the region pointed to selected. -// Parameters -// ref_type - IN: Type of reference to get region of - default -// to H5R_DATASET_REGION -// ref - IN: Reference to get region of -// Return Dataspace id -// Exception H5::IdComponentException -// Programmer Binh-Minh Ribler - May, 2004 -//-------------------------------------------------------------------------- -hid_t H5Object::p_get_region(void *ref, H5R_type_t ref_type) const -{ - hid_t space_id = H5Rget_region(getId(), ref_type, ref); - if (space_id < 0) - { - throw IdComponentException("", "H5Rget_region failed"); - } - return(space_id); -} - +H5Object::H5Object( const H5Object& original ) : H5Location( original ) {} //-------------------------------------------------------------------------- // Function: H5Object destructor @@ -577,6 +67,7 @@ hid_t H5Object::p_get_region(void *ref, H5R_type_t ref_type) const // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- H5Object::~H5Object() {} +#endif // DOXYGEN_SHOULD_SKIP_THIS #ifndef H5_NO_NAMESPACE } // end namespace diff --git a/c++/src/H5Object.h b/c++/src/H5Object.h index 4ac417b..3f9c343 100644 --- a/c++/src/H5Object.h +++ b/c++/src/H5Object.h @@ -14,84 +14,33 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5Object_H -#define _H5Object_H +#ifndef __H5Object_H +#define __H5Object_H +#include "H5Location.h" #include "H5Classes.h" // constains forward class declarations // H5Object is a baseclass. It has these subclasses: // Group, DataSet, and DataType. // DataType, in turn, has several specific datatypes as subclasses. +// Modification: +// Sept 18, 2012: Added class H5Location in between IdComponent and +// H5Object. An H5File now inherits from H5Location. All HDF5 +// wrappers in H5Object are moved up to H5Location. H5Object +// is left mostly empty for future wrappers that are only for +// group, dataset, and named datatype. Note that the reason for +// adding H5Location instead of simply moving H5File to be under +// H5Object is H5File is not an HDF5 object, and renaming H5Object +// to H5Location will risk breaking user applications. +// -BMR #ifndef H5_NO_NAMESPACE namespace H5 { #endif -#ifndef DOXYGEN_SHOULD_SKIP_THIS -class H5_DLLCPP H5Object; // forward declaration for UserData4Aiterate - -// Define the operator function pointer for H5Aiterate(). -typedef void (*attr_operator_t)( H5Object& loc/*in*/, - const H5std_string attr_name/*in*/, - void *operator_data/*in,out*/); - -class UserData4Aiterate { // user data for attribute iteration - public: - attr_operator_t op; - 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 { +class H5_DLLCPP H5Object : public H5Location { public: - // 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; - Attribute createAttribute( const H5std_string& name, const DataType& type, const DataSpace& space, const PropList& create_plist = PropList::DEFAULT ) const; - - // Opens an attribute given its name. - Attribute openAttribute( const char* name ) const; - Attribute openAttribute( const H5std_string& name ) const; - - // Opens an attribute given its index. - Attribute openAttribute( const unsigned int idx ) const; - - // 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. - H5std_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 H5std_string& name ) const; - - // Renames the attribute to a new name. - void renameAttr(const char* oldname, const char* newname) const; - void renameAttr(const H5std_string& oldname, const H5std_string& newname) const; - - // Creates a reference to a named Hdf5 object or to a dataset region - // in this object. - void reference(void* ref, const char* name, const DataSpace& dataspace, - H5R_type_t ref_type = H5R_DATASET_REGION) const; - void reference(void* ref, const char* name) const; - void reference(void* ref, const H5std_string& name) const; - - // Open a referenced HDF5 object whose location is specified by either - // a file, an HDF5 object, or an attribute. - void dereference(H5File& h5file, const void* ref, H5R_type_t ref_type = H5R_OBJECT); - void dereference(H5Object& obj, const void* ref, H5R_type_t ref_type = H5R_OBJECT); - void dereference(Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT); - +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Copy constructor: makes copy of an H5Object object. H5Object(const H5Object& original); @@ -99,30 +48,12 @@ class H5_DLLCPP H5Object : public IdComponent { 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 ); - // 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(void* ref, const char* name, hid_t space_id, H5R_type_t ref_type) const; - - // Dereferences a ref into an hdf5 id. - hid_t p_dereference(hid_t loc_id, const void* ref, H5R_type_t ref_type); - -#ifndef H5_NO_DEPRECATED_SYMBOLS - // 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; -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - - // 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 H5Object */ @@ -130,4 +61,4 @@ class H5_DLLCPP H5Object : public IdComponent { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5Object_H diff --git a/c++/src/H5PredType.cpp b/c++/src/H5PredType.cpp index 9dfc760..27cfd3a 100644 --- a/c++/src/H5PredType.cpp +++ b/c++/src/H5PredType.cpp @@ -56,6 +56,7 @@ PredType::PredType( const hid_t predtype_id ) : AtomType( predtype_id ) // Programmer Binh-Minh Ribler - 2000 //-------------------------------------------------------------------------- PredType::PredType() : AtomType() {} +#endif // DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: PredType copy constructor @@ -65,6 +66,7 @@ PredType::PredType() : AtomType() {} //-------------------------------------------------------------------------- PredType::PredType( const PredType& original ) : AtomType( original ) {} +#ifndef DOXYGEN_SHOULD_SKIP_THIS // Flag to terminate HDF5 library in DataType::~DataType const PredType PredType::AtExit(H5CPP_EXITED); diff --git a/c++/src/H5PredType.h b/c++/src/H5PredType.h index 9cb1c65..65e1c07 100644 --- a/c++/src/H5PredType.h +++ b/c++/src/H5PredType.h @@ -19,8 +19,8 @@ // closed by H5Tclose. They are treated as constants. ///////////////////////////////////////////////////////////////////// -#ifndef _H5PredType_H -#define _H5PredType_H +#ifndef __H5PredType_H +#define __H5PredType_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -32,11 +32,13 @@ namespace H5 { before the other PredType objects are created. At exit, when this special PredType object is to be destructed, no HDF5 library function will be called and the library will be terminated. -BMR, Mar 30, 2012 */ +#ifndef DOXYGEN_SHOULD_SKIP_THIS #define H5CPP_EXITED -3 // -3 is less likely to be used elsewhere +#endif // DOXYGEN_SHOULD_SKIP_THIS class H5_DLLCPP PredType : public AtomType { public: - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("PredType"); } // Makes a copy of the predefined type and stores the new @@ -256,4 +258,4 @@ class H5_DLLCPP PredType : public AtomType { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5PredType_H diff --git a/c++/src/H5PropList.cpp b/c++/src/H5PropList.cpp index ceea15f..9476d46 100644 --- a/c++/src/H5PropList.cpp +++ b/c++/src/H5PropList.cpp @@ -39,7 +39,7 @@ namespace H5 { //-------------------------------------------------------------------------- ///\brief Constant for default property. //-------------------------------------------------------------------------- -const PropList PropList::DEFAULT( H5P_DEFAULT ); +const PropList PropList::DEFAULT; //-------------------------------------------------------------------------- // Function Default constructor @@ -74,6 +74,9 @@ PropList::PropList(const PropList& original) : IdComponent(original) //-------------------------------------------------------------------------- PropList::PropList( const hid_t plist_id ) : IdComponent() { + if (plist_id == 0) + id = H5P_DEFAULT; + H5I_type_t id_type = H5Iget_type(plist_id); switch (id_type) { case H5I_GENPROP_CLS: @@ -216,7 +219,8 @@ void PropList::copyProp( PropList& dest, PropList& src, const H5std_string& name //-------------------------------------------------------------------------- // Function: PropList::getId -// Purpose: Get the id of this attribute +///\brief Get the id of this property list +///\return Property list identifier // Description: // Class hierarchy is revised to address bugzilla 1068. Class // AbstractDS and Attribute are moved out of H5Object. In @@ -229,6 +233,7 @@ hid_t PropList::getId() const return(id); } +#ifndef DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: PropList::p_setId ///\brief Sets the identifier of this object to a new value. @@ -253,6 +258,7 @@ void PropList::p_setId(const hid_t new_id) // reset object's id to the given id id = new_id; } +#endif // DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function: PropList::close diff --git a/c++/src/H5PropList.h b/c++/src/H5PropList.h index 2c079f9..b2c50d4 100644 --- a/c++/src/H5PropList.h +++ b/c++/src/H5PropList.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5PropList_H -#define _H5PropList_H +#ifndef __H5PropList_H +#define __H5PropList_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -94,7 +94,7 @@ class H5_DLLCPP PropList : public IdComponent { void removeProp(const char *name) const; void removeProp(const H5std_string& name) const; - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("PropList"); } // Default constructor: creates a stub PropList object. @@ -110,13 +110,15 @@ class H5_DLLCPP PropList : public IdComponent { virtual ~PropList(); protected: +#ifndef DOXYGEN_SHOULD_SKIP_THIS hid_t id; // HDF5 property list id // Sets the property list id. virtual void p_setId(const hid_t new_id); +#endif // DOXYGEN_SHOULD_SKIP_THIS }; #ifndef H5_NO_NAMESPACE } #endif -#endif // _H5PropList_H +#endif // __H5PropList_H diff --git a/c++/src/H5StrType.h b/c++/src/H5StrType.h index 8e79712..251b0b8 100644 --- a/c++/src/H5StrType.h +++ b/c++/src/H5StrType.h @@ -14,8 +14,8 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#ifndef _H5StrType_H -#define _H5StrType_H +#ifndef __H5StrType_H +#define __H5StrType_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -47,7 +47,7 @@ class H5_DLLCPP StrType : public AtomType { // Defines the storage mechanism for character strings. void setStrpad(H5T_str_t strpad) const; - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("StrType"); } // default constructor @@ -65,4 +65,4 @@ class H5_DLLCPP StrType : public AtomType { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5StrType_H diff --git a/c++/src/H5VarLenType.h b/c++/src/H5VarLenType.h index 688b2cc..caa347a 100644 --- a/c++/src/H5VarLenType.h +++ b/c++/src/H5VarLenType.h @@ -17,8 +17,8 @@ // Class VarLenType inherits from DataType and provides wrappers for // the HDF5 C's Variable-length Datatypes. -#ifndef _H5VarLenType_H -#define _H5VarLenType_H +#ifndef __H5VarLenType_H +#define __H5VarLenType_H #ifndef H5_NO_NAMESPACE namespace H5 { @@ -30,7 +30,7 @@ class H5_DLLCPP VarLenType : public DataType { // on the specified base type. VarLenType(const DataType* base_type); - ///\brief Returns this class name + ///\brief Returns this class name. virtual H5std_string fromClass () const { return("VarLenType"); } // Copy constructor: makes copy of the original object. @@ -49,4 +49,4 @@ class H5_DLLCPP VarLenType : public DataType { #ifndef H5_NO_NAMESPACE } #endif -#endif +#endif // __H5VarLenType_H diff --git a/c++/src/Makefile.am b/c++/src/Makefile.am index 6278fa0..ec942fd 100644 --- a/c++/src/Makefile.am +++ b/c++/src/Makefile.am @@ -40,12 +40,12 @@ bin_SCRIPTS=h5c++ # Source files for the library libhdf5_cpp_la_SOURCES=H5Exception.cpp H5IdComponent.cpp H5Library.cpp \ - H5Attribute.cpp H5Object.cpp H5PropList.cpp H5FaccProp.cpp \ - H5FcreatProp.cpp H5DcreatProp.cpp H5DxferProp.cpp H5DataType.cpp \ - H5DataSpace.cpp H5AbstractDs.cpp H5AtomType.cpp H5PredType.cpp \ - H5EnumType.cpp H5IntType.cpp H5FloatType.cpp H5StrType.cpp \ - H5ArrayType.cpp H5VarLenType.cpp H5CompType.cpp H5DataSet.cpp \ - H5CommonFG.cpp H5Group.cpp H5File.cpp + H5Attribute.cpp H5Location.cpp H5Object.cpp H5PropList.cpp \ + H5FaccProp.cpp H5FcreatProp.cpp H5DcreatProp.cpp H5DxferProp.cpp \ + H5DataType.cpp H5DataSpace.cpp H5AbstractDs.cpp H5AtomType.cpp \ + H5PredType.cpp H5EnumType.cpp H5IntType.cpp H5FloatType.cpp \ + H5StrType.cpp H5ArrayType.cpp H5VarLenType.cpp H5CompType.cpp \ + H5DataSet.cpp H5CommonFG.cpp H5Group.cpp H5File.cpp # HDF5 C++ library depends on HDF5 Library. libhdf5_cpp_la_LIBADD=$(LIBHDF5) @@ -55,8 +55,9 @@ include_HEADERS=H5Cpp.h H5AbstractDs.h H5AtomType.h H5Attribute.h H5Classes.h \ H5CommonFG.h H5CompType.h H5DataSet.h H5DataSpace.h H5DataType.h \ H5DcreatProp.h H5DxferProp.h H5EnumType.h H5Exception.h H5FaccProp.h \ H5FcreatProp.h H5File.h H5FloatType.h H5Group.h H5IdComponent.h \ - H5Include.h H5IntType.h H5Library.h H5Object.h H5PredType.h \ - H5PropList.h H5StrType.h H5CppDoc.h H5ArrayType.h H5VarLenType.h + H5Include.h H5IntType.h H5Library.h H5Location.h H5Object.h \ + H5PredType.h H5PropList.h H5StrType.h H5CppDoc.h H5ArrayType.h \ + H5VarLenType.h # h5c++ and libhdf5.settings are generated during configure. Remove only when # distclean. diff --git a/c++/src/Makefile.in b/c++/src/Makefile.in index d9fa6e3..3ef45c6 100644 --- a/c++/src/Makefile.in +++ b/c++/src/Makefile.in @@ -120,12 +120,12 @@ am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \ LTLIBRARIES = $(lib_LTLIBRARIES) libhdf5_cpp_la_DEPENDENCIES = $(LIBHDF5) am_libhdf5_cpp_la_OBJECTS = H5Exception.lo H5IdComponent.lo \ - H5Library.lo H5Attribute.lo H5Object.lo H5PropList.lo \ - H5FaccProp.lo H5FcreatProp.lo H5DcreatProp.lo H5DxferProp.lo \ - H5DataType.lo H5DataSpace.lo H5AbstractDs.lo H5AtomType.lo \ - H5PredType.lo H5EnumType.lo H5IntType.lo H5FloatType.lo \ - H5StrType.lo H5ArrayType.lo H5VarLenType.lo H5CompType.lo \ - H5DataSet.lo H5CommonFG.lo H5Group.lo H5File.lo + H5Library.lo H5Attribute.lo H5Location.lo H5Object.lo \ + H5PropList.lo H5FaccProp.lo H5FcreatProp.lo H5DcreatProp.lo \ + H5DxferProp.lo H5DataType.lo H5DataSpace.lo H5AbstractDs.lo \ + H5AtomType.lo H5PredType.lo H5EnumType.lo H5IntType.lo \ + H5FloatType.lo H5StrType.lo H5ArrayType.lo H5VarLenType.lo \ + H5CompType.lo H5DataSet.lo H5CommonFG.lo H5Group.lo H5File.lo libhdf5_cpp_la_OBJECTS = $(am_libhdf5_cpp_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -482,12 +482,12 @@ bin_SCRIPTS = h5c++ # Source files for the library libhdf5_cpp_la_SOURCES = H5Exception.cpp H5IdComponent.cpp H5Library.cpp \ - H5Attribute.cpp H5Object.cpp H5PropList.cpp H5FaccProp.cpp \ - H5FcreatProp.cpp H5DcreatProp.cpp H5DxferProp.cpp H5DataType.cpp \ - H5DataSpace.cpp H5AbstractDs.cpp H5AtomType.cpp H5PredType.cpp \ - H5EnumType.cpp H5IntType.cpp H5FloatType.cpp H5StrType.cpp \ - H5ArrayType.cpp H5VarLenType.cpp H5CompType.cpp H5DataSet.cpp \ - H5CommonFG.cpp H5Group.cpp H5File.cpp + H5Attribute.cpp H5Location.cpp H5Object.cpp H5PropList.cpp \ + H5FaccProp.cpp H5FcreatProp.cpp H5DcreatProp.cpp H5DxferProp.cpp \ + H5DataType.cpp H5DataSpace.cpp H5AbstractDs.cpp H5AtomType.cpp \ + H5PredType.cpp H5EnumType.cpp H5IntType.cpp H5FloatType.cpp \ + H5StrType.cpp H5ArrayType.cpp H5VarLenType.cpp H5CompType.cpp \ + H5DataSet.cpp H5CommonFG.cpp H5Group.cpp H5File.cpp # HDF5 C++ library depends on HDF5 Library. @@ -498,8 +498,9 @@ include_HEADERS = H5Cpp.h H5AbstractDs.h H5AtomType.h H5Attribute.h H5Classes.h H5CommonFG.h H5CompType.h H5DataSet.h H5DataSpace.h H5DataType.h \ H5DcreatProp.h H5DxferProp.h H5EnumType.h H5Exception.h H5FaccProp.h \ H5FcreatProp.h H5File.h H5FloatType.h H5Group.h H5IdComponent.h \ - H5Include.h H5IntType.h H5Library.h H5Object.h H5PredType.h \ - H5PropList.h H5StrType.h H5CppDoc.h H5ArrayType.h H5VarLenType.h + H5Include.h H5IntType.h H5Library.h H5Location.h H5Object.h \ + H5PredType.h H5PropList.h H5StrType.h H5CppDoc.h H5ArrayType.h \ + H5VarLenType.h # h5c++ and libhdf5.settings are generated during configure. Remove only when @@ -664,6 +665,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5IdComponent.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5IntType.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Library.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Location.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5Object.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5PredType.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/H5PropList.Plo@am__quote@ diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp index 58436f1..811d8c7 100644 --- a/c++/test/dsets.cpp +++ b/c++/test/dsets.cpp @@ -1058,7 +1058,7 @@ void test_dset() // Cause the library to emit initial messages Group grp = file.createGroup( "emit diagnostics", 0); - grp.setComment( ".", "Causes diagnostic messages to be emitted"); + grp.setComment("Causes diagnostic messages to be emitted"); nerrors += test_create(file)<0 ?1:0; nerrors += test_simple_io(file)<0 ?1:0; diff --git a/c++/test/h5cpputil.cpp b/c++/test/h5cpputil.cpp index 4485808..cd85b6e 100644 --- a/c++/test/h5cpputil.cpp +++ b/c++/test/h5cpputil.cpp @@ -100,12 +100,37 @@ void issue_fail_msg(const char* where, int line, const char* file_name, { //if (GetTestVerbosity()>=VERBO_HI) { + cerr << endl; cerr << ">>> FAILED in " << where << " at line " << line << " in " << file_name << " - " << message << endl << endl; } } /*------------------------------------------------------------------------- + * Function: issue_fail_msg + * + * Purpose: Displays that a function has failed with its location. + * + * Return: None + * + * Programmer: Binh-Minh Ribler (copied and modified macro CHECK from C) + * Monday, December 20, 2004 + * + *------------------------------------------------------------------------- + */ +void issue_fail_msg(const char* where, int line, const char* file_name, + const char* func_name, const char* message) +{ + //if (GetTestVerbosity()>=VERBO_HI) + { + cerr << endl; + cerr << ">>> FAILED in " << where << ": " << func_name << endl << + " at line " << line << " in " << file_name << endl << + " C library detail: " << message << endl << endl; + } +} + +/*------------------------------------------------------------------------- * Function: check_values * * Purpose: Checks a read value against the written value. If they are diff --git a/c++/test/h5cpputil.h b/c++/test/h5cpputil.h index 02f3d0d..e6aba79 100644 --- a/c++/test/h5cpputil.h +++ b/c++/test/h5cpputil.h @@ -42,6 +42,8 @@ int check_values (hsize_t i, hsize_t j, int apoint, int acheck); int test_report (int, const H5std_string&); void issue_fail_msg(const char* where, int line, const char* file_name, const char* message=""); +void issue_fail_msg(const char* where, int line, const char* file_name, + const char* func_name, const char* message); class InvalidActionException : public Exception { public: diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index 6bb9ca0..6f7674d 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -42,8 +42,13 @@ #include "h5cpputil.h" // C++ utilility header file -const H5std_string FILENAME("tattr.h5"); -const H5std_string ATTR_TMP_NAME("temp_name"); +const H5std_string FILE_BASIC("tattr_basic.h5"); +const H5std_string FILE_COMPOUND("tattr_compound.h5"); +const H5std_string FILE_SCALAR("tattr_scalar.h5"); +const H5std_string FILE_MULTI("tattr_multi.h5"); +const H5std_string FILE_DTYPE("tattr_dtype.h5"); +const H5std_string ATTR_TMP_NAME("temp_attr_name"); +const H5std_string FATTR_TMP_NAME("temp_fattr_name"); const size_t ATTR_MAX_DIMS = 7; /* 3-D dataset with fixed dimensions */ @@ -63,6 +68,10 @@ const int ATTR1_RANK = 1; const int ATTR1_DIM1 = 3; int attr_data1[ATTR1_DIM1]={512,-234,98123}; /* Test data for 1st attribute */ +// File attribute, using the same rank and dimensions as ATTR1_NAME's +const H5std_string FATTR1_NAME("File Attr1"); +const H5std_string FATTR2_NAME("File Attr2"); + const H5std_string ATTR2_NAME("Attr2"); const int ATTR2_RANK = 2; const int ATTR2_DIM1 = 2; @@ -121,7 +130,7 @@ static void test_attr_basic_write() try { // Create file - H5File fid1 (FILENAME, H5F_ACC_TRUNC); + H5File fid1 (FILE_BASIC, H5F_ACC_TRUNC); // Create dataspace for dataset DataSpace ds_space (SPACE1_RANK, dims1); @@ -136,6 +145,12 @@ static void test_attr_basic_write() // Create dataspace for attribute DataSpace att_space (ATTR1_RANK, dims2); + // Create a file attribute + Attribute file_attr2 = fid1.createAttribute (FATTR1_NAME, PredType::NATIVE_INT, att_space); + + // Create a file attribute + Attribute file_attr1 = fid1.createAttribute (FATTR2_NAME, PredType::NATIVE_INT, att_space); + // Create an attribute for the dataset Attribute ds_attr1 = dataset.createAttribute (ATTR1_NAME, PredType::NATIVE_INT, att_space); @@ -163,8 +178,9 @@ static void test_attr_basic_write() if(attr_data1[i]!=read_data1[i]) TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d,read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]); - // Create another attribute for this dataset - Attribute ds_attr2 = dataset.createAttribute (ATTR1A_NAME, PredType::NATIVE_INT, att_space); + // Create two more attributes for this dataset, but only write to one. + Attribute ds_attr2 = dataset.createAttribute (ATTR2_NAME, PredType::NATIVE_INT, att_space); + Attribute ds_attr3 = dataset.createAttribute (ATTR3_NAME, PredType::NATIVE_INT, att_space); // Write attribute information ds_attr2.write (PredType::NATIVE_INT, attr_data1a); @@ -180,6 +196,7 @@ static void test_attr_basic_write() // Close both attributes ds_attr1.close(); ds_attr2.close(); + ds_attr3.close(); /* * Test attribute with group @@ -240,14 +257,32 @@ static void test_attr_rename() try { // Open file - H5File fid1(FILENAME, H5F_ACC_RDWR); + H5File fid1(FILE_BASIC, H5F_ACC_RDWR); + + // Check rename of attribute belonging to a file + + // Change attribute name + fid1.renameAttr(FATTR1_NAME, FATTR_TMP_NAME); + + // Open attribute again + Attribute fattr1(fid1.openAttribute(FATTR_TMP_NAME)); + + // Verify new attribute name + H5std_string fattr_name = fattr1.getName(); + verify_val(fattr_name, FATTR_TMP_NAME, "Attribute::getName", __LINE__, __FILE__); + + int num_attrs = fid1.getNumAttrs(); + verify_val(num_attrs, 2, "Attribute::getNumAttrs", __LINE__, __FILE__); + + // Change first file attribute back to the original name + fid1.renameAttr(FATTR_TMP_NAME, FATTR1_NAME); // Open the dataset DataSet dataset = fid1.openDataSet(DSET1_NAME); - // Check rename + // Check rename of attribute belonging to a dataset - // change attribute name + // Change attribute name dataset.renameAttr(ATTR1_NAME, ATTR_TMP_NAME); // Open attribute again @@ -269,11 +304,11 @@ static void test_attr_rename() attr1.close(); // Open the second attribute - Attribute attr2(dataset.openAttribute(ATTR1A_NAME)); + Attribute attr2(dataset.openAttribute(ATTR2_NAME)); // Verify second attribute name H5std_string attr2_name = attr2.getName(); - verify_val(attr2_name, ATTR1A_NAME, "Attribute::getName", __LINE__, __FILE__); + verify_val(attr2_name, ATTR2_NAME, "Attribute::getName", __LINE__, __FILE__); // Read attribute information immediately, without closing attribute attr2.read (PredType::NATIVE_INT, read_data1); @@ -311,14 +346,14 @@ static void test_attr_basic_read() try { // Open file - H5File fid1(FILENAME, H5F_ACC_RDWR); + H5File fid1(FILE_BASIC, H5F_ACC_RDWR); // Open the dataset DataSet dataset = fid1.openDataSet(DSET1_NAME); // Verify the correct number of attributes int num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 2, "H5Object::getNumAttrs", __LINE__, __FILE__); + verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__); // Open an attribute for the dataset Attribute ds_attr=dataset.openAttribute(ATTR1_NAME); @@ -378,7 +413,7 @@ static void test_attr_compound_write() try { // Create file - H5File fid1(FILENAME.c_str(), H5F_ACC_TRUNC); + H5File fid1(FILE_COMPOUND.c_str(), H5F_ACC_TRUNC); // Create dataspace for dataset hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; @@ -442,14 +477,14 @@ static void test_attr_compound_read() try { // Open file - H5File fid1(FILENAME, H5F_ACC_RDWR); + H5File fid1(FILE_COMPOUND, H5F_ACC_RDWR); // Open the dataset DataSet dataset = fid1.openDataSet(DSET1_NAME); // Verify the correct number of attributes int num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 1, "H5Object::getNumAttrs", __LINE__, __FILE__); + verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__); // Open 1st attribute for the dataset Attribute attr = dataset.openAttribute((unsigned)0); @@ -571,7 +606,7 @@ static void test_attr_scalar_write() try { // Create file - H5File fid1(FILENAME, H5F_ACC_TRUNC); + H5File fid1(FILE_SCALAR, H5F_ACC_TRUNC); // Create dataspace for dataset hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; @@ -625,14 +660,14 @@ static void test_attr_scalar_read() try { // Open file - H5File fid1(FILENAME, H5F_ACC_RDWR); + H5File fid1(FILE_SCALAR, H5F_ACC_RDWR); // Open the dataset DataSet dataset = fid1.openDataSet(DSET1_NAME); // Verify the correct number of attributes int num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 1, "H5Object::getNumAttrs", __LINE__, __FILE__); + verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__); // Open an attribute for the dataset Attribute ds_attr=dataset.openAttribute(ATTR5_NAME); @@ -669,7 +704,7 @@ static void test_attr_mult_write() try { // Create file - H5File fid1 (FILENAME, H5F_ACC_TRUNC); + H5File fid1 (FILE_MULTI, H5F_ACC_TRUNC); // Create dataspace for dataset hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; @@ -746,14 +781,14 @@ static void test_attr_mult_read() try { // Open file - H5File fid1(FILENAME, H5F_ACC_RDWR); + H5File fid1(FILE_MULTI, H5F_ACC_RDWR); // Open the dataset DataSet dataset = fid1.openDataSet(DSET1_NAME); // Verify the correct number of attributes int num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 3, "H5Object::getNumAttrs", __LINE__, __FILE__); + verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__); // Open 1st attribute for the dataset Attribute attr = dataset.openAttribute((unsigned)0); @@ -929,22 +964,42 @@ static void test_attr_mult_read() static void test_attr_delete() { H5std_string attr_name; // Buffer for attribute names + int ii; - // Output message about test being performed + // Output message about test being performed SUBTEST("Removing Attribute Function"); try { - // Open file - H5File fid1(FILENAME, H5F_ACC_RDWR); + // Open file. + H5File fid1(FILE_BASIC, H5F_ACC_RDWR); + + // Get the number of file attributes + int num_attrs = fid1.getNumAttrs(); + verify_val(num_attrs, 2, "H5File::getNumAttrs", __LINE__, __FILE__); + + // Delete the second file attribute + fid1.removeAttr(FATTR2_NAME); + + // Get the number of file attributes + num_attrs = fid1.getNumAttrs(); + verify_val(num_attrs, 1, "H5File::getNumAttrs", __LINE__, __FILE__); + + // Verify the name of the only file attribute left + Attribute fattr = fid1.openAttribute((uint)0); + H5std_string attr_name = fattr.getName(); + verify_val(attr_name, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); + fattr.close(); + + // Test deleting non-existing attribute // Open the dataset DataSet dataset = fid1.openDataSet(DSET1_NAME); // Verify the correct number of attributes - int num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 3, "H5Object::getNumAttrs", __LINE__, __FILE__); + num_attrs = dataset.getNumAttrs(); + verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__); - // Try to delete bogus attribute, should fail. + // Try to delete bogus attribute, should fail try { dataset.removeAttr("Bogus"); @@ -954,16 +1009,18 @@ static void test_attr_delete() catch (AttributeIException E) // catching invalid removing attribute {} // do nothing, exception expected + // Test deleting dataset's attributes + // Verify the correct number of attributes num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 3, "H5Object::getNumAttrs", __LINE__, __FILE__); + verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__); // Delete middle (2nd) attribute dataset.removeAttr(ATTR2_NAME); // Verify the correct number of attributes num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 2, "H5Object::getNumAttrs", __LINE__, __FILE__); + verify_val(num_attrs, 2, "DataSet::getNumAttrs", __LINE__, __FILE__); // Open 1st attribute for the dataset Attribute attr = dataset.openAttribute((unsigned)0); @@ -989,9 +1046,9 @@ static void test_attr_delete() // Verify the correct number of attributes num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 1, "H5Object::getNumAttrs", __LINE__, __FILE__); + verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__); - // Open last (formally 3rd) attribute for the dataset + // Open the only attribute for the dataset (formally 3rd) attr = dataset.openAttribute((unsigned)0); // Verify Name @@ -1005,7 +1062,7 @@ static void test_attr_delete() // Verify the correct number of attributes num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 0, "H5Object::getNumAttrs", __LINE__, __FILE__); + verify_val(num_attrs, 0, "DataSet::getNumAttrs", __LINE__, __FILE__); PASSED(); } // end try block @@ -1035,19 +1092,19 @@ static void test_attr_dtype_shared() try { // Create a file - H5File fid1(FILENAME, H5F_ACC_TRUNC); + H5File fid1(FILE_DTYPE, H5F_ACC_TRUNC); // Close file fid1.close(); // Get size of file h5_stat_size_t empty_filesize; // Size of empty file - empty_filesize = h5_get_file_size(FILENAME.c_str(), H5P_DEFAULT); + empty_filesize = h5_get_file_size(FILE_DTYPE.c_str(), H5P_DEFAULT); if (empty_filesize < 0) TestErrPrintf("Line %d: file size wrong!\n", __LINE__); // Open the file again - fid1.openFile(FILENAME, H5F_ACC_RDWR); + fid1.openFile(FILE_DTYPE, H5F_ACC_RDWR); // Enclosing to work around the issue of unused variables and/or // objects created by copy constructors stay around until end of @@ -1120,7 +1177,7 @@ static void test_attr_dtype_shared() fid1.close(); // Open the file again - fid1.openFile(FILENAME, H5F_ACC_RDWR); + fid1.openFile(FILE_DTYPE, H5F_ACC_RDWR); { // Second enclosed block... @@ -1161,7 +1218,7 @@ static void test_attr_dtype_shared() fid1.close(); // Check size of file - filesize = h5_get_file_size(FILENAME.c_str(), H5P_DEFAULT); + filesize = h5_get_file_size(FILE_DTYPE.c_str(), H5P_DEFAULT); verify_val((long)filesize, (long)empty_filesize, "Checking file size", __LINE__, __FILE__); PASSED(); @@ -1192,7 +1249,7 @@ static void test_string_attr() try { // Create file - H5File fid1(FILENAME, H5F_ACC_RDWR); + H5File fid1(FILE_BASIC, H5F_ACC_RDWR); // // Fixed-lenth string attributes @@ -1349,6 +1406,6 @@ extern "C" #endif void cleanup_attr() { - HDremove(FILENAME.c_str()); + //HDremove(FILENAME.c_str()); } diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp index 765168c..65b7f11 100644 --- a/c++/test/tfile.cpp +++ b/c++/test/tfile.cpp @@ -140,7 +140,7 @@ static void test_file_create() // Test create with H5F_ACC_TRUNC. This will truncate the existing file. file1 = new H5File (FILE1, H5F_ACC_TRUNC); - // Try to truncate first file again. This should fail because file1 + // Try to create first file again. This should fail because file1 // is the same file and is currently open. Skip it on OpenVMS because // it creates another version of the file. #ifndef H5_HAVE_FILE_VERSIONS @@ -492,6 +492,116 @@ static void test_file_name() } // test_file_name() +#define NUM_OBJS 4 +#define NUM_ATTRS 3 +const int RANK1 = 1; +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 */ +static void test_file_attribute() +{ + int rdata[ATTR1_DIM1]; + int i; + + // Output message about test being performed + SUBTEST("File Attribute"); + + H5std_string file_name; + try { + // Create a file using default properties. + H5File file5(FILE5, H5F_ACC_TRUNC); + + // Create the data space + hsize_t dims[RANK1] = {ATTR1_DIM1}; + DataSpace space(RANK1, dims); + + // Create two attributes for the file + Attribute fattr1(file5.createAttribute(FATTR1_NAME, PredType::NATIVE_FLOAT, space)); + Attribute fattr2(file5.createAttribute(FATTR2_NAME, PredType::NATIVE_INT, space)); + + fattr2.write(PredType::NATIVE_INT, fattr_data); + + try { + // Try to create the same attribute again (should fail) + Attribute fattr_dup(file5.createAttribute(FATTR2_NAME, PredType::NATIVE_INT, space)); + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("H5File createAttribute", "Attempted to create an existing attribute."); + } + catch( AttributeIException E ) // catch creating existing attribute + {} // do nothing, FAIL expected + + // Create a new dataset + DataSet dataset(file5.createDataSet (DSETNAME, PredType::NATIVE_INT, space)); + + // Create an attribute for the dataset + Attribute dattr(dataset.createAttribute(DATTRNAME, PredType::NATIVE_INT, space)); + + // Write data to the second file attribute + dattr.write(PredType::NATIVE_INT, dattr_data); + + // Test flushing out the data from the attribute object + dattr.flush(H5F_SCOPE_GLOBAL); + + // Get and verify the number of all objects in the file + // Current: 1 file, 2 file attr, 1 ds, and 1 ds attr. + ssize_t num_objs = file5.getObjCount(H5F_OBJ_ALL); + verify_val(num_objs, 5, "H5File::getObjCount", __LINE__, __FILE__); + + num_objs = file5.getObjCount(H5F_OBJ_GROUP); + verify_val(num_objs, 0, "H5File::getObjCount(H5F_OBJ_GROUP)", __LINE__, __FILE__); + num_objs = file5.getObjCount(H5F_OBJ_DATASET); + verify_val(num_objs, 1, "H5File::getObjCount(H5F_OBJ_DATASET)", __LINE__, __FILE__); + num_objs = file5.getObjCount(H5F_OBJ_ATTR); + verify_val(num_objs, 3, "H5File::getObjCount(H5F_OBJ_ATTR)", __LINE__, __FILE__); + num_objs = file5.getObjCount(H5F_OBJ_DATATYPE); + verify_val(num_objs, 0, "H5File::getObjCount(H5F_OBJ_DATATYPE)", __LINE__, __FILE__); + num_objs = file5.getObjCount(H5F_OBJ_FILE); + verify_val(num_objs, 1, "H5File::getObjCount(H5F_OBJ_FILE)", __LINE__, __FILE__); + + // Get the file name using the attributes + H5std_string fname = fattr1.getFileName(); + verify_val(fname, FILE5, "H5File::getFileName()", __LINE__, __FILE__); + + fname.clear(); + fname = dattr.getFileName(); + verify_val(fname, FILE5, "H5File::getFileName()", __LINE__, __FILE__); + + // Get the class of a file attribute's datatype + H5T_class_t atclass = fattr1.getTypeClass(); + verify_val(atclass, H5T_FLOAT, "Attribute::getTypeClass()", __LINE__, __FILE__); + + // Get and verify the number of attributes attached to a file + int n_attrs = file5.getNumAttrs(); + verify_val(n_attrs, 2, "H5File::getNumAttrs()", __LINE__, __FILE__); + + // Get and verify the number of attributes attached to a dataset + n_attrs = 0; + n_attrs = dataset.getNumAttrs(); + verify_val(n_attrs, 1, "DataSet::getNumAttrs()", __LINE__, __FILE__); + + // Read back attribute's data + HDmemset(rdata, 0, sizeof(rdata)); + dattr.read(PredType::NATIVE_INT, rdata); + /* Check results */ + for (i = 0; i < ATTR1_DIM1; i++) { + if (rdata[i] != dattr_data[i]) { + H5_FAILED(); + cerr << endl; + cerr << "element [" << i << "] is " << rdata[i] << + "but should have been " << dattr_data[i] << endl; + } + } + PASSED(); + } // end of try block + + catch (Exception E) { + issue_fail_msg("test_file_name()", __LINE__, __FILE__, E.getCDetailMsg()); + } +} // test_file_attribute() + /*------------------------------------------------------------------------- * Function: test_file * @@ -518,6 +628,7 @@ void test_file() test_file_open(); // Test file opening test_file_size(); // Test file size test_file_name(); // Test getting file's name + test_file_attribute(); // Test file attribute feature } // test_file() diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp index dcb32dc..ae1ab02 100644 --- a/c++/test/trefer.cpp +++ b/c++/test/trefer.cpp @@ -27,13 +27,6 @@ #endif #include <string> -#ifndef H5_NO_NAMESPACE -#ifndef H5_NO_STD - using std::cerr; - using std::endl; -#endif // H5_NO_STD -#endif - #include "H5Cpp.h" // C++ API header file #ifndef H5_NO_NAMESPACE @@ -42,29 +35,31 @@ #include "h5cpputil.h" // C++ utilility header file +// File names const H5std_string FILE1("trefer1.h5"); const H5std_string FILE2("trefer2.h5"); -const H5std_string FILE3("trefer3.h5"); -const H5std_string DSET_DEFAULT_NAME("default"); -// Dataset 1 +// Dataset and datatype names const H5std_string DSET1_NAME("Dataset1"); -const int DSET1_LEN = 8; +const H5std_string DSET2_NAME("Dataset2"); +const H5std_string DSET3_NAME("Dataset3"); +const H5std_string DTYPE_NAME("Datatype1"); +// Compound type member names const H5std_string MEMBER1( "a_name" ); const H5std_string MEMBER2( "b_name" ); const H5std_string MEMBER3( "c_name" ); // 1-D dataset with fixed dimensions -const H5std_string SPACE1_NAME("Space1"); const int SPACE1_RANK = 1; const int SPACE1_DIM1 = 4; -// 2-D dataset with fixed dimensions -const H5std_string SPACE2_NAME("Space2"); +/* Larger 1-D dataset with fixed dimensions */ +const int SPACE3_RANK = 1; +const int SPACE3_DIM1 = 100; -// Larger 1-D dataset with fixed dimensions -const H5std_string SPACE3_NAME("Space3"); +/* Element selection information */ +const int POINT1_NPOINTS = 10; // Compound datatype typedef struct s1_t { @@ -75,8 +70,123 @@ typedef struct s1_t { /**************************************************************** ** -** test_reference_obj(): Test basic object reference functionality. -** Tests references to various kinds of objects +** test_reference_params(): Test basic H5R (reference) parameters +** for correct processing +** +****************************************************************/ +static void +test_reference_params(void) +{ + const char *write_comment = "Foo!"; /* Comments for group */ + + // Output message about test being performed + SUBTEST("Object Reference Parameters"); + + H5File* file1 = NULL; + try { + hobj_ref_t *wbuf, // buffer to write to disk + *rbuf, // buffer read from disk + *tbuf; // temp. buffer read from disk + + // Allocate write & read buffers + int temp_size = MAX(sizeof(unsigned),sizeof(hobj_ref_t)); + wbuf=(hobj_ref_t*)HDmalloc(temp_size*SPACE1_DIM1); + rbuf=(hobj_ref_t*)HDmalloc(temp_size*SPACE1_DIM1); + tbuf=(hobj_ref_t*)HDmalloc(temp_size*SPACE1_DIM1); + + // Create file FILE1 + file1 = new H5File (FILE1, H5F_ACC_TRUNC); + + // Create dataspace for datasets + hsize_t dims1[] = {SPACE1_DIM1}; + DataSpace sid1(SPACE1_RANK, dims1); + + // Create a group + Group group = file1->createGroup("Group1"); + + // Set group's comment + group.setComment(".", write_comment); + + // Create a dataset (inside /Group1) + DataSet dataset = group.createDataSet(DSET1_NAME, PredType::NATIVE_UINT, sid1); + + unsigned *tu32; // Temporary pointer to uint32 data + int i; + for (tu32=(unsigned *)wbuf, i=0; i<SPACE1_DIM1; i++) + *tu32++=i*3; // from C test + + // Write selection to disk + dataset.write(wbuf, PredType::NATIVE_UINT); + + // Close Dataset + dataset.close(); + + // Create another dataset (inside /Group1) + dataset = group.createDataSet(DSET2_NAME, PredType::NATIVE_UCHAR, sid1); + + // Close Dataset + dataset.close(); + + // Create a datatype to refer to + CompType dtype1(sizeof(s1_t)); + + // Insert fields + dtype1.insertMember(MEMBER1, HOFFSET(s1_t, a), PredType::NATIVE_INT); + dtype1.insertMember(MEMBER2, HOFFSET(s1_t, b), PredType::NATIVE_INT); + dtype1.insertMember(MEMBER3, HOFFSET(s1_t, c), PredType::NATIVE_FLOAT); + + // Save datatype for later + dtype1.commit(group, DTYPE_NAME); + + // Close datatype and group + dtype1.close(); + group.close(); + + // Create a dataset + dataset = file1->createDataSet(DSET3_NAME, PredType::STD_REF_OBJ, sid1); + + /* Test parameters to H5Location::reference */ + try { + file1->reference(NULL, "/Group1/Dataset1"); + } catch (ReferenceException E) {} // We expect this to fail + try { + file1->reference(&wbuf[0], NULL); + } catch (ReferenceException E) {} // We expect this to fail + try { + file1->reference(&wbuf[0], ""); + } catch (ReferenceException E) {} // We expect this to fail + try { + file1->reference(&wbuf[0], "/Group1/Dataset1", H5R_MAXTYPE); + } catch (ReferenceException E) {} // We expect this to fail + try { + file1->reference(&wbuf[0], "/Group1/Dataset1", H5R_DATASET_REGION); + } catch (ReferenceException E) {} // We expect this to fail + + // Close resources + dataset.close(); + file1->close(); + // Let sid1 go out of scope + + // Free memory buffers + HDfree(wbuf); + HDfree(rbuf); + HDfree(tbuf); + + PASSED(); + } // end try + catch (Exception E) { + issue_fail_msg("test_reference_param()",__LINE__,__FILE__, + E.getCFuncName(), E.getCDetailMsg()); + } + + if(file1) + delete file1; +} /* test_reference_param() */ + +/**************************************************************** +** +** test_reference_obj(): Test basic object reference functions +** to various kinds of objects ** ****************************************************************/ static void test_reference_obj(void) @@ -107,7 +217,7 @@ static void test_reference_obj(void) DataSpace sid1(SPACE1_RANK, dims1); // Create a group - Group group = file1->createGroup("Group1", (size_t)-1); + Group group = file1->createGroup("Group1"); // Set group's comment group.setComment(".", write_comment); @@ -116,7 +226,7 @@ static void test_reference_obj(void) DataSet dataset = group.createDataSet(DSET1_NAME, PredType::NATIVE_UINT, sid1); unsigned *tu32; // Temporary pointer to uint32 data - for (tu32=(unsigned *)wbuf, i=0; i<SPACE1_DIM1; i++) + for (tu32 = (unsigned *)wbuf, i = 0; i < SPACE1_DIM1; i++) *tu32++=i*3; // from C test // Write selection to disk @@ -126,7 +236,7 @@ static void test_reference_obj(void) dataset.close(); // Create another dataset (inside /Group1) - dataset = group.createDataSet("Dataset2", PredType::NATIVE_UCHAR, sid1); + dataset = group.createDataSet(DSET2_NAME, PredType::NATIVE_UCHAR, sid1); // Close Dataset dataset.close(); @@ -140,43 +250,34 @@ static void test_reference_obj(void) dtype1.insertMember(MEMBER3, HOFFSET(s1_t, c), PredType::NATIVE_FLOAT); // Save datatype for later - dtype1.commit(group, "Datatype1"); + dtype1.commit(group, DTYPE_NAME); // Close datatype and group dtype1.close(); group.close(); // Create a dataset - dataset = file1->createDataSet("Dataset3", PredType::STD_REF_OBJ, sid1); + dataset = file1->createDataSet(DSET3_NAME, PredType::STD_REF_OBJ, sid1); - // Create reference to dataset + // Create reference to dataset and test getRefObjType file1->reference(&wbuf[0], "/Group1/Dataset1"); + H5O_type_t refobj_type = dataset.getRefObjType(&wbuf[0], H5R_OBJECT); + verify_val(refobj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__); -#ifndef H5_NO_DEPRECATED_SYMBOLS - H5G_obj_t obj_type = dataset.getObjType(&wbuf[0], H5R_OBJECT); - verify_val(obj_type, H5G_DATASET, "DataSet::getObjType", __LINE__, __FILE__); -#endif /* H5_NO_DEPRECATED_SYMBOLS */ - - // Create reference to dataset + // Create reference to dataset and test getRefObjType file1->reference(&wbuf[1], "/Group1/Dataset2"); -#ifndef H5_NO_DEPRECATED_SYMBOLS - obj_type = dataset.getObjType(&wbuf[1], H5R_OBJECT); - verify_val(obj_type, H5G_DATASET, "DataSet::getObjType", __LINE__, __FILE__); -#endif /* H5_NO_DEPRECATED_SYMBOLS */ + refobj_type = dataset.getRefObjType(&wbuf[1], H5R_OBJECT); + verify_val(refobj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__); // Create reference to group file1->reference(&wbuf[2], "/Group1"); -#ifndef H5_NO_DEPRECATED_SYMBOLS - obj_type = dataset.getObjType(&wbuf[2], H5R_OBJECT); - verify_val(obj_type, H5G_GROUP, "DataSet::getObjType", __LINE__, __FILE__); -#endif /* H5_NO_DEPRECATED_SYMBOLS */ + refobj_type = dataset.getRefObjType(&wbuf[2], H5R_OBJECT); + verify_val(refobj_type, H5O_TYPE_GROUP, "DataSet::getRefObjType",__LINE__,__FILE__); // Create reference to named datatype file1->reference(&wbuf[3], "/Group1/Datatype1"); -#ifndef H5_NO_DEPRECATED_SYMBOLS - obj_type = dataset.getObjType(&wbuf[3], H5R_OBJECT); - verify_val(obj_type, H5G_TYPE, "DataSet::getObjType", __LINE__, __FILE__); -#endif /* H5_NO_DEPRECATED_SYMBOLS */ + refobj_type = dataset.getRefObjType(&wbuf[3], H5R_OBJECT); + verify_val(refobj_type, H5O_TYPE_NAMED_DATATYPE, "DataSet::getRefObjType",__LINE__,__FILE__); // Write selection to disk dataset.write(wbuf, PredType::STD_REF_OBJ); @@ -190,25 +291,25 @@ static void test_reference_obj(void) file1 = new H5File(FILE1, H5F_ACC_RDWR); // Open the dataset - dataset = file1->openDataSet("/Dataset3"); + dataset = file1->openDataSet(DSET3_NAME); // Read selection from disk dataset.read(rbuf, PredType::STD_REF_OBJ); // Dereference dataset object by ctor, from the location where // 'dataset' is located - DataSet dset2(dataset, &rbuf[0]); + DataSet dset2(dataset, &rbuf[0], H5R_OBJECT); // Check information in the referenced dataset sid1 = dset2.getSpace(); hssize_t n_elements = sid1.getSimpleExtentNpoints(); - verify_val((long)n_elements, 4, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); + verify_val((long)n_elements, 4, "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); // Read from disk dset2.read(tbuf, PredType::NATIVE_UINT); - for(tu32=(unsigned *)tbuf,i=0; i<SPACE1_DIM1; i++,tu32++) - verify_val(*tu32, (uint32_t)(i*3), "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); + for(tu32 = (unsigned *)tbuf, i = 0; i < SPACE1_DIM1; i++, tu32++) + verify_val(*tu32, (uint32_t)(i*3), "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); // Close dereferenced dataset dset2.close(); @@ -218,7 +319,7 @@ static void test_reference_obj(void) // Get group's comment H5std_string read_comment1 = group.getComment(".", 10); - verify_val(read_comment1, write_comment, "Group::getComment", __LINE__, __FILE__); + verify_val(read_comment1.c_str(), write_comment, "Group::getComment",__LINE__,__FILE__); // Test that getComment handles failures gracefully try { @@ -226,96 +327,29 @@ static void test_reference_obj(void) } catch (Exception E) {} // We expect this to fail - // Test reading the name of an item in the group - - // Test getObjnameByIdx(idx) - H5std_string name; - name = group.getObjnameByIdx(0); - verify_val(name, DSET1_NAME, "Group::getObjnameByIdx", __LINE__, __FILE__); - // Test getObjnameByIdx(hsize_t idx, H5std_string& name, size_t size) - name.clear(); - ssize_t name_size = group.getObjnameByIdx(0, name, 5); - verify_val(name, "Data", "Group::getObjnameByIdx(index,(std::string)buf,buf_len)", __LINE__, __FILE__); - verify_val(name_size, DSET1_LEN, "Group::getObjnameByIdx(index,(std::string)buf,buf_len)", __LINE__, __FILE__); - - name.clear(); - name_size = group.getObjnameByIdx(0, name, name_size+1); - verify_val(name, DSET1_NAME, "Group::getObjnameByIdx(index,(std::string)buf,buf_len)", __LINE__, __FILE__); - verify_val(name_size, DSET1_LEN, "Group::getObjnameByIdx(index,(std::string)buf,buf_len)", __LINE__, __FILE__); - - // Test getObjnameByIdx(hsize_t idx, char* name, size_t size) - group.getObjnameByIdx(0, name, name_size+1); - verify_val(name, DSET1_NAME, "Group::getObjnameByIdx(index,(char*)buf,buf_len)", __LINE__, __FILE__); - verify_val(name_size, DSET1_LEN, "Group::getObjnameByIdx(index,(char*)buf,buf_len)", __LINE__, __FILE__); - -#ifndef H5_NO_DEPRECATED_SYMBOLS - // Test getting the type of objects - - // Test getObjTypeByIdx(hsize_t idx) - obj_type = group.getObjTypeByIdx(0); - verify_val(obj_type, H5G_DATASET, "Group::getObjTypeByIdx(index)", __LINE__, __FILE__); - - // Test getObjTypeByIdx(hsize_t idx, char* type_name) - obj_type = H5G_UNKNOWN; - char type_name_C[256]; - obj_type = group.getObjTypeByIdx(0, type_name_C); - verify_val(obj_type, H5G_DATASET, "Group::getObjTypeByIdx(index, (char*)name)", __LINE__, __FILE__); - verify_val((const char*)type_name_C, (const char*)"dataset", "Group::getObjTypeByIdx(index, (char*)name)", __LINE__, __FILE__); - - // Test getObjTypeByIdx(hsize_t idx, H5std_string& type_name) - obj_type = H5G_UNKNOWN; - H5std_string type_name; - obj_type = group.getObjTypeByIdx(0, type_name); - verify_val(obj_type, H5G_DATASET, "Group::getObjTypeByIdx(index, (char*)name)", __LINE__, __FILE__); - verify_val(type_name, "dataset", "Group::getObjTypeByIdx(index, (char*)name)", __LINE__, __FILE__); - -#endif // ifndef H5_NO_DEPRECATED_SYMBOLS - // Close group group.close(); - // Dereference group object using file to specify location - group.dereference(*file1, &rbuf[2]); - H5std_string read_comment2 = group.getComment(".", 10); - verify_val(read_comment2, write_comment, "Group::getComment", __LINE__, __FILE__); - group.close(); - - // Dereference group object by ctor and using dataset to specify - // location - Group new_group(dataset, &rbuf[2]); - H5std_string read_comment3 = new_group.getComment(".", 10); - verify_val(read_comment3, write_comment, "Group::getComment", __LINE__, __FILE__); - new_group.close(); - - // Dereference datatype object from the location where 'dataset' - // is located + /* + * Verify correct referenced datatype + */ + // Open datatype object dtype1.dereference(dataset, &rbuf[3]); // Verify correct datatype - H5T_class_t tclass = dtype1.getClass(); - verify_val(tclass, H5T_COMPOUND, "DataType::getClass", __LINE__, __FILE__); + H5T_class_t tclass; + tclass = dtype1.getClass(); + verify_val(tclass, H5T_COMPOUND, "DataType::getClass",__LINE__,__FILE__); int n_members = dtype1.getNmembers(); - verify_val(n_members, 3, "DataType::getNmembers", __LINE__, __FILE__); + verify_val(n_members, 3, "CompType::getNmembers",__LINE__,__FILE__); - // Close datatype + // Close all objects and file dtype1.close(); - - // Dereference datatype object by ctor, using file to specify location - DataType dtype2(*file1, &rbuf[3]); - - // Verify correct datatype - H5T_class_t tclass2 = dtype2.getClass(); - verify_val(tclass2, H5T_COMPOUND, "DataType::getClass", __LINE__, __FILE__); - - // Close datatype - dtype2.close(); - - // Close dataset and file dataset.close(); file1->close(); - // Free memory buffers + // Free allocated buffers HDfree(wbuf); HDfree(rbuf); HDfree(tbuf); @@ -323,13 +357,440 @@ static void test_reference_obj(void) PASSED(); } // end try catch (Exception E) { - issue_fail_msg("test_reference_obj()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_reference_obj()",__LINE__,__FILE__, + E.getCFuncName(), E.getCDetailMsg()); } if(file1) delete file1; } // test_reference_obj() + +/**************************************************************** +** +** test_reference_group(): Test object reference functionality +** Tests for correct behavior of various routines on +** dereferenced group +** +****************************************************************/ +#define GROUPNAME "/group" +#define GROUPNAME2 "group2" +#define GROUPNAME3 "group3" +#define DSETNAME "/dset" +#define DSETNAME2 "dset2" +#define NAME_SIZE 16 + +static void +test_reference_group(void) +{ + hobj_ref_t wref; /* Reference to write */ + hobj_ref_t rref; /* Reference to read */ + const H5std_string write_comment="Foo!"; // Comments for group + + // Output message about test being performed + SUBTEST("Object Reference to Group"); + + H5File* file1 = NULL; + try { + /* + * Create file with a group and a dataset containing an object + * reference to the group + */ + + // Create file FILE1 + file1 = new H5File (FILE1, H5F_ACC_TRUNC); + + // Create scalar dataspace + DataSpace sid1; + + // Create a group + Group group = file1->createGroup(GROUPNAME); + + /* Create nested groups */ + Group group2 = group.createGroup(GROUPNAME2); + group2.close(); + group2 = group.createGroup(GROUPNAME3); + group2.close(); + + // Create bottom dataset + DataSet dset1 = group.createDataSet(DSETNAME2, PredType::NATIVE_INT, sid1); + dset1.close(); + + // Close group 1 + group.close(); + + // Create dataset + DataSet dset2 = file1->createDataSet(DSETNAME, PredType::STD_REF_OBJ, sid1); + + file1->reference(&wref, GROUPNAME); + + // Write selection to disk + dset2.write(&wref, PredType::STD_REF_OBJ); + + // Close resources + dset2.close(); + sid1.close(); + file1->close(); + + /* + * Re-open the file and test deferencing group + */ + + // Re-open file + file1->openFile(FILE1, H5F_ACC_RDWR); + + // Re-open dataset + dset1 = file1->openDataSet(DSETNAME); + + // Read in the reference + dset1.read(&rref, PredType::STD_REF_OBJ); + + // Dereference to get the group + Group refgroup(dset1, &rref); + + // Dereference group object the other way + group.dereference(dset1, &rref); + + /* + * Various queries on the group opened + */ + + // Check number of objects in the group dereferenced by constructor + hsize_t nobjs = refgroup.getNumObjs(); + verify_val(nobjs, 3, "H5Group::getNumObjs",__LINE__,__FILE__); + + // Check number of objects in the group dereferenced by ::reference + nobjs = group.getNumObjs(); + verify_val(nobjs, 3, "H5Group::getNumObjs",__LINE__,__FILE__); + + // Check getting file name given the group dereferenced via constructor + H5std_string fname = refgroup.getFileName(); + verify_val(fname, FILE1, "H5Group::getFileName",__LINE__,__FILE__); + + // Check getting file name given the group dereferenced by ::reference + fname = group.getFileName(); + verify_val(fname, FILE1, "H5Group::getFileName",__LINE__,__FILE__); + + // Unlink one of the objects in the dereferenced group, and re-check + refgroup.unlink(GROUPNAME2); + nobjs = refgroup.getNumObjs(); + verify_val(nobjs, 2, "H5Group::getNumObjs",__LINE__,__FILE__); + + // Close resources + group.close(); + refgroup.close(); + dset1.close(); + file1->close(); + + PASSED(); + } // end try + catch (Exception E) { + issue_fail_msg("test_reference_group()",__LINE__,__FILE__, + E.getCFuncName(), E.getCDetailMsg()); + } + + if(file1) + delete file1; +} /* test_reference_group() */ + +/**************************************************************** +** +** test_reference_region_1D(): Test 1-D reference functionality +** Tests 1-D references to various kinds of objects +** +****************************************************************/ +static void +test_reference_region_1D(void) +{ + hsize_t start[SPACE3_RANK]; /* Starting location of hyperslab */ + hsize_t stride[SPACE3_RANK]; /* Stride of hyperslab */ + hsize_t count[SPACE3_RANK]; /* Element count of hyperslab */ + hsize_t block[SPACE3_RANK]; /* Block size of hyperslab */ + hsize_t coord1[POINT1_NPOINTS][SPACE3_RANK]; /* Coordinates for point selection */ + hsize_t * coords; /* Coordinate buffer */ + hsize_t low[SPACE3_RANK]; /* Selection bounds */ + hsize_t high[SPACE3_RANK]; /* Selection bounds */ + int i; /* counting variables */ + + // Output message about test being performed + SUBTEST("1-D Dataset Region Reference Functions"); + + try { + hdset_reg_ref_t *wbuf, // buffer to write to disk + *rbuf; // buffer read from disk + uint8_t *dwbuf, // Buffer for writing numeric data to disk + *drbuf; // Buffer for reading numeric data from disk + + // Allocate write & read buffers + wbuf = (hdset_reg_ref_t *)HDcalloc(sizeof(hdset_reg_ref_t), (size_t)SPACE1_DIM1); + rbuf = (hdset_reg_ref_t *)HDmalloc(sizeof(hdset_reg_ref_t) * SPACE1_DIM1); + dwbuf = (uint8_t *)HDmalloc(sizeof(uint8_t) * SPACE3_DIM1); + drbuf = (uint8_t *)HDcalloc(sizeof(uint8_t), (size_t)SPACE3_DIM1); + + // Create file FILE1 + H5File file1(FILE2, H5F_ACC_TRUNC); + + // Create dataspace for datasets + hsize_t dims3[] = {SPACE3_DIM1}; + DataSpace sid3(SPACE3_RANK, dims3); + + // Create a dataset + DataSet dset3 = file1.createDataSet(DSET2_NAME, PredType::STD_U8LE, sid3); + + uint8_t *tu8; // Temporary pointer to uint8 data + for (tu8 = dwbuf, i = 0; i < SPACE3_DIM1; i++) + *tu8++ = i * 3; // from C test + + // Write selection to disk + dset3.write(dwbuf, PredType::STD_U8LE); + + // Close Dataset + dset3.close(); + + // Create dataspace for datasets + hsize_t dims1[] = {SPACE1_DIM1}; + DataSpace sid1(SPACE1_RANK, dims1); + + // Create a dataset + DataSet dset1 = file1.createDataSet(DSET1_NAME, PredType::STD_REF_DSETREG, sid1); + + /* + * Create references and prepare for testing + */ + + /* Select 15 2x1 hyperslabs for first reference */ + start[0] = 2; + stride[0] = 5; + count[0] = 15; + block[0] = 2; + + // Select a hyperslab region to add to the current selected region + sid3.selectHyperslab(H5S_SELECT_SET, count, start, stride, block); + + // Get and verify the number of elements in a dataspace selection + hssize_t nelms = sid3.getSelectNpoints(); + verify_val(nelms, 30, "DataSet::getRefObjType",__LINE__,__FILE__); + + // Store first dataset region + file1.reference(&wbuf[0], "/Dataset2", sid3); + + // Get and verify object type + H5O_type_t obj_type = dset1.getRefObjType(&wbuf[0], H5R_DATASET_REGION); + verify_val(obj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__); + + /* Select sequence of ten points for second reference */ + coord1[0][0] = 16; + coord1[1][0] = 22; + coord1[2][0] = 38; + coord1[3][0] = 41; + coord1[4][0] = 52; + coord1[5][0] = 63; + coord1[6][0] = 70; + coord1[7][0] = 89; + coord1[8][0] = 97; + coord1[9][0] = 3; + + // Selects array elements to be included in the selection for sid3 + sid3.selectElements(H5S_SELECT_SET, (size_t)POINT1_NPOINTS, (const hsize_t *)coord1); + + // Get and verify the number of elements in a dataspace selection + nelms = sid3.getSelectNpoints(); + verify_val(nelms, 10, "DataSet::getRefObjType",__LINE__,__FILE__); + + // Store first dataset region + file1.reference(&wbuf[1], "/Dataset2", sid3); + + // Write selection to disk + dset1.write(wbuf, PredType::STD_REF_DSETREG); + + // Close disk dataspace, dataset, and file + sid1.close(); + dset1.close(); + sid3.close(); + file1.close(); + + /* + * Testing various dereference functions + */ + + // Re-open the file + file1.openFile(FILE2, H5F_ACC_RDWR); + + // Open the dataset + dset1 = file1.openDataSet("/Dataset1"); + + // Read selection from disk + dset1.read(rbuf, PredType::STD_REF_DSETREG); + + { // Test DataSet::dereference + dset3.dereference(dset1, &rbuf[0], H5R_DATASET_REGION); + + // Get and verify object type + obj_type = dset1.getRefObjType(&rbuf[0], H5R_DATASET_REGION); + verify_val(obj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__); + + // Get dataspace of dset3 the verify number of elements + sid1 = dset3.getSpace(); + nelms = sid1.getSimpleExtentNpoints(); + verify_val((long)nelms, 100, "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); + } // End of test DataSet::dereference + + { // Test DataSet constructor -by dereference + // Dereference dataset object by ctor, from the location where + // 'dset1' is located + DataSet newds(dset1, &rbuf[0], H5R_DATASET_REGION); + + // Get dataspace of newds then verify number of elements + sid1 = newds.getSpace(); + nelms = sid1.getSimpleExtentNpoints(); + verify_val((long)nelms, 100, "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); + + // Close objects for this mini test + newds.close(); + sid1.close(); + } // End of test DataSet constructor -by dereference + + // Read from disk + dset3.read(drbuf, PredType::STD_U8LE); + + for(tu8 = (uint8_t *)drbuf, i = 0; i < SPACE3_DIM1; i++, tu8++) + verify_val(*tu8, (uint8_t)(i * 3), "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); + + /* + * Test getting the referenced region + */ + + // Get region + DataSpace reg_sp = dset1.getRegion(&rbuf[0]); + + // Get and verify number of elements in a dataspace selection + nelms = reg_sp.getSelectNpoints(); + verify_val((long)nelms, 30, "DataSpace::getSelectNpoints",__LINE__,__FILE__); + + // Get and verify number of hyperslab blocks + nelms = reg_sp.getSelectHyperNblocks(); + verify_val((long)nelms, 15, "DataSpace::getSelectNpoints",__LINE__,__FILE__); + + /* Allocate space for the hyperslab blocks */ + coords = (hsize_t *)HDmalloc(nelms * SPACE3_RANK * sizeof(hsize_t) * 2); + + // Get the list of hyperslab blocks currently selected + reg_sp.getSelectHyperBlocklist((hsize_t)0, (hsize_t)nelms, coords); + + // Verify values in the list + verify_val(coords[0], 2, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[1], 3, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[2], 7, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[3], 8, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[4], 12, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[5], 13, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[6], 17, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[7], 18, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[8], 22, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[9], 23, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[10], 27, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[11], 28, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[12], 32, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[13], 33, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[14], 37, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[15], 38, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[16], 42, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[17], 43, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[18], 47, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[19], 48, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[20], 52, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[21], 53, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[22], 57, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[23], 58, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[24], 62, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[25], 63, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[26], 67, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[27], 68, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[28], 72, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[29], 73, "Hyperslab Coordinates",__LINE__,__FILE__); + + HDfree(coords); + + // Check boundaries + reg_sp.getSelectBounds(low, high); + verify_val(low[0], 2, "DataSpace::getSelectBounds",__LINE__,__FILE__); + verify_val(high[0], 73, "DataSpace::getSelectBounds",__LINE__,__FILE__); + + /* Close region space */ + reg_sp.close(); + + /* + * Another test on getting the referenced region + */ + + // Get region + DataSpace elm_sp = dset1.getRegion(&rbuf[1]); + + // Get and verify number of element points in the current selection + hssize_t nelmspts = elm_sp.getSelectElemNpoints(); + verify_val((long)nelmspts, 10, "DataSpace::getSelectNpoints",__LINE__,__FILE__); + + /* Allocate space for the hyperslab blocks */ + coords = (hsize_t *)HDmalloc(nelmspts * SPACE3_RANK * sizeof(hsize_t)); + + // Get the list of element points currently selected + elm_sp.getSelectElemPointlist((hsize_t)0, (hsize_t)nelmspts, coords); + + // Verify points + verify_val(coords[0], coord1[0][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[1], coord1[1][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[2], coord1[2][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[3], coord1[3][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[4], coord1[4][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[5], coord1[5][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[6], coord1[6][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[7], coord1[7][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[8], coord1[8][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[9], coord1[9][0], "Element Coordinates",__LINE__,__FILE__); + + HDfree(coords); + + // Check boundaries + elm_sp.getSelectBounds(low, high); + verify_val(low[0], 3, "DataSpace::getSelectBounds",__LINE__,__FILE__); + verify_val(high[0], 97, "DataSpace::getSelectBounds",__LINE__,__FILE__); + + // Close element space + elm_sp.close(); + + // Close resources + sid1.close(); + dset3.close(); + dset1.close(); + file1.close(); + + // Free memory buffers + HDfree(wbuf); + HDfree(rbuf); + HDfree(dwbuf); + HDfree(drbuf); + + PASSED(); + } // end try + catch (Exception E) { + issue_fail_msg("test_reference_region_1D()",__LINE__,__FILE__, + E.getCFuncName(), E.getCDetailMsg()); + } +} /* test_reference_region_1D() */ + + +/**************************************************************** +** +** test_reference_compat(): Test basic object reference functionality. +** Tests references to various kinds of objects using deprecated API. +** +****************************************************************/ +static void test_reference_compat(void) +{ + // Not yet +} // test_reference_compat() + + /**************************************************************** ** ** test_reference(): Main reference testing routine. @@ -344,7 +805,11 @@ void test_reference(void) //MESSAGE("Testing References\n"); MESSAGE(5, ("Testing References\n")); + test_reference_params(); // Test basic parameters of reference functionality test_reference_obj(); // Test basic object reference functionality + test_reference_group(); // Test group reference functionality + test_reference_region_1D(); // Test 1-D reference functionality + test_reference_compat(); // Tests deprecated reference routines (not yet) } // test_reference() @@ -360,5 +825,6 @@ extern "C" void cleanup_reference(void) { HDremove(FILE1.c_str()); + HDremove(FILE2.c_str()); } |