summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2002-06-10 21:49:22 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2002-06-10 21:49:22 (GMT)
commitc12b97f829ffada2d6af8c02dc5205c8639e9df3 (patch)
tree3fc8f39d4c61e3d24ad90d8674fee04872a33fc6
parente4614ad65dbe822da09348bc3463ab360920f3a1 (diff)
downloadhdf5-c12b97f829ffada2d6af8c02dc5205c8639e9df3.zip
hdf5-c12b97f829ffada2d6af8c02dc5205c8639e9df3.tar.gz
hdf5-c12b97f829ffada2d6af8c02dc5205c8639e9df3.tar.bz2
[svn-r5583] Purpose:
New Feature - per library change Description: Added the new member function getMemberIndex to classes EnumType and CompType to match the new C API H5Tget_member_index. Given the name of a member of an enumeration or compound datatype, this new function queries the index of the member. Platforms: SunOS 5.7 (arabica) Linux 6.2 (eirene)
-rw-r--r--c++/src/H5CompType.cpp46
-rw-r--r--c++/src/H5CompType.h4
-rw-r--r--c++/src/H5EnumType.cpp29
-rw-r--r--c++/src/H5EnumType.h4
4 files changed, 81 insertions, 2 deletions
diff --git a/c++/src/H5CompType.cpp b/c++/src/H5CompType.cpp
index 6bf2bfa..eddb114 100644
--- a/c++/src/H5CompType.cpp
+++ b/c++/src/H5CompType.cpp
@@ -82,11 +82,53 @@ string CompType::getMemberName( int member_num ) const
return( member_name ); // return the member name string
}
-// Retrieves the offset of a member of a compound datatype.
+/*-------------------------------------------------------------------------
+ * Function: getMemberIndex
+ *
+ * Purpose: Returns the index of a member in a compound data type.
+ * Members are stored in no particular order with numbers 0
+ * through N-1, where N is the value returned by the member
+ * function getNmembers.
+ *
+ * Return: Success: index of the member if exists.
+ * Failure: DataTypeIException
+ *
+ * BMR - June 10, 2002
+ *-------------------------------------------------------------------------
+ */
+int CompType::getMemberIndex(const char* name) const
+{
+ int member_index = H5Tget_member_index(id, name);
+ if( member_index < 0 )
+ {
+ throw DataTypeIException("CompType::getMemberIndex",
+ "H5Tget_member_index returns negative value");
+ }
+ return( member_index );
+}
+int CompType::getMemberIndex(const string& name) const
+{
+ return(getMemberIndex(name.c_str()));
+}
+
+/*-------------------------------------------------------------------------
+ * Function: getMemberOffset
+ *
+ * Purpose: Returns the byte offset of the beginning of a member with
+ * respect to the beginning of the compound data type datum.
+ * Members are stored in no particular order with numbers 0
+ * through N-1, where N is the value returned by the member
+ * function getNmembers.
+ *
+ * Return: Success: Byte offset.
+ * Failure: Quincey: for now, 0 is not a failure
+ *
+ * BMR - 2000
+ *-------------------------------------------------------------------------
+ */
size_t CompType::getMemberOffset( int member_num ) const
{
size_t offset = H5Tget_member_offset( id, member_num );
- // Q. said: for now, 0 is not a failure
//if( offset == 0 )
//{
//throw DataTypeIException("CompType::getMemberOffset",
diff --git a/c++/src/H5CompType.h b/c++/src/H5CompType.h
index 838f7cb..8af8791 100644
--- a/c++/src/H5CompType.h
+++ b/c++/src/H5CompType.h
@@ -37,6 +37,10 @@ class __DLLCPP__ CompType : public DataType {
// Returns the name of a member of this compound datatype.
string getMemberName( int member_num ) const;
+ // Returns the index of a member in this compound data type.
+ int getMemberIndex(const char* name) const;
+ int getMemberIndex(const string& name) const;
+
// Returns the offset of a member of this compound datatype.
size_t getMemberOffset( int memb_no ) const;
diff --git a/c++/src/H5EnumType.cpp b/c++/src/H5EnumType.cpp
index 5248f8e..3c52796 100644
--- a/c++/src/H5EnumType.cpp
+++ b/c++/src/H5EnumType.cpp
@@ -122,6 +122,35 @@ void EnumType::valueOf( const char* name, void *value ) const
}
}
+/*-------------------------------------------------------------------------
+ * Function: getMemberIndex
+ *
+ * Purpose: Returns the index of a member in an enumeration data type.
+ * Members are stored in no particular order with numbers 0
+ * through N-1, where N is the value returned by the member
+ * function getNmembers.
+ *
+ * Return: Success: index of the member if exists.
+ * Failure: DataTypeIException
+ *
+ * BMR - June 10, 2002
+ *-------------------------------------------------------------------------
+ */
+int EnumType::getMemberIndex(const char *name) const
+{
+ int member_index = H5Tget_member_index(id, name);
+ if( member_index < 0 )
+ {
+ throw DataTypeIException("EnumType::getMemberIndex",
+ "H5Tget_member_index returns negative value");
+ }
+ return( member_index );
+}
+int EnumType::getMemberIndex(const string& name) const
+{
+ return(EnumType::getMemberIndex(name.c_str()));
+}
+
// Retrieves the value of a member in this enumeration datatype, given the
// member's index.
void EnumType::getMemberValue( int memb_no, void *value ) const
diff --git a/c++/src/H5EnumType.h b/c++/src/H5EnumType.h
index 40fe633..5795516 100644
--- a/c++/src/H5EnumType.h
+++ b/c++/src/H5EnumType.h
@@ -55,6 +55,10 @@ class __DLLCPP__ EnumType : public DataType {
void valueOf( const string& name, void *value ) const;
void valueOf( const char* name, void *value ) const;
+ // Returns the index of a member in this enumeration data type.
+ int getMemberIndex(const char* name) const;
+ int getMemberIndex(const string& name) const;
+
// Returns the value of an enumeration datatype member
void getMemberValue( int memb_no, void *value ) const;