ORowSetValue: move float and double to union

Change-Id: Ic5de8ad2cf9ef1143b1a5468e5fc5c9974aca5ec
Reviewed-on: https://gerrit.libreoffice.org/2021
Tested-by: LibreOffice gerrit bot <gerrit@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
David Ostrovsky
2013-02-09 11:06:11 +00:00
committed by Caolán McNamara
parent c1e3943cea
commit 0efe5cf57e
3 changed files with 98 additions and 75 deletions
+4 -1
View File
@@ -60,9 +60,12 @@ namespace connectivity
sal_Int64 m_nInt64;
sal_uInt64 m_uInt64;
float m_nFloat;
double m_nDouble;
rtl_uString* m_pString;
void* m_pValue; // can contains double, etc
void* m_pValue; // date/time/timestamp/sequence
} m_aValue;
sal_Int32 m_eTypeKind; // the database type
@@ -43,6 +43,9 @@ public:
void test_Int64();
void test_uInt64();
void test_float();
void test_double();
CPPUNIT_TEST_SUITE(FValueTest);
CPPUNIT_TEST(test_Bool);
@@ -59,6 +62,9 @@ public:
CPPUNIT_TEST(test_Int64);
CPPUNIT_TEST(test_uInt64);
CPPUNIT_TEST(test_float);
CPPUNIT_TEST(test_double);
CPPUNIT_TEST_SUITE_END();
};
@@ -239,6 +245,44 @@ void FValueTest::test_uInt64()
CPPUNIT_ASSERT_MESSAGE("sal_uInt64 conversion from Any didn't work", src_saluInt64 == trg_saluInt64);
}
void FValueTest::test_float()
{
float src_float = 1.234f;
ORowSetValue v(src_float);
float trg_float = v.getFloat();
std::cerr << "src_float: " << src_float << std::endl;
std::cerr << "trg_float: " << trg_float << std::endl;
CPPUNIT_ASSERT_MESSAGE("float conversion to ORowSetValue didn't work", src_float == trg_float);
Any any_float = v.makeAny();
ORowSetValue t;
t.fill(any_float);
trg_float = t.getFloat();
CPPUNIT_ASSERT_MESSAGE("float conversion from Any didn't work", src_float == trg_float);
}
void FValueTest::test_double()
{
double src_double = 1.23456789;
ORowSetValue v(src_double);
double trg_double = v.getDouble();
std::cerr << "src_double: " << src_double << std::endl;
std::cerr << "trg_double: " << trg_double << std::endl;
CPPUNIT_ASSERT_MESSAGE("double conversion to ORowSetValue didn't work", src_double == trg_double);
Any any_double = v.makeAny();
ORowSetValue t;
t.fill(any_double);
trg_double = t.getDouble();
CPPUNIT_ASSERT_MESSAGE("double conversion from Any didn't work", src_double == trg_double);
}
CPPUNIT_TEST_SUITE_REGISTRATION(FValueTest);
}}
+50 -74
View File
@@ -274,17 +274,6 @@ void ORowSetValue::free()
rtl_uString_release(m_aValue.m_pString);
m_aValue.m_pString = NULL;
break;
case DataType::FLOAT:
delete (float*)m_aValue.m_pValue;
TRACE_FREE( float )
m_aValue.m_pValue = NULL;
break;
case DataType::DOUBLE:
case DataType::REAL:
delete (double*)m_aValue.m_pValue;
TRACE_FREE( double )
m_aValue.m_pValue = NULL;
break;
case DataType::DATE:
delete (::com::sun::star::util::Date*)m_aValue.m_pValue;
TRACE_FREE( Date )
@@ -320,6 +309,9 @@ void ORowSetValue::free()
case DataType::INTEGER:
case DataType::BIGINT:
case DataType::BOOLEAN:
case DataType::FLOAT:
case DataType::DOUBLE:
case DataType::REAL:
break;
default:
if ( m_aValue.m_pValue )
@@ -359,15 +351,6 @@ ORowSetValue& ORowSetValue::operator=(const ORowSetValue& _rRH)
rtl_uString_acquire(_rRH.m_aValue.m_pString);
m_aValue.m_pString = _rRH.m_aValue.m_pString;
break;
case DataType::FLOAT:
m_aValue.m_pValue = new float(*(float*)_rRH.m_aValue.m_pValue);
TRACE_ALLOC( float )
break;
case DataType::DOUBLE:
case DataType::REAL:
m_aValue.m_pValue = new double(*(double*)_rRH.m_aValue.m_pValue);
TRACE_ALLOC( double )
break;
case DataType::DATE:
m_aValue.m_pValue = new Date(*(Date*)_rRH.m_aValue.m_pValue);
TRACE_ALLOC( Date )
@@ -414,6 +397,13 @@ ORowSetValue& ORowSetValue::operator=(const ORowSetValue& _rRH)
else
m_aValue.m_uInt64 = _rRH.m_aValue.m_uInt64;
break;
case DataType::FLOAT:
m_aValue.m_nFloat = _rRH.m_aValue.m_nFloat;
break;
case DataType::DOUBLE:
case DataType::REAL:
m_aValue.m_nDouble = _rRH.m_aValue.m_nDouble;
break;
default:
m_aValue.m_pValue = new Any(*(Any*)_rRH.m_aValue.m_pValue);
TRACE_ALLOC( Any )
@@ -430,13 +420,6 @@ ORowSetValue& ORowSetValue::operator=(const ORowSetValue& _rRH)
case DataType::LONGVARCHAR:
(*this) = ::rtl::OUString(_rRH.m_aValue.m_pString);
break;
case DataType::FLOAT:
(*this) = *(float*)_rRH.m_aValue.m_pValue;
break;
case DataType::DOUBLE:
case DataType::REAL:
(*this) = *(double*)_rRH.m_aValue.m_pValue;
break;
case DataType::DATE:
(*this) = *(Date*)_rRH.m_aValue.m_pValue;
break;
@@ -479,6 +462,13 @@ ORowSetValue& ORowSetValue::operator=(const ORowSetValue& _rRH)
else
m_aValue.m_uInt64 = _rRH.m_aValue.m_uInt64;
break;
case DataType::FLOAT:
m_aValue.m_nFloat = _rRH.m_aValue.m_nFloat;
break;
case DataType::DOUBLE:
case DataType::REAL:
m_aValue.m_nDouble = _rRH.m_aValue.m_nDouble;
break;
default:
(*(Any*)m_aValue.m_pValue) = (*(Any*)_rRH.m_aValue.m_pValue);
}
@@ -564,18 +554,12 @@ ORowSetValue& ORowSetValue::operator=(const ::rtl::OUString& _rRH)
ORowSetValue& ORowSetValue::operator=(const double& _rRH)
{
if( !isStorageCompatible(m_eTypeKind,DataType::DOUBLE) )
if(m_eTypeKind != DataType::DOUBLE)
free();
if(m_bNull)
{
m_aValue.m_pValue = new double(_rRH);
TRACE_ALLOC( double )
m_eTypeKind = DataType::DOUBLE;
m_bNull = sal_False;
}
else
*(double*)m_aValue.m_pValue = _rRH;
m_aValue.m_nDouble = _rRH;
m_eTypeKind = DataType::DOUBLE;
m_bNull = sal_False;
return *this;
}
@@ -585,15 +569,9 @@ ORowSetValue& ORowSetValue::operator=(const float& _rRH)
if(m_eTypeKind != DataType::FLOAT)
free();
if(m_bNull)
{
m_aValue.m_pValue = new float(_rRH);
TRACE_ALLOC( float )
m_eTypeKind = DataType::FLOAT;
m_bNull = sal_False;
}
else
*(float*)m_aValue.m_pValue = _rRH;
m_aValue.m_nFloat = _rRH;
m_eTypeKind = DataType::FLOAT;
m_bNull = sal_False;
return *this;
}
@@ -839,11 +817,11 @@ bool ORowSetValue::operator==(const ORowSetValue& _rRH) const
}
break;
case DataType::FLOAT:
bRet = *(float*)m_aValue.m_pValue == *(float*)_rRH.m_aValue.m_pValue;
bRet = m_aValue.m_nFloat == _rRH.m_aValue.m_nFloat;
break;
case DataType::DOUBLE:
case DataType::REAL:
bRet = *(double*)m_aValue.m_pValue == *(double*)_rRH.m_aValue.m_pValue;
bRet = m_aValue.m_nDouble == _rRH.m_aValue.m_nDouble;
break;
case DataType::TINYINT:
bRet = m_bSigned ? ( m_aValue.m_nInt8 == _rRH.m_aValue.m_nInt8 ) : (m_aValue.m_uInt8 == _rRH.m_aValue.m_uInt8);
@@ -906,13 +884,11 @@ Any ORowSetValue::makeAny() const
rValue <<= (::rtl::OUString)m_aValue.m_pString;
break;
case DataType::FLOAT:
OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
rValue <<= *(float*)m_aValue.m_pValue;
rValue <<= m_aValue.m_nFloat;
break;
case DataType::DOUBLE:
case DataType::REAL:
OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
rValue <<= *(double*)m_aValue.m_pValue;
rValue <<= m_aValue.m_nDouble;
break;
case DataType::DATE:
OSL_ENSURE(m_aValue.m_pValue,"Value is null!");
@@ -1104,11 +1080,11 @@ bool ORowSetValue::getBool() const
bRet = ::rtl::OUString(m_aValue.m_pString).toInt32() != 0;
break;
case DataType::FLOAT:
bRet = *(float*)m_aValue.m_pValue != 0.0;
bRet = m_aValue.m_nFloat != 0.0;
break;
case DataType::DOUBLE:
case DataType::REAL:
bRet = *(double*)m_aValue.m_pValue != 0.0;
bRet = m_aValue.m_nDouble != 0.0;
break;
case DataType::DATE:
case DataType::TIME:
@@ -1164,11 +1140,11 @@ sal_Int8 ORowSetValue::getInt8() const
nRet = sal_Int8(::rtl::OUString(m_aValue.m_pString).toInt32());
break;
case DataType::FLOAT:
nRet = sal_Int8(*(float*)m_aValue.m_pValue);
nRet = sal_Int8(m_aValue.m_nFloat);
break;
case DataType::DOUBLE:
case DataType::REAL:
nRet = sal_Int8(*(double*)m_aValue.m_pValue);
nRet = sal_Int8(m_aValue.m_nDouble);
break;
case DataType::DATE:
case DataType::TIME:
@@ -1235,11 +1211,11 @@ sal_uInt8 ORowSetValue::getUInt8() const
nRet = sal_uInt8(::rtl::OUString(m_aValue.m_pString).toInt32());
break;
case DataType::FLOAT:
nRet = sal_uInt8(*(float*)m_aValue.m_pValue);
nRet = sal_uInt8(m_aValue.m_nFloat);
break;
case DataType::DOUBLE:
case DataType::REAL:
nRet = sal_uInt8(*(double*)m_aValue.m_pValue);
nRet = sal_uInt8(m_aValue.m_nDouble);
break;
case DataType::DATE:
case DataType::TIME:
@@ -1310,11 +1286,11 @@ sal_Int16 ORowSetValue::getInt16() const
nRet = sal_Int16(::rtl::OUString(m_aValue.m_pString).toInt32());
break;
case DataType::FLOAT:
nRet = sal_Int16(*(float*)m_aValue.m_pValue);
nRet = sal_Int16(m_aValue.m_nFloat);
break;
case DataType::DOUBLE:
case DataType::REAL:
nRet = sal_Int16(*(double*)m_aValue.m_pValue);
nRet = sal_Int16(m_aValue.m_nDouble);
break;
case DataType::DATE:
case DataType::TIME:
@@ -1381,11 +1357,11 @@ sal_uInt16 ORowSetValue::getUInt16() const
nRet = sal_uInt16(::rtl::OUString(m_aValue.m_pString).toInt32());
break;
case DataType::FLOAT:
nRet = sal_uInt16(*(float*)m_aValue.m_pValue);
nRet = sal_uInt16(m_aValue.m_nFloat);
break;
case DataType::DOUBLE:
case DataType::REAL:
nRet = sal_uInt16(*(double*)m_aValue.m_pValue);
nRet = sal_uInt16(m_aValue.m_nDouble);
break;
case DataType::DATE:
case DataType::TIME:
@@ -1453,11 +1429,11 @@ sal_Int32 ORowSetValue::getInt32() const
nRet = ::rtl::OUString(m_aValue.m_pString).toInt32();
break;
case DataType::FLOAT:
nRet = sal_Int32(*(float*)m_aValue.m_pValue);
nRet = sal_Int32(m_aValue.m_nFloat);
break;
case DataType::DOUBLE:
case DataType::REAL:
nRet = sal_Int32(*(double*)m_aValue.m_pValue);
nRet = sal_Int32(m_aValue.m_nDouble);
break;
case DataType::DATE:
nRet = dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
@@ -1526,11 +1502,11 @@ sal_uInt32 ORowSetValue::getUInt32() const
nRet = ::rtl::OUString(m_aValue.m_pString).toInt32();
break;
case DataType::FLOAT:
nRet = sal_uInt32(*(float*)m_aValue.m_pValue);
nRet = sal_uInt32(m_aValue.m_nFloat);
break;
case DataType::DOUBLE:
case DataType::REAL:
nRet = sal_uInt32(*(double*)m_aValue.m_pValue);
nRet = sal_uInt32(m_aValue.m_nDouble);
break;
case DataType::DATE:
nRet = dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
@@ -1600,11 +1576,11 @@ sal_Int64 ORowSetValue::getLong() const
nRet = ::rtl::OUString(m_aValue.m_pString).toInt64();
break;
case DataType::FLOAT:
nRet = sal_Int64(*(float*)m_aValue.m_pValue);
nRet = sal_Int64(m_aValue.m_nFloat);
break;
case DataType::DOUBLE:
case DataType::REAL:
nRet = sal_Int64(*(double*)m_aValue.m_pValue);
nRet = sal_Int64(m_aValue.m_nDouble);
break;
case DataType::DATE:
nRet = dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
@@ -1673,11 +1649,11 @@ sal_uInt64 ORowSetValue::getULong() const
nRet = static_cast<sal_uInt64>(::rtl::OUString(m_aValue.m_pString).toInt64());
break;
case DataType::FLOAT:
nRet = sal_uInt64(*(float*)m_aValue.m_pValue);
nRet = sal_uInt64(m_aValue.m_nFloat);
break;
case DataType::DOUBLE:
case DataType::REAL:
nRet = sal_uInt64(*(double*)m_aValue.m_pValue);
nRet = sal_uInt64(m_aValue.m_nDouble);
break;
case DataType::DATE:
nRet = dbtools::DBTypeConversion::toDays(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
@@ -1747,11 +1723,11 @@ float ORowSetValue::getFloat() const
nRet = ::rtl::OUString(m_aValue.m_pString).toFloat();
break;
case DataType::FLOAT:
nRet = *(float*)m_aValue.m_pValue;
nRet = m_aValue.m_nFloat;
break;
case DataType::DOUBLE:
case DataType::REAL:
nRet = (float)*(double*)m_aValue.m_pValue;
nRet = (float)m_aValue.m_nDouble;
break;
case DataType::DATE:
nRet = (float)dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Date*)m_aValue.m_pValue);
@@ -1826,11 +1802,11 @@ double ORowSetValue::getDouble() const
nRet = ::rtl::OUString(m_aValue.m_pString).toDouble();
break;
case DataType::FLOAT:
nRet = *(float*)m_aValue.m_pValue;
nRet = m_aValue.m_nFloat;
break;
case DataType::DOUBLE:
case DataType::REAL:
nRet = *(double*)m_aValue.m_pValue;
nRet = m_aValue.m_nDouble;
break;
case DataType::DATE:
nRet = dbtools::DBTypeConversion::toDouble(*(::com::sun::star::util::Date*)m_aValue.m_pValue);