LCOV - code coverage report
Current view: top level - basic/source/sbx - sbxdbl.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 130 0.0 %
Date: 2014-04-14 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <tools/errcode.hxx>
      21             : #include <basic/sbx.hxx>
      22             : #include "sbxconv.hxx"
      23             : #include "runtime.hxx"
      24             : 
      25           0 : double ImpGetDouble( const SbxValues* p )
      26             : {
      27             :     double nRes;
      28           0 :     switch( +p->eType )
      29             :     {
      30             :         case SbxNULL:
      31           0 :             SbxBase::SetError( SbxERR_CONVERSION );
      32             :         case SbxEMPTY:
      33           0 :             nRes = 0; break;
      34             :         case SbxCHAR:
      35           0 :             nRes = p->nChar; break;
      36             :         case SbxBYTE:
      37           0 :             nRes = p->nByte; break;
      38             :         case SbxINTEGER:
      39             :         case SbxBOOL:
      40           0 :             nRes = p->nInteger; break;
      41             :         case SbxERROR:
      42             :         case SbxUSHORT:
      43           0 :             nRes = p->nUShort; break;
      44             :         case SbxLONG:
      45           0 :             nRes = p->nLong; break;
      46             :         case SbxULONG:
      47           0 :             nRes = p->nULong; break;
      48             :         case SbxSINGLE:
      49           0 :             nRes = p->nSingle; break;
      50             :         case SbxDATE:
      51             :         case SbxDOUBLE:
      52           0 :             nRes = p->nDouble; break;
      53             :         case SbxCURRENCY:
      54           0 :             nRes = ImpCurrencyToDouble( p->nInt64 ); break;
      55             :         case SbxSALINT64:
      56           0 :             nRes = static_cast< double >(p->nInt64); break;
      57             :         case SbxSALUINT64:
      58           0 :             nRes = ImpSalUInt64ToDouble( p->uInt64 ); break;
      59             :         case SbxDECIMAL:
      60             :         case SbxBYREF | SbxDECIMAL:
      61           0 :             if( p->pDecimal )
      62           0 :                 p->pDecimal->getDouble( nRes );
      63             :             else
      64           0 :                 nRes = 0.0;
      65           0 :             break;
      66             :         case SbxBYREF | SbxSTRING:
      67             :         case SbxSTRING:
      68             :         case SbxLPSTR:
      69           0 :             if( !p->pOUString )
      70             :             {
      71           0 :                 nRes = 0;
      72             : #ifndef DISABLE_SCRIPTING
      73           0 :                 if ( SbiRuntime::isVBAEnabled() )// VBA only behaviour
      74           0 :                     SbxBase::SetError( SbxERR_CONVERSION );
      75             : #endif
      76             :             }
      77             :             else
      78             :             {
      79             :                 double d;
      80             :                 SbxDataType t;
      81           0 :                 if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
      82             :                 {
      83           0 :                     nRes = 0;
      84             : #ifndef DISABLE_SCRIPTING
      85           0 :                     if ( SbiRuntime::isVBAEnabled() )// VBA only behaviour
      86           0 :                         SbxBase::SetError( SbxERR_CONVERSION );
      87             : #endif
      88             :                 }
      89             :                 else
      90           0 :                     nRes = d;
      91             :             }
      92           0 :             break;
      93             :         case SbxOBJECT:
      94             :         {
      95           0 :             SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
      96           0 :             if( pVal )
      97           0 :                 nRes = pVal->GetDouble();
      98             :             else
      99             :             {
     100           0 :                 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
     101             :             }
     102           0 :             break;
     103             :         }
     104             : 
     105             :         case SbxBYREF | SbxCHAR:
     106           0 :             nRes = *p->pChar; break;
     107             :         case SbxBYREF | SbxBYTE:
     108           0 :             nRes = *p->pByte; break;
     109             :         case SbxBYREF | SbxINTEGER:
     110             :         case SbxBYREF | SbxBOOL:
     111           0 :             nRes = *p->pInteger; break;
     112             :         case SbxBYREF | SbxLONG:
     113           0 :             nRes = *p->pLong; break;
     114             :         case SbxBYREF | SbxULONG:
     115           0 :             nRes = *p->pULong; break;
     116             :         case SbxBYREF | SbxERROR:
     117             :         case SbxBYREF | SbxUSHORT:
     118           0 :             nRes = *p->pUShort; break;
     119             :         case SbxBYREF | SbxSINGLE:
     120           0 :             nRes = *p->pSingle; break;
     121             :         case SbxBYREF | SbxDATE:
     122             :         case SbxBYREF | SbxDOUBLE:
     123           0 :             nRes = *p->pDouble; break;
     124             :         case SbxBYREF | SbxCURRENCY:
     125           0 :             nRes = ImpCurrencyToDouble( *p->pnInt64 ); break;
     126             :         case SbxBYREF | SbxSALINT64:
     127           0 :             nRes = static_cast< double >(*p->pnInt64); break;
     128             :         case SbxBYREF | SbxSALUINT64:
     129           0 :             nRes = ImpSalUInt64ToDouble( *p->puInt64 ); break;
     130             : 
     131             :         default:
     132           0 :             SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
     133             :     }
     134           0 :     return nRes;
     135             : }
     136             : 
     137           0 : void ImpPutDouble( SbxValues* p, double n, bool bCoreString )
     138             : {
     139           0 :     SbxValues aTmp;
     140             : start:
     141           0 :     switch( +p->eType )
     142             :     {
     143             :         // Here are tests necessary
     144             :         case SbxCHAR:
     145           0 :             aTmp.pChar = &p->nChar; goto direct;
     146             :         case SbxBYTE:
     147           0 :             aTmp.pByte = &p->nByte; goto direct;
     148             :         case SbxINTEGER:
     149             :         case SbxBOOL:
     150           0 :             aTmp.pInteger = &p->nInteger; goto direct;
     151             :         case SbxLONG:
     152           0 :             aTmp.pLong = &p->nLong; goto direct;
     153             :         case SbxULONG:
     154           0 :             aTmp.pULong = &p->nULong; goto direct;
     155             :         case SbxERROR:
     156             :         case SbxUSHORT:
     157           0 :             aTmp.pUShort = &p->nUShort; goto direct;
     158             :         case SbxSINGLE:
     159           0 :             aTmp.pSingle = &p->nSingle; goto direct;
     160             :         case SbxDECIMAL:
     161             :         case SbxBYREF | SbxDECIMAL:
     162             :             {
     163           0 :             SbxDecimal* pDec = ImpCreateDecimal( p );
     164           0 :             if( !pDec->setDouble( n ) )
     165           0 :                 SbxBase::SetError( SbxERR_OVERFLOW );
     166           0 :             break;
     167             :             }
     168             :         direct:
     169           0 :             aTmp.eType = SbxDataType( p->eType | SbxBYREF );
     170           0 :             p = &aTmp; goto start;
     171             : 
     172             :         case SbxCURRENCY:
     173           0 :             if( n > SbxMAXCURR )
     174             :             {
     175           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCURR;
     176             :             }
     177           0 :             else if( n < SbxMINCURR )
     178             :             {
     179           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCURR;
     180             :             }
     181           0 :             p->nInt64 = ImpDoubleToCurrency( n );
     182           0 :             break;
     183             : 
     184             :             // from here on no longer
     185             :         case SbxSALINT64:
     186           0 :             p->nInt64 = ImpDoubleToSalInt64( n ); break;
     187             :         case SbxSALUINT64:
     188           0 :             p->uInt64 = ImpDoubleToSalUInt64( n ); break;
     189             :         case SbxDATE:
     190             :         case SbxDOUBLE:
     191           0 :             p->nDouble = n; break;
     192             : 
     193             :         case SbxBYREF | SbxSTRING:
     194             :         case SbxSTRING:
     195             :         case SbxLPSTR:
     196           0 :             if( !p->pOUString )
     197           0 :                 p->pOUString = new OUString;
     198           0 :             ImpCvtNum( (double) n, 14, *p->pOUString, bCoreString );
     199           0 :             break;
     200             :         case SbxOBJECT:
     201             :         {
     202           0 :             SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
     203           0 :             if( pVal )
     204           0 :                 pVal->PutDouble( n );
     205             :             else
     206           0 :                 SbxBase::SetError( SbxERR_NO_OBJECT );
     207           0 :             break;
     208             :         }
     209             :         case SbxBYREF | SbxCHAR:
     210           0 :             if( n > SbxMAXCHAR )
     211             :             {
     212           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCHAR;
     213             :             }
     214           0 :             else if( n < SbxMINCHAR )
     215             :             {
     216           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCHAR;
     217             :             }
     218           0 :             *p->pChar = (sal_Unicode) n; break;
     219             :         case SbxBYREF | SbxBYTE:
     220           0 :             if( n > SbxMAXBYTE )
     221             :             {
     222           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
     223             :             }
     224           0 :             else if( n < 0 )
     225             :             {
     226           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
     227             :             }
     228           0 :             *p->pByte = (sal_uInt8) n; break;
     229             :         case SbxBYREF | SbxINTEGER:
     230             :         case SbxBYREF | SbxBOOL:
     231           0 :             if( n > SbxMAXINT )
     232             :             {
     233           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
     234             :             }
     235           0 :             else if( n < SbxMININT )
     236             :             {
     237           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMININT;
     238             :             }
     239           0 :             *p->pInteger = (sal_Int16) n; break;
     240             :         case SbxBYREF | SbxERROR:
     241             :         case SbxBYREF | SbxUSHORT:
     242           0 :             if( n > SbxMAXUINT )
     243             :             {
     244           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXUINT;
     245             :             }
     246           0 :             else if( n < 0 )
     247             :             {
     248           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
     249             :             }
     250           0 :             *p->pUShort = (sal_uInt16) n; break;
     251             :         case SbxBYREF | SbxLONG:
     252           0 :             if( n > SbxMAXLNG )
     253             :             {
     254           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXLNG;
     255             :             }
     256           0 :             else if( n < SbxMINLNG )
     257             :             {
     258           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINLNG;
     259             :             }
     260           0 :             *p->pLong = (sal_Int32) n; break;
     261             :         case SbxBYREF | SbxULONG:
     262           0 :             if( n > SbxMAXULNG )
     263             :             {
     264           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXULNG;
     265             :             }
     266           0 :             else if( n < 0 )
     267             :             {
     268           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
     269             :             }
     270           0 :             *p->pULong = (sal_uInt32) n; break;
     271             :         case SbxBYREF | SbxSINGLE:
     272           0 :             if( n > SbxMAXSNG )
     273             :             {
     274           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXSNG;
     275             :             }
     276           0 :             else if( n < SbxMINSNG )
     277             :             {
     278           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINSNG;
     279             :             }
     280           0 :             else if( n > 0 && n < SbxMAXSNG2 )
     281             :             {
     282           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXSNG2;
     283             :             }
     284           0 :             else if( n < 0 && n > SbxMINSNG2 )
     285             :             {
     286           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINSNG2;
     287             :             }
     288           0 :             *p->pSingle = (float) n; break;
     289             :         case SbxBYREF | SbxSALINT64:
     290           0 :             *p->pnInt64 = ImpDoubleToSalInt64( n ); break;
     291             :         case SbxBYREF | SbxSALUINT64:
     292           0 :             *p->puInt64 = ImpDoubleToSalUInt64( n ); break;
     293             :         case SbxBYREF | SbxDATE:
     294             :         case SbxBYREF | SbxDOUBLE:
     295           0 :             *p->pDouble = (double) n; break;
     296             :         case SbxBYREF | SbxCURRENCY:
     297           0 :             if( n > SbxMAXCURR )
     298             :             {
     299           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCURR;
     300             :             }
     301           0 :             else if( n < SbxMINCURR )
     302             :             {
     303           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCURR;
     304             :             }
     305           0 :             *p->pnInt64 = ImpDoubleToCurrency( n ); break;
     306             : 
     307             :         default:
     308           0 :             SbxBase::SetError( SbxERR_CONVERSION );
     309             :     }
     310           0 : }
     311             : 
     312             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10