Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/2021

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/21/2021/1

ORowSetValue: move float and double to union

Change-Id: Ic5de8ad2cf9ef1143b1a5468e5fc5c9974aca5ec
---
M connectivity/inc/connectivity/FValue.hxx
M connectivity/qa/connectivity/commontools/FValue_test.cxx
M connectivity/source/commontools/FValue.cxx
3 files changed, 98 insertions(+), 75 deletions(-)



diff --git a/connectivity/inc/connectivity/FValue.hxx b/connectivity/inc/connectivity/FValue.hxx
index 3f72b41..02b4a4b 100644
--- a/connectivity/inc/connectivity/FValue.hxx
+++ b/connectivity/inc/connectivity/FValue.hxx
@@ -60,9 +60,12 @@
             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
diff --git a/connectivity/qa/connectivity/commontools/FValue_test.cxx 
b/connectivity/qa/connectivity/commontools/FValue_test.cxx
index be3024e..9e1b4dd 100644
--- a/connectivity/qa/connectivity/commontools/FValue_test.cxx
+++ b/connectivity/qa/connectivity/commontools/FValue_test.cxx
@@ -43,6 +43,9 @@
     void test_Int64();
     void test_uInt64();
 
+    void test_float();
+    void test_double();
+
     CPPUNIT_TEST_SUITE(FValueTest);
 
     CPPUNIT_TEST(test_Bool);
@@ -58,6 +61,9 @@
 
     CPPUNIT_TEST(test_Int64);
     CPPUNIT_TEST(test_uInt64);
+
+    CPPUNIT_TEST(test_float);
+    CPPUNIT_TEST(test_double);
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -239,6 +245,44 @@
     CPPUNIT_ASSERT_MESSAGE("sal_uInt64 conversion from Any didn't work", src_saluInt64 == 
trg_saluInt64);
 }
 
+void FValueTest::test_float()
+{
+    float src_float = 1.2f;
+    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.23456789d;
+    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);
 
 }}
diff --git a/connectivity/source/commontools/FValue.cxx b/connectivity/source/commontools/FValue.cxx
index e4580dd..fef5087 100644
--- a/connectivity/source/commontools/FValue.cxx
+++ b/connectivity/source/commontools/FValue.cxx
@@ -274,17 +274,6 @@
                 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 @@
             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 )
@@ -358,15 +350,6 @@
             case DataType::LONGVARCHAR:
                 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);
@@ -414,6 +397,13 @@
                 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 )
@@ -429,13 +419,6 @@
             case DataType::NUMERIC:
             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;
@@ -478,6 +461,13 @@
                     m_aValue.m_nInt64   = _rRH.m_aValue.m_nInt64;
                 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 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 @@
     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 @@
             }
             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 @@
                 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 @@
                 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 @@
                 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 @@
                 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 @@
                 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 @@
                 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 @@
                 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 @@
                 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 @@
                 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 @@
                 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 @@
                 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 @@
                 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);

-- 
To view, visit https://gerrit.libreoffice.org/2021
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic5de8ad2cf9ef1143b1a5468e5fc5c9974aca5ec
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: David Ostrovsky <David.Ostrovsky@gmx.de>

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.