diff options
author | Dana Robinson <43805+derobins@users.noreply.github.com> | 2022-04-07 14:23:35 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-07 14:23:35 (GMT) |
commit | 13d852d89ede307314adbfaa036fe670dfa75554 (patch) | |
tree | f3e66489a150de1fd493365cf5cf535963679e5d /c++/test/tcompound.cpp | |
parent | 541bc15452f71f3eae7471fdecbe7994a7f138e2 (diff) | |
download | hdf5-13d852d89ede307314adbfaa036fe670dfa75554.zip hdf5-13d852d89ede307314adbfaa036fe670dfa75554.tar.gz hdf5-13d852d89ede307314adbfaa036fe670dfa75554.tar.bz2 |
1.12: Brings C++ wrappers in line with develop, minus C++11 bits (#1604)
Diffstat (limited to 'c++/test/tcompound.cpp')
-rw-r--r-- | c++/test/tcompound.cpp | 90 |
1 files changed, 43 insertions, 47 deletions
diff --git a/c++/test/tcompound.cpp b/c++/test/tcompound.cpp index 82c21e8..c27171b 100644 --- a/c++/test/tcompound.cpp +++ b/c++/test/tcompound.cpp @@ -101,11 +101,11 @@ test_compound_2() SUBTEST("Compound Element Reordering"); try { // Sizes should be the same, but be careful just in case - buf = (unsigned char *)HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); - bkg = (unsigned char *)HDmalloc(nelmts * sizeof(dst_typ_t)); - orig = (unsigned char *)HDmalloc(nelmts * sizeof(src_typ_t)); + buf = static_cast<unsigned char *>(HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t)))); + bkg = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(dst_typ_t))); + orig = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(src_typ_t))); for (i = 0; i < nelmts; i++) { - s_ptr = ((src_typ_t *)orig) + i; + s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i; s_ptr->a = i * 8 + 0; s_ptr->b = i * 8 + 1; s_ptr->c[0] = i * 8 + 2; @@ -115,7 +115,7 @@ test_compound_2() s_ptr->d = i * 8 + 6; s_ptr->e = i * 8 + 7; } - memcpy(buf, orig, nelmts * sizeof(src_typ_t)); + HDmemcpy(buf, orig, nelmts * sizeof(src_typ_t)); // Build hdf5 datatypes array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four); @@ -142,12 +142,12 @@ test_compound_2() array_dt->close(); // Perform the conversion - st.convert(dt, (size_t)nelmts, buf, bkg); + st.convert(dt, static_cast<size_t>(nelmts), buf, bkg); // Compare results for (i = 0; i < nelmts; i++) { - s_ptr = ((src_typ_t *)orig) + i; - d_ptr = ((dst_typ_t *)buf) + i; + s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i; + d_ptr = (reinterpret_cast<dst_typ_t *>(buf)) + i; if (s_ptr->a != d_ptr->a || s_ptr->b != d_ptr->b || s_ptr->c[0] != d_ptr->c[0] || s_ptr->c[1] != d_ptr->c[1] || s_ptr->c[2] != d_ptr->c[2] || s_ptr->c[3] != d_ptr->c[3] || s_ptr->d != d_ptr->d || s_ptr->e != d_ptr->e) { @@ -176,8 +176,7 @@ test_compound_2() issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } - if (array_dt) - delete array_dt; + delete array_dt; } // test_compound_2() /*------------------------------------------------------------------------- @@ -215,11 +214,11 @@ test_compound_3() SUBTEST("Compound Datatype Subset Conversions"); try { /* Initialize */ - buf = (unsigned char *)HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); - bkg = (unsigned char *)HDmalloc(nelmts * sizeof(dst_typ_t)); - orig = (unsigned char *)HDmalloc(nelmts * sizeof(src_typ_t)); + buf = static_cast<unsigned char *>(HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t)))); + bkg = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(dst_typ_t))); + orig = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(src_typ_t))); for (i = 0; i < nelmts; i++) { - s_ptr = ((src_typ_t *)orig) + i; + s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i; s_ptr->a = i * 8 + 0; s_ptr->b = i * 8 + 1; s_ptr->c[0] = i * 8 + 2; @@ -254,12 +253,12 @@ test_compound_3() array_dt->close(); /* Perform the conversion */ - st.convert(dt, (size_t)nelmts, buf, bkg); + st.convert(dt, static_cast<size_t>(nelmts), buf, bkg); /* Compare results */ for (i = 0; i < nelmts; i++) { - s_ptr = ((src_typ_t *)orig) + i; - d_ptr = ((dst_typ_t *)buf) + i; + s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i; + d_ptr = (reinterpret_cast<dst_typ_t *>(buf)) + i; if (s_ptr->a != d_ptr->a || s_ptr->c[0] != d_ptr->c[0] || s_ptr->c[1] != d_ptr->c[1] || s_ptr->c[2] != d_ptr->c[2] || s_ptr->c[3] != d_ptr->c[3] || s_ptr->e != d_ptr->e) { H5_FAILED(); @@ -269,8 +268,8 @@ test_compound_3() << ", e=" << s_ptr->e << "}" << endl; cerr << " dst={a=" << d_ptr->a << ", c=[" << d_ptr->c[0] << "," << d_ptr->c[1] << "," << d_ptr->c[2] << "," << d_ptr->c[3] << "], e=" << d_ptr->e << "}" << endl; - } // if - } // for + } + } /* Release resources */ HDfree(buf); @@ -287,8 +286,7 @@ test_compound_3() issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } - if (array_dt) - delete array_dt; + delete array_dt; } // test_compound_3() /*------------------------------------------------------------------------- @@ -331,11 +329,11 @@ test_compound_4() SUBTEST("Compound Element Shrinking & Reordering"); try { /* Sizes should be the same, but be careful just in case */ - buf = (unsigned char *)HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); - bkg = (unsigned char *)HDmalloc(nelmts * sizeof(dst_typ_t)); - orig = (unsigned char *)HDmalloc(nelmts * sizeof(src_typ_t)); + buf = static_cast<unsigned char *>(HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t)))); + bkg = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(dst_typ_t))); + orig = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(src_typ_t))); for (i = 0; i < nelmts; i++) { - s_ptr = ((src_typ_t *)orig) + i; + s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i; s_ptr->a = i * 8 + 0; s_ptr->b = (i * 8 + 1) & 0x7fff; s_ptr->c[0] = i * 8 + 2; @@ -372,12 +370,12 @@ test_compound_4() array_dt->close(); /* Perform the conversion */ - st.convert(dt, (size_t)nelmts, buf, bkg); + st.convert(dt, static_cast<size_t>(nelmts), buf, bkg); /* Compare results */ for (i = 0; i < nelmts; i++) { - s_ptr = ((src_typ_t *)orig) + i; - d_ptr = ((dst_typ_t *)buf) + i; + s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i; + d_ptr = (reinterpret_cast<dst_typ_t *>(buf)) + i; if (s_ptr->a != d_ptr->a || s_ptr->b != d_ptr->b || s_ptr->c[0] != d_ptr->c[0] || s_ptr->c[1] != d_ptr->c[1] || s_ptr->c[2] != d_ptr->c[2] || s_ptr->c[3] != d_ptr->c[3] || s_ptr->d != d_ptr->d || s_ptr->e != d_ptr->e) { @@ -407,8 +405,7 @@ test_compound_4() issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } - if (array_dt) - delete array_dt; + delete array_dt; } // test_compound_4() /*------------------------------------------------------------------------- @@ -476,8 +473,8 @@ test_compound_5() /* Convert data */ memcpy(buf, src, sizeof(src)); - src_type.convert(dst_type, (size_t)2, buf, bkg); - dst = (dst_typ_t *)buf; + src_type.convert(dst_type, 2, buf, bkg); + dst = static_cast<dst_typ_t *>(buf); /* Cleanup */ src_type.close(); @@ -504,8 +501,7 @@ test_compound_5() issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } - if (array_dt) - delete array_dt; + delete array_dt; } // test_compound_5() /*------------------------------------------------------------------------- @@ -544,11 +540,11 @@ test_compound_6() SUBTEST("Compound Element Growing"); try { /* Sizes should be the same, but be careful just in case */ - buf = (unsigned char *)HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); - bkg = (unsigned char *)HDmalloc(nelmts * sizeof(dst_typ_t)); - orig = (unsigned char *)HDmalloc(nelmts * sizeof(src_typ_t)); + buf = static_cast<unsigned char *>(HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t)))); + bkg = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(dst_typ_t))); + orig = static_cast<unsigned char *>(HDmalloc(nelmts * sizeof(src_typ_t))); for (i = 0; i < nelmts; i++) { - s_ptr = ((src_typ_t *)orig) + i; + s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i; s_ptr->b = (i * 8 + 1) & 0x7fff; s_ptr->d = (i * 8 + 6) & 0x7fff; } @@ -564,19 +560,19 @@ test_compound_6() dt.insertMember("d", HOFFSET(dst_typ_t, d), PredType::NATIVE_LONG); /* Perform the conversion */ - st.convert(dt, (size_t)nelmts, buf, bkg); + st.convert(dt, static_cast<size_t>(nelmts), buf, bkg); /* Compare results */ for (i = 0; i < nelmts; i++) { - s_ptr = ((src_typ_t *)orig) + i; - d_ptr = ((dst_typ_t *)buf) + i; + s_ptr = (reinterpret_cast<src_typ_t *>(orig)) + i; + d_ptr = (reinterpret_cast<dst_typ_t *>(buf)) + i; if (s_ptr->b != d_ptr->b || s_ptr->d != d_ptr->d) { H5_FAILED(); cerr << " i=" << i << endl; cerr << " src={b=" << s_ptr->b << ", d=" << s_ptr->d << "}" << endl; cerr << " dst={b=" << d_ptr->b << ", d=" << d_ptr->d << "}" << endl; - } // if - } // for + } + } /* Release resources */ HDfree(buf); @@ -719,22 +715,22 @@ test_compound_set_size() // verify_val(packed, FALSE, "DataType::packed", __LINE__, __FILE__); // Expand the type, and verify that it became unpacked - dtype.setSize((size_t)33); + dtype.setSize(33); // packed = dtype.packed(); // not until C library provides API // verify_val(packed, FALSE, "DataType::packed", __LINE__, __FILE__); // Verify setSize() actually set size size_t new_size = dtype.getSize(); - verify_val(new_size, (size_t)33, "DataType::getSize", __LINE__, __FILE__); + verify_val(static_cast<long>(new_size), 33, "DataType::getSize", __LINE__, __FILE__); // Shrink the type, and verify that it became packed - dtype.setSize((size_t)32); + dtype.setSize(32); // packed = dtype.packed(); // not until C library provides API // verify_val(packed, TRUE, "DataType::packed", __LINE__, __FILE__); // Verify setSize() actually set size again new_size = dtype.getSize(); - verify_val(new_size, (size_t)32, "DataType::getSize", __LINE__, __FILE__); + verify_val(static_cast<long>(new_size), 32, "DataType::getSize", __LINE__, __FILE__); /* Close types and file */ dtype_tmp.close(); |