Simplify equality comparison among the various UNOIDL integer types
Change-Id: I67b11049938de470a2a5096cac376fdb0529ab5c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132992 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
parent
fc2413e9a8
commit
9a42c99d7b
1 changed files with 71 additions and 57 deletions
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <cmath>
|
||||
#include <string.h>
|
||||
#include <type_traits>
|
||||
|
||||
#include <osl/diagnose.h>
|
||||
#include <rtl/ustring.hxx>
|
||||
|
@ -259,6 +260,27 @@ inline bool _equalSequence(
|
|||
}
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
std::enable_if_t<std::is_signed_v<T1> && std::is_signed_v<T2>, bool> equal(T1 value1, T2 value2) {
|
||||
return value1 == value2;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
std::enable_if_t<std::is_signed_v<T1> && std::is_unsigned_v<T2>, bool> equal(T1 value1, T2 value2) {
|
||||
return value1 >= 0 && static_cast<std::make_unsigned_t<T1>>(value1) == value2;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
std::enable_if_t<std::is_unsigned_v<T1> && std::is_signed_v<T2>, bool> equal(T1 value1, T2 value2) {
|
||||
return value2 >= 0 && value1 == static_cast<std::make_unsigned_t<T2>>(value2);
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
std::enable_if_t<std::is_unsigned_v<T1> && std::is_unsigned_v<T2>, bool> equal(T1 value1, T2 value2)
|
||||
{
|
||||
return value1 == value2;
|
||||
}
|
||||
|
||||
inline bool _equalData(
|
||||
void * pDest,
|
||||
typelib_TypeDescriptionReference * pDestType, typelib_TypeDescription * pDestTypeDescr,
|
||||
|
@ -294,20 +316,19 @@ inline bool _equalData(
|
|||
switch (eSourceTypeClass)
|
||||
{
|
||||
case typelib_TypeClass_BYTE:
|
||||
return (*static_cast<sal_Int8 *>(pDest) == *static_cast<sal_Int8 *>(pSource));
|
||||
return equal(*static_cast<sal_Int8 *>(pDest), *static_cast<sal_Int8 *>(pSource));
|
||||
case typelib_TypeClass_SHORT:
|
||||
return (static_cast<sal_Int16>(*static_cast<sal_Int8 *>(pDest)) == *static_cast<sal_Int16 *>(pSource));
|
||||
return equal(*static_cast<sal_Int8 *>(pDest), *static_cast<sal_Int16 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_SHORT:
|
||||
return (static_cast<sal_Int32>(*static_cast<sal_Int8 *>(pDest)) == static_cast<sal_Int32>(*static_cast<sal_uInt16 *>(pSource)));
|
||||
return equal(*static_cast<sal_Int8 *>(pDest), *static_cast<sal_uInt16 *>(pSource));
|
||||
case typelib_TypeClass_LONG:
|
||||
return (static_cast<sal_Int32>(*static_cast<sal_Int8 *>(pDest)) == *static_cast<sal_Int32 *>(pSource));
|
||||
return equal(*static_cast<sal_Int8 *>(pDest), *static_cast<sal_Int32 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_LONG:
|
||||
return (static_cast<sal_Int64>(*static_cast<sal_Int8 *>(pDest)) == static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pSource)));
|
||||
return equal(*static_cast<sal_Int8 *>(pDest), *static_cast<sal_uInt32 *>(pSource));
|
||||
case typelib_TypeClass_HYPER:
|
||||
return (static_cast<sal_Int64>(*static_cast<sal_Int8 *>(pDest)) == *static_cast<sal_Int64 *>(pSource));
|
||||
return equal(*static_cast<sal_Int8 *>(pDest), *static_cast<sal_Int64 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_HYPER:
|
||||
return (*static_cast<sal_Int8 *>(pDest) >= 0 &&
|
||||
static_cast<sal_Int64>(*static_cast<sal_Int8 *>(pDest)) == *static_cast<sal_Int64 *>(pSource)); // same size
|
||||
return equal(*static_cast<sal_Int8 *>(pDest), *static_cast<sal_Int64 *>(pSource));
|
||||
case typelib_TypeClass_FLOAT:
|
||||
return (static_cast<float>(*static_cast<sal_Int8 *>(pDest)) == *static_cast<float *>(pSource));
|
||||
case typelib_TypeClass_DOUBLE:
|
||||
|
@ -319,20 +340,19 @@ inline bool _equalData(
|
|||
switch (eSourceTypeClass)
|
||||
{
|
||||
case typelib_TypeClass_BYTE:
|
||||
return (*static_cast<sal_Int16 *>(pDest) == static_cast<sal_Int16>(*static_cast<sal_Int8 *>(pSource)));
|
||||
return equal(*static_cast<sal_Int16 *>(pDest), *static_cast<sal_Int8 *>(pSource));
|
||||
case typelib_TypeClass_SHORT:
|
||||
return (*static_cast<sal_Int16 *>(pDest) == *static_cast<sal_Int16 *>(pSource));
|
||||
return equal(*static_cast<sal_Int16 *>(pDest), *static_cast<sal_Int16 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_SHORT:
|
||||
return (static_cast<sal_Int32>(*static_cast<sal_Int16 *>(pDest)) == static_cast<sal_Int32>(*static_cast<sal_uInt16 *>(pSource)));
|
||||
return equal(*static_cast<sal_Int16 *>(pDest), *static_cast<sal_uInt16 *>(pSource));
|
||||
case typelib_TypeClass_LONG:
|
||||
return (static_cast<sal_Int32>(*static_cast<sal_Int16 *>(pDest)) == *static_cast<sal_Int32 *>(pSource));
|
||||
return equal(*static_cast<sal_Int16 *>(pDest), *static_cast<sal_Int32 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_LONG:
|
||||
return (static_cast<sal_Int64>(*static_cast<sal_Int16 *>(pDest)) == static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pSource)));
|
||||
return equal(*static_cast<sal_Int16 *>(pDest), *static_cast<sal_uInt32 *>(pSource));
|
||||
case typelib_TypeClass_HYPER:
|
||||
return (static_cast<sal_Int64>(*static_cast<sal_Int16 *>(pDest)) == *static_cast<sal_Int64 *>(pSource));
|
||||
return equal(*static_cast<sal_Int16 *>(pDest), *static_cast<sal_Int64 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_HYPER:
|
||||
return (*static_cast<sal_Int16 *>(pDest) >= 0 &&
|
||||
static_cast<sal_Int64>(*static_cast<sal_Int16 *>(pDest)) == *static_cast<sal_Int64 *>(pSource)); // same size
|
||||
return equal(*static_cast<sal_Int16 *>(pDest), *static_cast<sal_Int64 *>(pSource));
|
||||
case typelib_TypeClass_FLOAT:
|
||||
return (static_cast<float>(*static_cast<sal_Int16 *>(pDest)) == *static_cast<float *>(pSource));
|
||||
case typelib_TypeClass_DOUBLE:
|
||||
|
@ -344,19 +364,19 @@ inline bool _equalData(
|
|||
switch (eSourceTypeClass)
|
||||
{
|
||||
case typelib_TypeClass_BYTE:
|
||||
return (static_cast<sal_Int32>(*static_cast<sal_uInt16 *>(pDest)) == static_cast<sal_Int32>(*static_cast<sal_Int8 *>(pSource)));
|
||||
return equal(*static_cast<sal_uInt16 *>(pDest), *static_cast<sal_Int8 *>(pSource));
|
||||
case typelib_TypeClass_SHORT:
|
||||
return (static_cast<sal_Int32>(*static_cast<sal_uInt16 *>(pDest)) == static_cast<sal_Int32>(*static_cast<sal_Int16 *>(pSource)));
|
||||
return equal(*static_cast<sal_uInt16 *>(pDest), *static_cast<sal_Int16 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_SHORT:
|
||||
return (*static_cast<sal_uInt16 *>(pDest) == *static_cast<sal_uInt16 *>(pSource));
|
||||
return equal(*static_cast<sal_uInt16 *>(pDest), *static_cast<sal_uInt16 *>(pSource));
|
||||
case typelib_TypeClass_LONG:
|
||||
return (static_cast<sal_Int32>(*static_cast<sal_uInt16 *>(pDest)) == *static_cast<sal_Int32 *>(pSource));
|
||||
return equal(*static_cast<sal_uInt16 *>(pDest), *static_cast<sal_Int32 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_LONG:
|
||||
return (static_cast<sal_uInt32>(*static_cast<sal_uInt16 *>(pDest)) == *static_cast<sal_uInt32 *>(pSource));
|
||||
return equal(*static_cast<sal_uInt16 *>(pDest), *static_cast<sal_uInt32 *>(pSource));
|
||||
case typelib_TypeClass_HYPER:
|
||||
return (static_cast<sal_Int64>(*static_cast<sal_uInt16 *>(pDest)) == *static_cast<sal_Int64 *>(pSource));
|
||||
return equal(*static_cast<sal_uInt16 *>(pDest), *static_cast<sal_Int64 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_HYPER:
|
||||
return (static_cast<sal_uInt64>(*static_cast<sal_uInt16 *>(pDest)) == *static_cast<sal_uInt64 *>(pSource));
|
||||
return equal(*static_cast<sal_uInt16 *>(pDest), *static_cast<sal_uInt64 *>(pSource));
|
||||
case typelib_TypeClass_FLOAT:
|
||||
return (static_cast<float>(*static_cast<sal_uInt16 *>(pDest)) == *static_cast<float *>(pSource));
|
||||
case typelib_TypeClass_DOUBLE:
|
||||
|
@ -368,20 +388,19 @@ inline bool _equalData(
|
|||
switch (eSourceTypeClass)
|
||||
{
|
||||
case typelib_TypeClass_BYTE:
|
||||
return (*static_cast<sal_Int32 *>(pDest) == static_cast<sal_Int32>(*static_cast<sal_Int8 *>(pSource)));
|
||||
return equal(*static_cast<sal_Int32 *>(pDest), *static_cast<sal_Int8 *>(pSource));
|
||||
case typelib_TypeClass_SHORT:
|
||||
return (*static_cast<sal_Int32 *>(pDest) == static_cast<sal_Int32>(*static_cast<sal_Int16 *>(pSource)));
|
||||
return equal(*static_cast<sal_Int32 *>(pDest), *static_cast<sal_Int16 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_SHORT:
|
||||
return (*static_cast<sal_Int32 *>(pDest) == static_cast<sal_Int32>(*static_cast<sal_uInt16 *>(pSource)));
|
||||
return equal(*static_cast<sal_Int32 *>(pDest), *static_cast<sal_uInt16 *>(pSource));
|
||||
case typelib_TypeClass_LONG:
|
||||
return (*static_cast<sal_Int32 *>(pDest) == *static_cast<sal_Int32 *>(pSource));
|
||||
return equal(*static_cast<sal_Int32 *>(pDest), *static_cast<sal_Int32 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_LONG:
|
||||
return (static_cast<sal_Int64>(*static_cast<sal_Int32 *>(pDest)) == static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pSource)));
|
||||
return equal(*static_cast<sal_Int32 *>(pDest), *static_cast<sal_uInt32 *>(pSource));
|
||||
case typelib_TypeClass_HYPER:
|
||||
return (static_cast<sal_Int64>(*static_cast<sal_Int32 *>(pDest)) == *static_cast<sal_Int64 *>(pSource));
|
||||
return equal(*static_cast<sal_Int32 *>(pDest), *static_cast<sal_Int64 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_HYPER:
|
||||
return (*static_cast<sal_Int32 *>(pDest) >= 0 &&
|
||||
static_cast<sal_Int64>(*static_cast<sal_Int32 *>(pDest)) == *static_cast<sal_Int64 *>(pSource)); // same size
|
||||
return equal(*static_cast<sal_Int32 *>(pDest), *static_cast<sal_Int64 *>(pSource));
|
||||
case typelib_TypeClass_FLOAT:
|
||||
return (static_cast<float>(*static_cast<sal_Int32 *>(pDest)) == *static_cast<float *>(pSource));
|
||||
case typelib_TypeClass_DOUBLE:
|
||||
|
@ -393,19 +412,19 @@ inline bool _equalData(
|
|||
switch (eSourceTypeClass)
|
||||
{
|
||||
case typelib_TypeClass_BYTE:
|
||||
return (static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pDest)) == static_cast<sal_Int64>(*static_cast<sal_Int8 *>(pSource)));
|
||||
return equal(*static_cast<sal_uInt32 *>(pDest), *static_cast<sal_Int8 *>(pSource));
|
||||
case typelib_TypeClass_SHORT:
|
||||
return (static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pDest)) == static_cast<sal_Int64>(*static_cast<sal_Int16 *>(pSource)));
|
||||
return equal(*static_cast<sal_uInt32 *>(pDest), *static_cast<sal_Int16 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_SHORT:
|
||||
return (*static_cast<sal_uInt32 *>(pDest) == static_cast<sal_uInt32>(*static_cast<sal_uInt16 *>(pSource)));
|
||||
return equal(*static_cast<sal_uInt32 *>(pDest), *static_cast<sal_uInt16 *>(pSource));
|
||||
case typelib_TypeClass_LONG:
|
||||
return (static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pDest)) == static_cast<sal_Int64>(*static_cast<sal_Int32 *>(pSource)));
|
||||
return equal(*static_cast<sal_uInt32 *>(pDest), *static_cast<sal_Int32 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_LONG:
|
||||
return (*static_cast<sal_uInt32 *>(pDest) == *static_cast<sal_uInt32 *>(pSource));
|
||||
return equal(*static_cast<sal_uInt32 *>(pDest), *static_cast<sal_uInt32 *>(pSource));
|
||||
case typelib_TypeClass_HYPER:
|
||||
return (static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pDest)) == *static_cast<sal_Int64 *>(pSource));
|
||||
return equal(*static_cast<sal_uInt32 *>(pDest), *static_cast<sal_Int64 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_HYPER:
|
||||
return (static_cast<sal_uInt64>(*static_cast<sal_uInt32 *>(pDest)) == *static_cast<sal_uInt64 *>(pSource));
|
||||
return equal(*static_cast<sal_uInt32 *>(pDest), *static_cast<sal_uInt64 *>(pSource));
|
||||
case typelib_TypeClass_FLOAT:
|
||||
return (static_cast<float>(*static_cast<sal_uInt32 *>(pDest)) == *static_cast<float *>(pSource));
|
||||
case typelib_TypeClass_DOUBLE:
|
||||
|
@ -417,20 +436,19 @@ inline bool _equalData(
|
|||
switch (eSourceTypeClass)
|
||||
{
|
||||
case typelib_TypeClass_BYTE:
|
||||
return (*static_cast<sal_Int64 *>(pDest) == static_cast<sal_Int64>(*static_cast<sal_Int8 *>(pSource)));
|
||||
return equal(*static_cast<sal_Int64 *>(pDest), *static_cast<sal_Int8 *>(pSource));
|
||||
case typelib_TypeClass_SHORT:
|
||||
return (*static_cast<sal_Int64 *>(pDest) == static_cast<sal_Int64>(*static_cast<sal_Int16 *>(pSource)));
|
||||
return equal(*static_cast<sal_Int64 *>(pDest), *static_cast<sal_Int16 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_SHORT:
|
||||
return (*static_cast<sal_Int64 *>(pDest) == static_cast<sal_Int64>(*static_cast<sal_uInt16 *>(pSource)));
|
||||
return equal(*static_cast<sal_Int64 *>(pDest), *static_cast<sal_uInt16 *>(pSource));
|
||||
case typelib_TypeClass_LONG:
|
||||
return (*static_cast<sal_Int64 *>(pDest) == static_cast<sal_Int64>(*static_cast<sal_Int32 *>(pSource)));
|
||||
return equal(*static_cast<sal_Int64 *>(pDest), *static_cast<sal_Int32 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_LONG:
|
||||
return (*static_cast<sal_Int64 *>(pDest) == static_cast<sal_Int64>(*static_cast<sal_uInt32 *>(pSource)));
|
||||
return equal(*static_cast<sal_Int64 *>(pDest), *static_cast<sal_uInt32 *>(pSource));
|
||||
case typelib_TypeClass_HYPER:
|
||||
return (*static_cast<sal_Int64 *>(pDest) == *static_cast<sal_Int64 *>(pSource));
|
||||
return equal(*static_cast<sal_Int64 *>(pDest), *static_cast<sal_Int64 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_HYPER:
|
||||
return (*static_cast<sal_Int64 *>(pDest) >= 0 &&
|
||||
*static_cast<sal_Int64 *>(pDest) == *static_cast<sal_Int64 *>(pSource)); // same size
|
||||
return equal(*static_cast<sal_Int64 *>(pDest), *static_cast<sal_Int64 *>(pSource));
|
||||
case typelib_TypeClass_FLOAT:
|
||||
return (static_cast<float>(*static_cast<sal_Int64 *>(pDest)) == *static_cast<float *>(pSource));
|
||||
case typelib_TypeClass_DOUBLE:
|
||||
|
@ -442,23 +460,19 @@ inline bool _equalData(
|
|||
switch (eSourceTypeClass)
|
||||
{
|
||||
case typelib_TypeClass_BYTE:
|
||||
return (*static_cast<sal_Int8 *>(pSource) >= 0 &&
|
||||
*static_cast<sal_uInt64 *>(pDest) == static_cast<sal_uInt64>(*static_cast<sal_Int8 *>(pSource)));
|
||||
return equal(*static_cast<sal_uInt64 *>(pDest), *static_cast<sal_Int8 *>(pSource));
|
||||
case typelib_TypeClass_SHORT:
|
||||
return (*static_cast<sal_Int16 *>(pSource) >= 0 &&
|
||||
*static_cast<sal_uInt64 *>(pDest) == static_cast<sal_uInt64>(*static_cast<sal_Int16 *>(pSource)));
|
||||
return equal(*static_cast<sal_uInt64 *>(pDest), *static_cast<sal_Int16 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_SHORT:
|
||||
return (*static_cast<sal_uInt64 *>(pDest) == static_cast<sal_uInt64>(*static_cast<sal_uInt16 *>(pSource)));
|
||||
return equal(*static_cast<sal_uInt64 *>(pDest), *static_cast<sal_uInt16 *>(pSource));
|
||||
case typelib_TypeClass_LONG:
|
||||
return (*static_cast<sal_Int32 *>(pSource) >= 0 &&
|
||||
*static_cast<sal_uInt64 *>(pDest) == static_cast<sal_uInt64>(*static_cast<sal_Int32 *>(pSource)));
|
||||
return equal(*static_cast<sal_uInt64 *>(pDest), *static_cast<sal_Int32 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_LONG:
|
||||
return (*static_cast<sal_uInt64 *>(pDest) == static_cast<sal_uInt64>(*static_cast<sal_uInt32 *>(pSource)));
|
||||
return equal(*static_cast<sal_uInt64 *>(pDest), *static_cast<sal_uInt32 *>(pSource));
|
||||
case typelib_TypeClass_HYPER:
|
||||
return (*static_cast<sal_Int64 *>(pSource) >= 0 &&
|
||||
*static_cast<sal_uInt64 *>(pDest) == static_cast<sal_uInt64>(*static_cast<sal_Int64 *>(pSource)));
|
||||
return equal(*static_cast<sal_uInt64 *>(pDest), *static_cast<sal_Int64 *>(pSource));
|
||||
case typelib_TypeClass_UNSIGNED_HYPER:
|
||||
return (*static_cast<sal_uInt64 *>(pDest) == *static_cast<sal_uInt64 *>(pSource));
|
||||
return equal(*static_cast<sal_uInt64 *>(pDest), *static_cast<sal_uInt64 *>(pSource));
|
||||
case typelib_TypeClass_FLOAT:
|
||||
if (::floor( *static_cast<float *>(pSource) ) != *static_cast<float *>(pSource) || *static_cast<float *>(pSource) < 0)
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue