diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2018-07-17 17:21:07 (GMT) |
---|---|---|
committer | M. Scot Breitenfeld <brtnfld@hdfgroup.org> | 2018-07-26 22:20:28 (GMT) |
commit | f9d2edc7ed14bb4fb6d04dd414b7e481721e9f19 (patch) | |
tree | 3228b71d40c995c62bd1ddba3178a0e9eef0b1f2 | |
parent | 622806b89dcc305e1744985763e6293d85497ffa (diff) | |
download | hdf5-f9d2edc7ed14bb4fb6d04dd414b7e481721e9f19.zip hdf5-f9d2edc7ed14bb4fb6d04dd414b7e481721e9f19.tar.gz hdf5-f9d2edc7ed14bb4fb6d04dd414b7e481721e9f19.tar.bz2 |
Fixed HDFFV-10472
Description:
Added operator!= to DataType
bool operator!=(const DataType& compared_type)
Platforms tested:
Linux/64 (jelly)
Linux/32 (jam)
Darwin (osx1010test)
-rw-r--r-- | c++/src/H5DataType.cpp | 14 | ||||
-rw-r--r-- | c++/src/H5DataType.h | 3 | ||||
-rw-r--r-- | c++/test/ttypes.cpp | 81 |
3 files changed, 98 insertions, 0 deletions
diff --git a/c++/src/H5DataType.cpp b/c++/src/H5DataType.cpp index e460871..28933dd 100644 --- a/c++/src/H5DataType.cpp +++ b/c++/src/H5DataType.cpp @@ -396,6 +396,20 @@ bool DataType::operator==(const DataType& compared_type) const } //-------------------------------------------------------------------------- +// Function: DataType::operator!= +///\brief Compares this DataType against the given one to determines +/// whether the two objects refer to different actual datatypes. +///\param compared_type - IN: Reference to the datatype to compare +///\return true if the datatypes are not equal, and false, otherwise. +///\exception H5::DataTypeIException +// July, 2018 +//-------------------------------------------------------------------------- +bool DataType::operator!=(const DataType& compared_type) const +{ + return !operator==(compared_type); +} + +//-------------------------------------------------------------------------- // Function: DataType::p_commit (private) //\brief Commits a transient datatype to a file, creating a new // named datatype diff --git a/c++/src/H5DataType.h b/c++/src/H5DataType.h index 52fd4de..e4d9e4b 100644 --- a/c++/src/H5DataType.h +++ b/c++/src/H5DataType.h @@ -90,6 +90,9 @@ class H5_DLLCPP DataType : public H5Object { // Determines whether two datatypes are the same. bool operator==(const DataType& compared_type) const; + // Determines whether two datatypes are not the same. + bool operator!=(const DataType& compared_type) const; + // Locks a datatype. void lock() const; diff --git a/c++/test/ttypes.cpp b/c++/test/ttypes.cpp index a2bd561..b30d9e7 100644 --- a/c++/test/ttypes.cpp +++ b/c++/test/ttypes.cpp @@ -1026,6 +1026,86 @@ static void test_encode_decode() /*------------------------------------------------------------------------- + * Function: test_operators + * + * Purpose Test datatype encode/decode functionality. + * + * Return None + * + * Programmer Binh-Minh Ribler (using C version) + * August, 2017 + *------------------------------------------------------------------------- + */ +const H5std_string filename4("h5_type_operators.h5"); + +static void test_operators() +{ + short enum_val; + + SUBTEST("DataType::operator== and DataType::operator!="); + try { + // Create the file. + H5File file(filename4, H5F_ACC_TRUNC); + + // + // Test with CompType + // + + // Create a compound datatype + CompType cmptyp(sizeof(src_typ_t)); + + cmptyp.insertMember("a", HOFFSET(src_typ_t, a), PredType::NATIVE_INT); + cmptyp.insertMember("b", HOFFSET(src_typ_t, b), PredType::NATIVE_FLOAT); + cmptyp.insertMember("c", HOFFSET(src_typ_t, c), PredType::NATIVE_LONG); + cmptyp.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_DOUBLE); + + // Copy this compound datatype + CompType clone_cmptyp(cmptyp); + + // Verify that operator== and operator!= work properly + verify_val(cmptyp == clone_cmptyp, true, "DataType::operator==", __LINE__, __FILE__); + verify_val(cmptyp != clone_cmptyp, false, "DataType::operator!=", __LINE__, __FILE__); + + // + // Test with EnumType + // + + // Create a enumerate datatype + EnumType enumtyp(sizeof(short)); + + enumtyp.insert("RED", (enum_val=0,&enum_val)); + enumtyp.insert("GREEN", (enum_val=1,&enum_val)); + enumtyp.insert("BLUE", (enum_val=2,&enum_val)); + + // Verify that operator== and operator!= work properly + verify_val(cmptyp == enumtyp, false, "DataType::operator==", __LINE__, __FILE__); + verify_val(cmptyp != enumtyp, true, "DataType::operator!=", __LINE__, __FILE__); + + // + // Test with compound datatype's member + // + + // Create a variable-length string type + IntType inttyp(PredType::NATIVE_INT); + FloatType flttyp(PredType::NATIVE_FLOAT); + + // Get NATIVE_INT member from the compound datatype above + IntType member_inttyp = cmptyp.getMemberIntType(0); + + verify_val(inttyp == member_inttyp, true, "DataType::operator==", __LINE__, __FILE__); + verify_val(flttyp == member_inttyp, false, "DataType::operator==", __LINE__, __FILE__); + verify_val(flttyp != member_inttyp, true, "DataType::operator==", __LINE__, __FILE__); + + PASSED(); + } + catch (Exception& E) + { + issue_fail_msg("test_operators", __LINE__, __FILE__, E.getCDetailMsg()); + } +} // test_operators + + +/*------------------------------------------------------------------------- * Function: test_types * * Purpose Main datatypes testing routine @@ -1048,6 +1128,7 @@ void test_types() test_transient(); test_named(); test_encode_decode(); + test_operators(); } // test_types() |