diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2018-05-12 23:36:37 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2018-05-12 23:36:37 (GMT) |
commit | e5b337dd881b60a5300675f6b30ca3429020acbe (patch) | |
tree | 3a8a0acbbb12c93a06abf36e77e8fcd05481a4fc | |
parent | 276a6110e3be918b01820f35ca57f588eeb3bf5f (diff) | |
download | hdf5-e5b337dd881b60a5300675f6b30ca3429020acbe.zip hdf5-e5b337dd881b60a5300675f6b30ca3429020acbe.tar.gz hdf5-e5b337dd881b60a5300675f6b30ca3429020acbe.tar.bz2 |
Code cleanup
Description:
The function getNumAttrs should be in H5Location so that when an
attribute is the location, the function will get the number of attributes
belong to the object, which the invoking attribute is attached to.
Platforms tested:
Linux/64 (jelly)
Linux/64 (platypus)
Darwin (osx1010test)
-rw-r--r-- | c++/src/H5CommonFG.cpp | 6 | ||||
-rw-r--r-- | c++/src/H5CommonFG.h | 2 | ||||
-rw-r--r-- | c++/src/H5Cpp.h | 2 | ||||
-rw-r--r-- | c++/src/H5Location.cpp | 98 | ||||
-rw-r--r-- | c++/src/H5Location.h | 7 | ||||
-rw-r--r-- | c++/src/H5Object.cpp | 6 |
6 files changed, 29 insertions, 92 deletions
diff --git a/c++/src/H5CommonFG.cpp b/c++/src/H5CommonFG.cpp index 118b1b2..314a9fe 100644 --- a/c++/src/H5CommonFG.cpp +++ b/c++/src/H5CommonFG.cpp @@ -308,8 +308,7 @@ void CommonFG::link(H5L_type_t link_type, const H5std_string& curr_name, const H // Modification // May 2018: // This function is deprecated immediately, in 1.8.21, because -// their replacement have two arguments and one of them is a -// default. +// its replacement has two arguments and one of them is a default. // 2007: QAK modified to use H5L APIs - BMR //-------------------------------------------------------------------------- void CommonFG::unlink(const char* name) const @@ -325,8 +324,7 @@ void CommonFG::unlink(const char* name) const // Modification // May 2018: // This function is deprecated immediately, in 1.8.21, because -// their replacement have two arguments and one of them is a -// default. +// its replacement has two arguments and one of them is a default. //-------------------------------------------------------------------------- void CommonFG::unlink(const H5std_string& name) const { diff --git a/c++/src/H5CommonFG.h b/c++/src/H5CommonFG.h index 4afc777..fa08263 100644 --- a/c++/src/H5CommonFG.h +++ b/c++/src/H5CommonFG.h @@ -99,7 +99,7 @@ class H5_DLLCPP CommonFG { // Removes the specified name at this location. // Deprecated in favor of H5Location::unlink overloaded (1.8.21) - // These functions can be removed immediately because their replacement + // These functions can be removed immediately because their replacements // have a default argument out of two. //void unlink(const char* name) const; //void unlink(const H5std_string& name) const; diff --git a/c++/src/H5Cpp.h b/c++/src/H5Cpp.h index b04c7a2..4108831 100644 --- a/c++/src/H5Cpp.h +++ b/c++/src/H5Cpp.h @@ -29,9 +29,7 @@ #include "H5Attribute.h" #include "H5OcreatProp.h" #include "H5DcreatProp.h" -#include "H5StrcreatProp.h" #include "H5AcreatProp.h" -#include "H5LcreatProp.h" #include "H5CommonFG.h" #include "H5DataType.h" #include "H5DxferProp.h" diff --git a/c++/src/H5Location.cpp b/c++/src/H5Location.cpp index 692c7c2..6894fdd 100644 --- a/c++/src/H5Location.cpp +++ b/c++/src/H5Location.cpp @@ -148,6 +148,25 @@ int H5Location::iterateAttrs(attr_operator_t user_op, unsigned *_idx, void *op_d } //-------------------------------------------------------------------------- +// Function: H5Location::getNumAttrs +///\brief Returns the number of attributes attached to an HDF5 object. +///\return Number of attributes +///\exception H5::AttributeIException +// Modification +// - Moved from H5Object to allow passing an attribute id to the +// C API, in 1.8.20. +//-------------------------------------------------------------------------- +int H5Location::getNumAttrs() const +{ + H5O_info_t objinfo; /* Object info */ + + if(H5Oget_info(getId(), &objinfo) < 0) + throwException("getNumAttrs", "H5Oget_info failed"); + else + return(static_cast<int>(objinfo.num_attrs)); +} + +//-------------------------------------------------------------------------- // Function: H5Location::nameExists ///\brief Checks if a link of a given name exists in a location. ///\param name - IN: Searched name - \c char* @@ -308,25 +327,6 @@ void H5Location::getObjectInfo(const H5std_string& name, H5O_info_t *objinfo, } //-------------------------------------------------------------------------- -// Function: H5Location::getNumAttrs -///\brief Replaced by H5Object::getNumAttrs. -///\return Number of attributes -///\exception H5::AttributeIException -// Programmer Binh-Minh Ribler - 2000 -// Modification -// - Moved to H5Object in 1.8.20. -BMR Oct, 2017 -//-------------------------------------------------------------------------- -int H5Location::getNumAttrs() const -{ - H5O_info_t oinfo; /* Object info */ - - if(H5Oget_info(getId(), &oinfo) < 0) - throwException("getNumAttrs", "H5Oget_info failed"); - else - return(static_cast<int>(oinfo.num_attrs)); -} - -//-------------------------------------------------------------------------- // Function: H5Location::objVersion ///\brief Returns the header version of this HDF5 object. ///\return Object version, which can have the following values: @@ -1138,66 +1138,6 @@ void H5Location::link(const H5std_string& curr_name, const hid_t same_loc, link(curr_name.c_str(), same_loc, new_name.c_str(), lcpl, lapl); } -#if 0 -//-------------------------------------------------------------------------- -// Function: H5Location::link -///\brief Creates a link of the specified type from \a new_name to -/// \a curr_name. -///\param link_type - IN: Link type; possible values are -/// \li \c H5G_LINK_HARD -/// \li \c H5G_LINK_SOFT -///\param curr_name - IN: Name of the existing object if link is a hard -/// link; can be anything for the soft link -///\param new_name - IN: New name for the object -///\exception H5::FileIException or H5::GroupIException -///\par Description -/// Note that both names are interpreted relative to the -/// specified location. -/// For information on creating hard link and soft link, please -/// refer to the C layer Reference Manual at: -/// https://support.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-CreateHard and -/// https://support.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-CreateSoft -// Programmer Binh-Minh Ribler - 2000 -// Modification -// 2007: QAK modified to use H5L APIs - BMR -//-------------------------------------------------------------------------- -void H5Location::link(H5L_type_t link_type, const char* curr_name, const char* new_name) const -{ - herr_t ret_value = -1; - - switch(link_type) { - case H5L_TYPE_HARD: - ret_value = H5Lcreate_hard(getId(), curr_name, H5L_SAME_LOC, new_name, H5P_DEFAULT, H5P_DEFAULT); - break; - - case H5L_TYPE_SOFT: - ret_value = H5Lcreate_soft(curr_name, getId(), new_name, H5P_DEFAULT, H5P_DEFAULT); - break; - - case H5L_TYPE_ERROR: - case H5L_TYPE_EXTERNAL: - case H5L_TYPE_MAX: - default: - throwException("link", "unknown link type"); - break; - } /* end switch */ - - if(ret_value < 0) - throwException("link", "creating link failed"); -} - -//-------------------------------------------------------------------------- -// Function: H5Location::link -///\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 curr_name and \a new_name. -// Programmer Binh-Minh Ribler - 2000 -//-------------------------------------------------------------------------- -void H5Location::link(H5L_type_t link_type, const H5std_string& curr_name, const H5std_string& new_name) const -{ - link(link_type, curr_name.c_str(), new_name.c_str()); -} -#endif //-------------------------------------------------------------------------- // Function: H5Location::copyLink diff --git a/c++/src/H5Location.h b/c++/src/H5Location.h index d929754..e76a6fc 100644 --- a/c++/src/H5Location.h +++ b/c++/src/H5Location.h @@ -41,6 +41,9 @@ class UserData4Aiterate { // user data for attribute iteration // Inheritance: IdComponent class H5_DLLCPP H5Location : public IdComponent { public: + // Determines the number of attributes belong to this object. + int getNumAttrs() const; + // Checks if a link of a given name exists in this location bool nameExists(const char* name, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const; bool nameExists(const H5std_string& name, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const; @@ -60,10 +63,6 @@ class H5_DLLCPP H5Location : public IdComponent { void getObjectInfo(const H5std_string& name, H5O_info_t *oinfo, const LinkAccPropList& lapl = LinkAccPropList::DEFAULT) const; - // Determines the number of attributes at this location. - // - moved to H5Object (1.8.20) - int getNumAttrs() const; // Deprecated - #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; diff --git a/c++/src/H5Object.cpp b/c++/src/H5Object.cpp index a3b53d4..868a5d3 100644 --- a/c++/src/H5Object.cpp +++ b/c++/src/H5Object.cpp @@ -285,12 +285,14 @@ void H5Object::renameAttr(const H5std_string& oldname, const H5std_string& newna //-------------------------------------------------------------------------- // Function: H5Object::getNumAttrs -///\brief Returns the number of attributes attached to this HDF5 object. +///\brief Deprecated - replaced by 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 // Modification -// - Moved from H5Location in 1.8.20. -BMR Oct, 2017 +// - Moved to H5Location to allow passing an attribute id to the +// C API, in 1.8.20. //-------------------------------------------------------------------------- int H5Object::getNumAttrs() const { |