LCOV - code coverage report
Current view: top level - sc/source/filter/excel - tokstack.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 304 507 60.0 %
Date: 2014-11-03 Functions: 24 34 70.6 %
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 "tokstack.hxx"
      21             : #include "compiler.hxx"
      22             : #include "global.hxx"
      23             : #include "scmatrix.hxx"
      24             : 
      25             : #include <svl/sharedstringpool.hxx>
      26             : 
      27             : #include <stdio.h>
      28             : #include <string.h>
      29             : 
      30             : const sal_uInt16    TokenPool::nScTokenOff = 8192;
      31             : 
      32         632 : TokenStack::TokenStack( sal_uInt16 nNewSize )
      33             : {
      34         632 :     pStack = new TokenId[ nNewSize ];
      35             : 
      36         632 :     Reset();
      37         632 :     nSize = nNewSize;
      38         632 : }
      39             : 
      40         632 : TokenStack::~TokenStack()
      41             : {
      42         632 :     delete[] pStack;
      43         632 : }
      44             : 
      45             : // !ATTENTION!": to the outside the numbering starts with 1!
      46             : // !ATTENTION!": SC-Token are stored with an offset nScTokenOff
      47             : //                  -> to distinguish from other tokens
      48             : 
      49         632 : TokenPool::TokenPool( svl::SharedStringPool& rSPool ) :
      50         632 :     mrStringPool(rSPool)
      51             : {
      52         632 :     sal_uInt16  nLauf = nScTokenOff;
      53             : 
      54             :     // pool for Id-sequences
      55         632 :     nP_Id = 256;
      56         632 :     pP_Id = new sal_uInt16[ nP_Id ];
      57             : 
      58             :     // pool for Ids
      59         632 :     nElement = 32;
      60         632 :     pElement = new sal_uInt16[ nElement ];
      61         632 :     pType = new E_TYPE[ nElement ];
      62         632 :     pSize = new sal_uInt16[ nElement ];
      63         632 :     nP_IdLast = 0;
      64             : 
      65             :     // pool for strings
      66         632 :     nP_Str = 4;
      67         632 :     ppP_Str = new OUString *[ nP_Str ];
      68        3160 :     for( nLauf = 0 ; nLauf < nP_Str ; nLauf++ )
      69        2528 :         ppP_Str[ nLauf ] = NULL;
      70             : 
      71             :     // pool for double
      72         632 :     nP_Dbl = 8;
      73         632 :     pP_Dbl = new double[ nP_Dbl ];
      74             : 
      75             :     // pool for error codes
      76         632 :     nP_Err = 8;
      77         632 :     pP_Err = new sal_uInt16[ nP_Err ];
      78             : 
      79             :     // pool for References
      80         632 :     nP_RefTr = 32;
      81         632 :     ppP_RefTr = new ScSingleRefData *[ nP_RefTr ];
      82       20856 :     for( nLauf = 0 ; nLauf < nP_RefTr ; nLauf++ )
      83       20224 :         ppP_RefTr[ nLauf ] = NULL;
      84             : 
      85         632 :     nP_Ext = 32;
      86         632 :     ppP_Ext = new EXTCONT*[ nP_Ext ];
      87         632 :     memset( ppP_Ext, 0, sizeof( EXTCONT* ) * nP_Ext );
      88             : 
      89         632 :     nP_Nlf = 16;
      90         632 :     ppP_Nlf = new NLFCONT*[ nP_Nlf ];
      91         632 :     memset( ppP_Nlf, 0, sizeof( NLFCONT* ) * nP_Nlf );
      92             : 
      93         632 :     nP_Matrix = 16;
      94         632 :     ppP_Matrix = new ScMatrix*[ nP_Matrix ];
      95         632 :     memset( ppP_Matrix, 0, sizeof( ScMatrix* ) * nP_Matrix );
      96             : 
      97         632 :     pScToken = new ScTokenArray;
      98             : 
      99         632 :     Reset();
     100         632 : }
     101             : 
     102        1264 : TokenPool::~TokenPool()
     103             : {
     104             :     sal_uInt16 n;
     105             : 
     106         632 :     delete[] pP_Id;
     107         632 :     delete[] pElement;
     108         632 :     delete[] pType;
     109         632 :     delete[] pSize;
     110         632 :     delete[] pP_Dbl;
     111         632 :     delete[] pP_Err;
     112             : 
     113       20856 :     for( n = 0 ; n < nP_RefTr ; n++ )
     114       20224 :         delete ppP_RefTr[ n ];
     115         632 :     delete[] ppP_RefTr;
     116             : 
     117        3168 :     for( n = 0 ; n < nP_Str ; n++ )
     118        2536 :         delete ppP_Str[ n ];
     119         632 :     delete[] ppP_Str;
     120             : 
     121       20856 :     for( n = 0 ; n < nP_Ext ; n++ )
     122       20224 :         delete ppP_Ext[ n ];
     123         632 :     delete[] ppP_Ext;
     124             : 
     125       10744 :     for( n = 0 ; n < nP_Nlf ; n++ )
     126       10112 :         delete ppP_Nlf[ n ];
     127         632 :     delete[] ppP_Nlf;
     128             : 
     129       10744 :     for( n = 0 ; n < nP_Matrix ; n++ )
     130             :     {
     131       10112 :         if( ppP_Matrix[ n ] )
     132           6 :             ppP_Matrix[ n ]->DecRef( );
     133             :     }
     134         632 :     delete[] ppP_Matrix;
     135             : 
     136         632 :     delete pScToken;
     137         632 : }
     138             : 
     139             : /** Returns the new number of elements, or 0 if overflow. */
     140           6 : static sal_uInt16 lcl_canGrow( sal_uInt16 nOld, sal_uInt16 nByMin = 1 )
     141             : {
     142           6 :     if (!nOld)
     143           0 :         return nByMin ? nByMin : 1;
     144           6 :     if (nOld == SAL_MAX_UINT16)
     145           0 :         return 0;
     146           6 :     sal_uInt32 nNew = ::std::max( static_cast<sal_uInt32>(nOld) * 2,
     147          12 :             static_cast<sal_uInt32>(nOld) + nByMin);
     148           6 :     if (nNew > SAL_MAX_UINT16)
     149           0 :         nNew = SAL_MAX_UINT16;
     150           6 :     if (nNew - nByMin < nOld)
     151           0 :         nNew = 0;
     152           6 :     return static_cast<sal_uInt16>(nNew);
     153             : }
     154             : 
     155           2 : bool TokenPool::GrowString( void )
     156             : {
     157           2 :     sal_uInt16 nP_StrNew = lcl_canGrow( nP_Str);
     158           2 :     if (!nP_StrNew)
     159           0 :         return false;
     160             : 
     161             :     sal_uInt16      nL;
     162             : 
     163           2 :     OUString** ppP_StrNew = new (::std::nothrow) OUString *[ nP_StrNew ];
     164           2 :     if (!ppP_StrNew)
     165           0 :         return false;
     166             : 
     167          10 :     for( nL = 0 ; nL < nP_Str ; nL++ )
     168           8 :         ppP_StrNew[ nL ] = ppP_Str[ nL ];
     169          10 :     for( nL = nP_Str ; nL < nP_StrNew ; nL++ )
     170           8 :         ppP_StrNew[ nL ] = NULL;
     171             : 
     172           2 :     nP_Str = nP_StrNew;
     173             : 
     174           2 :     delete[]    ppP_Str;
     175           2 :     ppP_Str = ppP_StrNew;
     176           2 :     return true;
     177             : }
     178             : 
     179           0 : bool TokenPool::GrowDouble( void )
     180             : {
     181           0 :     sal_uInt16 nP_DblNew = lcl_canGrow( nP_Dbl);
     182           0 :     if (!nP_DblNew)
     183           0 :         return false;
     184             : 
     185           0 :     double* pP_DblNew = new (::std::nothrow) double[ nP_DblNew ];
     186           0 :     if (!pP_DblNew)
     187           0 :         return false;
     188             : 
     189           0 :     for( sal_uInt16 nL = 0 ; nL < nP_Dbl ; nL++ )
     190           0 :         pP_DblNew[ nL ] = pP_Dbl[ nL ];
     191             : 
     192           0 :     nP_Dbl = nP_DblNew;
     193             : 
     194           0 :     delete[] pP_Dbl;
     195           0 :     pP_Dbl = pP_DblNew;
     196           0 :     return true;
     197             : }
     198             : 
     199             : /* TODO: in case we had FormulaTokenArray::AddError() */
     200             : #if 0
     201             : void TokenPool::GrowError( void )
     202             : {
     203             :     sal_uInt16 nP_ErrNew = lcl_canGrow( nP_Err);
     204             :     if (!nP_ErrNew)
     205             :         return false;
     206             : 
     207             :     sal_uInt16*     pP_ErrNew = new (::std::nothrow) sal_uInt16[ nP_ErrNew ];
     208             :     if (!pP_ErrNew)
     209             :         return false;
     210             : 
     211             :     for( sal_uInt16 nL = 0 ; nL < nP_Err ; nL++ )
     212             :         pP_ErrNew[ nL ] = pP_Err[ nL ];
     213             : 
     214             :     nP_Err = nP_ErrNew;
     215             : 
     216             :     delete[] pP_Err;
     217             :     pP_Err = pP_ErrNew;
     218             :     return true;
     219             : }
     220             : #endif
     221             : 
     222           0 : bool TokenPool::GrowTripel( sal_uInt16 nByMin )
     223             : {
     224           0 :     sal_uInt16 nP_RefTrNew = lcl_canGrow( nP_RefTr, nByMin);
     225           0 :     if (!nP_RefTrNew)
     226           0 :         return false;
     227             : 
     228             :     sal_uInt16          nL;
     229             : 
     230           0 :     ScSingleRefData** ppP_RefTrNew = new (::std::nothrow) ScSingleRefData *[ nP_RefTrNew ];
     231           0 :     if (!ppP_RefTrNew)
     232           0 :         return false;
     233             : 
     234           0 :     for( nL = 0 ; nL < nP_RefTr ; nL++ )
     235           0 :         ppP_RefTrNew[ nL ] = ppP_RefTr[ nL ];
     236           0 :     for( nL = nP_RefTr ; nL < nP_RefTrNew ; nL++ )
     237           0 :         ppP_RefTrNew[ nL ] = NULL;
     238             : 
     239           0 :     nP_RefTr = nP_RefTrNew;
     240             : 
     241           0 :     delete[] ppP_RefTr;
     242           0 :     ppP_RefTr = ppP_RefTrNew;
     243           0 :     return true;
     244             : }
     245             : 
     246           0 : bool TokenPool::GrowId( void )
     247             : {
     248           0 :     sal_uInt16 nP_IdNew = lcl_canGrow( nP_Id);
     249           0 :     if (!nP_IdNew)
     250           0 :         return false;
     251             : 
     252           0 :     sal_uInt16* pP_IdNew = new (::std::nothrow) sal_uInt16[ nP_IdNew ];
     253           0 :     if (!pP_IdNew)
     254           0 :         return false;
     255             : 
     256           0 :     for( sal_uInt16 nL = 0 ; nL < nP_Id ; nL++ )
     257           0 :         pP_IdNew[ nL ] = pP_Id[ nL ];
     258             : 
     259           0 :     nP_Id = nP_IdNew;
     260             : 
     261           0 :     delete[] pP_Id;
     262           0 :     pP_Id = pP_IdNew;
     263           0 :     return true;
     264             : }
     265             : 
     266           4 : bool TokenPool::GrowElement( void )
     267             : {
     268           4 :     sal_uInt16 nElementNew = lcl_canGrow( nElement);
     269           4 :     if (!nElementNew)
     270           0 :         return false;
     271             : 
     272           4 :     sal_uInt16* pElementNew = new (::std::nothrow) sal_uInt16[ nElementNew ];
     273           4 :     E_TYPE* pTypeNew = new (::std::nothrow) E_TYPE[ nElementNew ];
     274           4 :     sal_uInt16* pSizeNew = new (::std::nothrow) sal_uInt16[ nElementNew ];
     275           4 :     if (!pElementNew || !pTypeNew || !pSizeNew)
     276             :     {
     277           0 :         delete [] pElementNew;
     278           0 :         delete [] pTypeNew;
     279           0 :         delete [] pSizeNew;
     280           0 :         return false;
     281             :     }
     282             : 
     283         132 :     for( sal_uInt16 nL = 0 ; nL < nElement ; nL++ )
     284             :     {
     285         128 :         pElementNew[ nL ] = pElement[ nL ];
     286         128 :         pTypeNew[ nL ] = pType[ nL ];
     287         128 :         pSizeNew[ nL ] = pSize[ nL ];
     288             :     }
     289             : 
     290           4 :     nElement = nElementNew;
     291             : 
     292           4 :     delete[] pElement;
     293           4 :     delete[] pType;
     294           4 :     delete[] pSize;
     295           4 :     pElement = pElementNew;
     296           4 :     pType = pTypeNew;
     297           4 :     pSize = pSizeNew;
     298           4 :     return true;
     299             : }
     300             : 
     301           0 : bool TokenPool::GrowExt( void )
     302             : {
     303           0 :     sal_uInt16 nNewSize = lcl_canGrow( nP_Ext);
     304           0 :     if (!nNewSize)
     305           0 :         return false;
     306             : 
     307           0 :     EXTCONT** ppNew = new (::std::nothrow) EXTCONT*[ nNewSize ];
     308           0 :     if (!ppNew)
     309           0 :         return false;
     310             : 
     311           0 :     memset( ppNew, 0, sizeof( EXTCONT* ) * nNewSize );
     312           0 :     memcpy( ppNew, ppP_Ext, sizeof( EXTCONT* ) * nP_Ext );
     313             : 
     314           0 :     delete[] ppP_Ext;
     315           0 :     ppP_Ext = ppNew;
     316           0 :     nP_Ext = nNewSize;
     317           0 :     return true;
     318             : }
     319             : 
     320           0 : bool TokenPool::GrowNlf( void )
     321             : {
     322           0 :     sal_uInt16 nNewSize = lcl_canGrow( nP_Nlf);
     323           0 :     if (!nNewSize)
     324           0 :         return false;
     325             : 
     326           0 :     NLFCONT** ppNew = new (::std::nothrow) NLFCONT*[ nNewSize ];
     327           0 :     if (!ppNew)
     328           0 :         return false;
     329             : 
     330           0 :     memset( ppNew, 0, sizeof( NLFCONT* ) * nNewSize );
     331           0 :     memcpy( ppNew, ppP_Nlf, sizeof( NLFCONT* ) * nP_Nlf );
     332             : 
     333           0 :     delete[] ppP_Nlf;
     334           0 :     ppP_Nlf = ppNew;
     335           0 :     nP_Nlf = nNewSize;
     336           0 :     return true;
     337             : }
     338             : 
     339           0 : bool TokenPool::GrowMatrix( void )
     340             : {
     341           0 :     sal_uInt16 nNewSize = lcl_canGrow( nP_Matrix);
     342           0 :     if (!nNewSize)
     343           0 :         return false;
     344             : 
     345           0 :     ScMatrix**  ppNew = new (::std::nothrow) ScMatrix*[ nNewSize ];
     346           0 :     if (!ppNew)
     347           0 :         return false;
     348             : 
     349           0 :     memset( ppNew, 0, sizeof( ScMatrix* ) * nNewSize );
     350           0 :     memcpy( ppNew, ppP_Matrix, sizeof( ScMatrix* ) * nP_Matrix );
     351             : 
     352           0 :     delete[] ppP_Matrix;
     353           0 :     ppP_Matrix = ppNew;
     354           0 :     nP_Matrix = nNewSize;
     355           0 :     return true;
     356             : }
     357             : 
     358       29180 : bool TokenPool::GetElement( const sal_uInt16 nId )
     359             : {
     360             :     OSL_ENSURE( nId < nElementAkt, "*TokenPool::GetElement(): Id too large!?" );
     361       29180 :     if (nId >= nElementAkt)
     362           0 :         return false;
     363             : 
     364       29180 :     bool bRet = true;
     365       29180 :     if( pType[ nId ] == T_Id )
     366        5810 :         bRet = GetElementRek( nId );
     367             :     else
     368             :     {
     369       23370 :         switch( pType[ nId ] )
     370             :         {
     371             :             case T_Str:
     372             :                 {
     373        5474 :                     sal_uInt16 n = pElement[ nId ];
     374        5474 :                     OUString* p = ( n < nP_Str )? ppP_Str[ n ] : NULL;
     375        5474 :                     if (p)
     376        5474 :                         pScToken->AddString(mrStringPool.intern(*p));
     377             :                     else
     378           0 :                         bRet = false;
     379             :                 }
     380        5474 :                 break;
     381             :             case T_D:
     382             :                 {
     383        2774 :                     sal_uInt16 n = pElement[ nId ];
     384        2774 :                     if (n < nP_Dbl)
     385        2774 :                         pScToken->AddDouble( pP_Dbl[ n ] );
     386             :                     else
     387           0 :                         bRet = false;
     388             :                 }
     389        2774 :                 break;
     390             :             case T_Err:
     391             : /* TODO: in case we had FormulaTokenArray::AddError() */
     392             : #if 0
     393             :                 {
     394             :                     sal_uInt16 n = pElement[ nId ];
     395             :                     if (n < nP_Err)
     396             :                         pScToken->AddError( pP_Err[ n ] );
     397             :                     else
     398             :                         bRet = false;
     399             :                 }
     400             : #endif
     401           0 :                 break;
     402             :             case T_RefC:
     403             :                 {
     404       10372 :                     sal_uInt16 n = pElement[ nId ];
     405       10372 :                     ScSingleRefData* p = ( n < nP_RefTr )? ppP_RefTr[ n ] : NULL;
     406       10372 :                     if (p)
     407       10372 :                         pScToken->AddSingleReference( *p );
     408             :                     else
     409           0 :                         bRet = false;
     410             :                 }
     411       10372 :                 break;
     412             :             case T_RefA:
     413             :                 {
     414        4702 :                     sal_uInt16 n = pElement[ nId ];
     415        4702 :                     if (n < nP_RefTr && ppP_RefTr[ n ] && n+1 < nP_RefTr && ppP_RefTr[ n + 1 ])
     416             :                     {
     417             :                         ScComplexRefData aScComplexRefData;
     418        4702 :                         aScComplexRefData.Ref1 = *ppP_RefTr[ n ];
     419        4702 :                         aScComplexRefData.Ref2 = *ppP_RefTr[ n + 1 ];
     420        4702 :                         pScToken->AddDoubleReference( aScComplexRefData );
     421             :                     }
     422             :                     else
     423           0 :                         bRet = false;
     424             :                 }
     425        4702 :                 break;
     426             :             case T_RN:
     427             :             {
     428          28 :                 sal_uInt16 n = pElement[nId];
     429          28 :                 if (n < maRangeNames.size())
     430             :                 {
     431          28 :                     const RangeName& r = maRangeNames[n];
     432          28 :                     pScToken->AddRangeName(r.mnIndex, r.mbGlobal);
     433             :                 }
     434             :             }
     435          28 :             break;
     436             :             case T_Ext:
     437             :                 {
     438           2 :                     sal_uInt16      n = pElement[ nId ];
     439           2 :                     EXTCONT*        p = ( n < nP_Ext )? ppP_Ext[ n ] : NULL;
     440             : 
     441           2 :                     if( p )
     442             :                     {
     443           2 :                         if( p->eId == ocEuroConvert )
     444           0 :                             pScToken->AddOpCode( p->eId );
     445             :                         else
     446           2 :                             pScToken->AddExternal( p->aText, p->eId );
     447             :                     }
     448             :                     else
     449           0 :                         bRet = false;
     450             :                 }
     451           2 :                 break;
     452             :             case T_Nlf:
     453             :                 {
     454           0 :                     sal_uInt16      n = pElement[ nId ];
     455           0 :                     NLFCONT*        p = ( n < nP_Nlf )? ppP_Nlf[ n ] : NULL;
     456             : 
     457           0 :                     if( p )
     458           0 :                         pScToken->AddColRowName( p->aRef );
     459             :                     else
     460           0 :                         bRet = false;
     461             :                 }
     462           0 :                 break;
     463             :             case T_Matrix:
     464             :                 {
     465          14 :                     sal_uInt16      n = pElement[ nId ];
     466          14 :                     ScMatrix*       p = ( n < nP_Matrix )? ppP_Matrix[ n ] : NULL;
     467             : 
     468          14 :                     if( p )
     469          14 :                         pScToken->AddMatrix( p );
     470             :                     else
     471           0 :                         bRet = false;
     472             :                 }
     473          14 :                 break;
     474             :             case T_ExtName:
     475             :             {
     476           0 :                 sal_uInt16 n = pElement[nId];
     477           0 :                 if (n < maExtNames.size())
     478             :                 {
     479           0 :                     const ExtName& r = maExtNames[n];
     480           0 :                     pScToken->AddExternalName(r.mnFileId, r.maName);
     481             :                 }
     482             :                 else
     483           0 :                     bRet = false;
     484             :             }
     485           0 :             break;
     486             :             case T_ExtRefC:
     487             :             {
     488           4 :                 sal_uInt16 n = pElement[nId];
     489           4 :                 if (n < maExtCellRefs.size())
     490             :                 {
     491           4 :                     const ExtCellRef& r = maExtCellRefs[n];
     492           4 :                     pScToken->AddExternalSingleReference(r.mnFileId, r.maTabName, r.maRef);
     493             :                 }
     494             :                 else
     495           0 :                     bRet = false;
     496             :             }
     497           4 :             break;
     498             :             case T_ExtRefA:
     499             :             {
     500           0 :                 sal_uInt16 n = pElement[nId];
     501           0 :                 if (n < maExtAreaRefs.size())
     502             :                 {
     503           0 :                     const ExtAreaRef& r = maExtAreaRefs[n];
     504           0 :                     pScToken->AddExternalDoubleReference(r.mnFileId, r.maTabName, r.maRef);
     505             :                 }
     506             :                 else
     507           0 :                     bRet = false;
     508             :             }
     509           0 :             break;
     510             :             default:
     511             :                 OSL_FAIL("-TokenPool::GetElement(): undefined state!?");
     512           0 :                 bRet = false;
     513             :         }
     514             :     }
     515       29180 :     return bRet;
     516             : }
     517             : 
     518       19336 : bool TokenPool::GetElementRek( const sal_uInt16 nId )
     519             : {
     520             : #ifdef DBG_UTIL
     521             :     m_nRek++;
     522             :     OSL_ENSURE(m_nRek <= nP_Id, "*TokenPool::GetElement(): recursion loops!?");
     523             : #endif
     524             : 
     525             :     OSL_ENSURE( nId < nElementAkt, "*TokenPool::GetElementRek(): nId >= nElementAkt" );
     526             : 
     527       19336 :     if (nId >= nElementAkt)
     528             :     {
     529             :         SAL_WARN("sc.filter", "*TokenPool::GetElementRek(): nId >= nElementAkt");
     530             : #ifdef DBG_UTIL
     531             :         m_nRek--;
     532             : #endif
     533           0 :         return false;
     534             :     }
     535             : 
     536       19336 :     if (pType[ nId ] != T_Id)
     537             :     {
     538             :         SAL_WARN("sc.filter", "-TokenPool::GetElementRek(): pType[ nId ] != T_Id");
     539             : #ifdef DBG_UTIL
     540             :         m_nRek--;
     541             : #endif
     542           0 :         return false;
     543             :     }
     544             : 
     545       19336 :     bool bRet = true;
     546       19336 :     sal_uInt16      nAnz = pSize[ nId ];
     547       19336 :     sal_uInt16 nFirstId = pElement[ nId ];
     548       19336 :     if (nFirstId >= nP_Id)
     549             :     {
     550             :         SAL_WARN("sc.filter", "TokenPool::GetElementRek: nFirstId >= nP_Id");
     551           0 :         nAnz = 0;
     552           0 :         bRet = false;
     553             :     }
     554       19336 :     sal_uInt16* pAkt = nAnz ? &pP_Id[ nFirstId ] : NULL;
     555       19336 :     if (nAnz > nP_Id - nFirstId)
     556             :     {
     557             :         SAL_WARN("sc.filter", "TokenPool::GetElementRek: nAnz > nP_Id - nFirstId");
     558           0 :         nAnz = nP_Id - nFirstId;
     559           0 :         bRet = false;
     560             :     }
     561       97162 :     for( ; nAnz > 0 ; nAnz--, pAkt++ )
     562             :     {
     563       77826 :         if( *pAkt < nScTokenOff )
     564             :         {// recursion or not?
     565       36396 :             if (*pAkt >= nElementAkt)
     566             :             {
     567             :                 SAL_WARN("sc.filter", "TokenPool::GetElementRek: *pAkt >= nElementAkt");
     568           0 :                 bRet = false;
     569             :             }
     570             :             else
     571             :             {
     572       36396 :                 if (pType[ *pAkt ] == T_Id)
     573       13526 :                     bRet = GetElementRek( *pAkt );
     574             :                 else
     575       22870 :                     bRet = GetElement( *pAkt );
     576             :             }
     577             :         }
     578             :         else    // elementary SC_Token
     579       41430 :             pScToken->AddOpCode( ( DefTokenId ) ( *pAkt - nScTokenOff ) );
     580             :     }
     581             : 
     582             : #ifdef DBG_UTIL
     583             :     m_nRek--;
     584             : #endif
     585       19336 :     return bRet;
     586             : }
     587             : 
     588       20002 : void TokenPool::operator >>( TokenId& rId )
     589             : {
     590       20002 :     rId = static_cast<TokenId>( nElementAkt + 1 );
     591             : 
     592       20002 :     if( nElementAkt >= nElement )
     593           4 :         if (!GrowElement())
     594       20002 :             return;
     595             : 
     596       20002 :     pElement[ nElementAkt ] = nP_IdLast;    // Start of Token-sequence
     597       20002 :     pType[ nElementAkt ] = T_Id;            // set Typeinfo
     598       20002 :     pSize[ nElementAkt ] = nP_IdAkt - nP_IdLast;
     599             :         // write from nP_IdLast to nP_IdAkt-1 -> length of the sequence
     600             : 
     601       20002 :     nElementAkt++;          // start value for next sequence
     602       20002 :     nP_IdLast = nP_IdAkt;
     603             : }
     604             : 
     605        3438 : const TokenId TokenPool::Store( const double& rDouble )
     606             : {
     607        3438 :     if( nElementAkt >= nElement )
     608           0 :         if (!GrowElement())
     609           0 :             return static_cast<const TokenId>(nElementAkt+1);
     610             : 
     611        3438 :     if( nP_DblAkt >= nP_Dbl )
     612           0 :         if (!GrowDouble())
     613           0 :             return static_cast<const TokenId>(nElementAkt+1);
     614             : 
     615        3438 :     pElement[ nElementAkt ] = nP_DblAkt;    // Index in Double-Array
     616        3438 :     pType[ nElementAkt ] = T_D;             // set Typeinfo Double
     617             : 
     618        3438 :     pP_Dbl[ nP_DblAkt ] = rDouble;
     619             : 
     620        3438 :     pSize[ nElementAkt ] = 1;               // does not matter
     621             : 
     622        3438 :     nElementAkt++;
     623        3438 :     nP_DblAkt++;
     624             : 
     625        3438 :     return static_cast<const TokenId>(nElementAkt); // return old value + 1!
     626             : }
     627             : 
     628           0 : const TokenId TokenPool::Store( const sal_uInt16 nIndex )
     629             : {
     630           0 :     return StoreName(nIndex, true);
     631             : }
     632             : 
     633        5476 : const TokenId TokenPool::Store( const OUString& rString )
     634             : {
     635             :     // mostly copied to Store( const sal_Char* ), to avoid a temporary string
     636        5476 :     if( nElementAkt >= nElement )
     637           0 :         if (!GrowElement())
     638           0 :             return static_cast<const TokenId>(nElementAkt+1);
     639             : 
     640        5476 :     if( nP_StrAkt >= nP_Str )
     641           2 :         if (!GrowString())
     642           0 :             return static_cast<const TokenId>(nElementAkt+1);
     643             : 
     644        5476 :     pElement[ nElementAkt ] = nP_StrAkt;    // Index in String-Array
     645        5476 :     pType[ nElementAkt ] = T_Str;           // set Typeinfo String
     646             : 
     647             :     // create String
     648        5476 :     if( !ppP_Str[ nP_StrAkt ] )
     649             :         //...but only, if it does not exist already
     650          44 :         ppP_Str[ nP_StrAkt ] = new (::std::nothrow) OUString( rString );
     651             :     else
     652             :         //...copy otherwise
     653        5432 :         *ppP_Str[ nP_StrAkt ] = rString;
     654             : 
     655        5476 :     if (ppP_Str[ nP_StrAkt ])
     656             :     {
     657             :         /* attention trucate to 16 bits */
     658        5476 :         pSize[ nElementAkt ] = ( sal_uInt16 ) ppP_Str[ nP_StrAkt ]->getLength();
     659             :     }
     660             : 
     661        5476 :     nElementAkt++;
     662        5476 :     nP_StrAkt++;
     663             : 
     664        5476 :     return static_cast<const TokenId>(nElementAkt); // return old value + 1!
     665             : }
     666             : 
     667       10372 : const TokenId TokenPool::Store( const ScSingleRefData& rTr )
     668             : {
     669       10372 :     if( nElementAkt >= nElement )
     670           0 :         if (!GrowElement())
     671           0 :             return static_cast<const TokenId>(nElementAkt+1);
     672             : 
     673       10372 :     if( nP_RefTrAkt >= nP_RefTr )
     674           0 :         if (!GrowTripel())
     675           0 :             return static_cast<const TokenId>(nElementAkt+1);
     676             : 
     677       10372 :     pElement[ nElementAkt ] = nP_RefTrAkt;
     678       10372 :     pType[ nElementAkt ] = T_RefC;          // set Typeinfo Cell-Ref
     679             : 
     680       10372 :     if( !ppP_RefTr[ nP_RefTrAkt ] )
     681         504 :         ppP_RefTr[ nP_RefTrAkt ] = new ScSingleRefData( rTr );
     682             :     else
     683        9868 :         *ppP_RefTr[ nP_RefTrAkt ] = rTr;
     684             : 
     685       10372 :     nElementAkt++;
     686       10372 :     nP_RefTrAkt++;
     687             : 
     688       10372 :     return static_cast<const TokenId>(nElementAkt); // return old value + 1!
     689             : }
     690             : 
     691        4704 : const TokenId TokenPool::Store( const ScComplexRefData& rTr )
     692             : {
     693        4704 :     if( nElementAkt >= nElement )
     694           0 :         if (!GrowElement())
     695           0 :             return static_cast<const TokenId>(nElementAkt+1);
     696             : 
     697        4704 :     if( nP_RefTrAkt + 1 >= nP_RefTr )
     698           0 :         if (!GrowTripel( 2))
     699           0 :             return static_cast<const TokenId>(nElementAkt+1);
     700             : 
     701        4704 :     pElement[ nElementAkt ] = nP_RefTrAkt;
     702        4704 :     pType[ nElementAkt ] = T_RefA;          // setTypeinfo Area-Ref
     703             : 
     704        4704 :     if( !ppP_RefTr[ nP_RefTrAkt ] )
     705          74 :         ppP_RefTr[ nP_RefTrAkt ] = new ScSingleRefData( rTr.Ref1 );
     706             :     else
     707        4630 :         *ppP_RefTr[ nP_RefTrAkt ] = rTr.Ref1;
     708        4704 :     nP_RefTrAkt++;
     709             : 
     710        4704 :     if( !ppP_RefTr[ nP_RefTrAkt ] )
     711          88 :         ppP_RefTr[ nP_RefTrAkt ] = new ScSingleRefData( rTr.Ref2 );
     712             :     else
     713        4616 :         *ppP_RefTr[ nP_RefTrAkt ] = rTr.Ref2;
     714        4704 :     nP_RefTrAkt++;
     715             : 
     716        4704 :     nElementAkt++;
     717             : 
     718        4704 :     return static_cast<const TokenId>(nElementAkt); // return old value + 1!
     719             : }
     720             : 
     721         354 : const TokenId TokenPool::Store( const DefTokenId e, const OUString& r )
     722             : {
     723         354 :     if( nElementAkt >= nElement )
     724           0 :         if (!GrowElement())
     725           0 :             return static_cast<const TokenId>(nElementAkt+1);
     726             : 
     727         354 :     if( nP_ExtAkt >= nP_Ext )
     728           0 :         if (!GrowExt())
     729           0 :             return static_cast<const TokenId>(nElementAkt+1);
     730             : 
     731         354 :     pElement[ nElementAkt ] = nP_ExtAkt;
     732         354 :     pType[ nElementAkt ] = T_Ext;           // set Typeinfo String
     733             : 
     734         354 :     if( ppP_Ext[ nP_ExtAkt ] )
     735             :     {
     736         350 :         ppP_Ext[ nP_ExtAkt ]->eId = e;
     737         350 :         ppP_Ext[ nP_ExtAkt ]->aText = r;
     738             :     }
     739             :     else
     740           4 :         ppP_Ext[ nP_ExtAkt ] = new EXTCONT( e, r );
     741             : 
     742         354 :     nElementAkt++;
     743         354 :     nP_ExtAkt++;
     744             : 
     745         354 :     return static_cast<const TokenId>(nElementAkt); // return old value + 1!
     746             : }
     747             : 
     748           0 : const TokenId TokenPool::StoreNlf( const ScSingleRefData& rTr )
     749             : {
     750           0 :     if( nElementAkt >= nElement )
     751           0 :         if (!GrowElement())
     752           0 :             return static_cast<const TokenId>(nElementAkt+1);
     753             : 
     754           0 :     if( nP_NlfAkt >= nP_Nlf )
     755           0 :         if (!GrowNlf())
     756           0 :             return static_cast<const TokenId>(nElementAkt+1);
     757             : 
     758           0 :     pElement[ nElementAkt ] = nP_NlfAkt;
     759           0 :     pType[ nElementAkt ] = T_Nlf;
     760             : 
     761           0 :     if( ppP_Nlf[ nP_NlfAkt ] )
     762             :     {
     763           0 :         ppP_Nlf[ nP_NlfAkt ]->aRef = rTr;
     764             :     }
     765             :     else
     766           0 :         ppP_Nlf[ nP_NlfAkt ] = new NLFCONT( rTr );
     767             : 
     768           0 :     nElementAkt++;
     769           0 :     nP_NlfAkt++;
     770             : 
     771           0 :     return static_cast<const TokenId>(nElementAkt);
     772             : }
     773             : 
     774          14 : const TokenId TokenPool::StoreMatrix()
     775             : {
     776             :     ScMatrix* pM;
     777             : 
     778          14 :     if( nElementAkt >= nElement )
     779           0 :         if (!GrowElement())
     780           0 :             return static_cast<const TokenId>(nElementAkt+1);
     781             : 
     782          14 :     if( nP_MatrixAkt >= nP_Matrix )
     783           0 :         if (!GrowMatrix())
     784           0 :             return static_cast<const TokenId>(nElementAkt+1);
     785             : 
     786          14 :     pElement[ nElementAkt ] = nP_MatrixAkt;
     787          14 :     pType[ nElementAkt ] = T_Matrix;
     788             : 
     789          14 :     pM = new ScMatrix( 0, 0 );
     790          14 :     pM->IncRef( );
     791          14 :     ppP_Matrix[ nP_MatrixAkt ] = pM;
     792             : 
     793          14 :     nElementAkt++;
     794          14 :     nP_MatrixAkt++;
     795             : 
     796          14 :     return static_cast<const TokenId>(nElementAkt);
     797             : }
     798             : 
     799          28 : const TokenId TokenPool::StoreName( sal_uInt16 nIndex, bool bGlobal )
     800             : {
     801          28 :     if ( nElementAkt >= nElement )
     802           0 :         if (!GrowElement())
     803           0 :             return static_cast<const TokenId>(nElementAkt+1);
     804             : 
     805          28 :     pElement[nElementAkt] = static_cast<sal_uInt16>(maRangeNames.size());
     806          28 :     pType[nElementAkt] = T_RN;
     807             : 
     808          28 :     maRangeNames.push_back(RangeName());
     809          28 :     RangeName& r = maRangeNames.back();
     810          28 :     r.mnIndex = nIndex;
     811          28 :     r.mbGlobal = bGlobal;
     812             : 
     813          28 :     ++nElementAkt;
     814             : 
     815          28 :     return static_cast<const TokenId>(nElementAkt);
     816             : }
     817             : 
     818           0 : const TokenId TokenPool::StoreExtName( sal_uInt16 nFileId, const OUString& rName )
     819             : {
     820           0 :     if ( nElementAkt >= nElement )
     821           0 :         if (!GrowElement())
     822           0 :             return static_cast<const TokenId>(nElementAkt+1);
     823             : 
     824           0 :     pElement[nElementAkt] = static_cast<sal_uInt16>(maExtNames.size());
     825           0 :     pType[nElementAkt] = T_ExtName;
     826             : 
     827           0 :     maExtNames.push_back(ExtName());
     828           0 :     ExtName& r = maExtNames.back();
     829           0 :     r.mnFileId = nFileId;
     830           0 :     r.maName = rName;
     831             : 
     832           0 :     ++nElementAkt;
     833             : 
     834           0 :     return static_cast<const TokenId>(nElementAkt);
     835             : }
     836             : 
     837           4 : const TokenId TokenPool::StoreExtRef( sal_uInt16 nFileId, const OUString& rTabName, const ScSingleRefData& rRef )
     838             : {
     839           4 :     if ( nElementAkt >= nElement )
     840           0 :         if (!GrowElement())
     841           0 :             return static_cast<const TokenId>(nElementAkt+1);
     842             : 
     843           4 :     pElement[nElementAkt] = static_cast<sal_uInt16>(maExtCellRefs.size());
     844           4 :     pType[nElementAkt] = T_ExtRefC;
     845             : 
     846           4 :     maExtCellRefs.push_back(ExtCellRef());
     847           4 :     ExtCellRef& r = maExtCellRefs.back();
     848           4 :     r.mnFileId = nFileId;
     849           4 :     r.maTabName = rTabName;
     850           4 :     r.maRef = rRef;
     851             : 
     852           4 :     ++nElementAkt;
     853             : 
     854           4 :     return static_cast<const TokenId>(nElementAkt);
     855             : }
     856             : 
     857           0 : const TokenId TokenPool::StoreExtRef( sal_uInt16 nFileId, const OUString& rTabName, const ScComplexRefData& rRef )
     858             : {
     859           0 :     if ( nElementAkt >= nElement )
     860           0 :         if (!GrowElement())
     861           0 :             return static_cast<const TokenId>(nElementAkt+1);
     862             : 
     863           0 :     pElement[nElementAkt] = static_cast<sal_uInt16>(maExtAreaRefs.size());
     864           0 :     pType[nElementAkt] = T_ExtRefA;
     865             : 
     866           0 :     maExtAreaRefs.push_back(ExtAreaRef());
     867           0 :     ExtAreaRef& r = maExtAreaRefs.back();
     868           0 :     r.mnFileId = nFileId;
     869           0 :     r.maTabName = rTabName;
     870           0 :     r.maRef = rRef;
     871             : 
     872           0 :     ++nElementAkt;
     873             : 
     874           0 :     return static_cast<const TokenId>(nElementAkt);
     875             : }
     876             : 
     877        9082 : void TokenPool::Reset( void )
     878             : {
     879        9082 :     nP_IdAkt = nP_IdLast = nElementAkt = nP_StrAkt = nP_DblAkt = nP_ErrAkt = nP_RefTrAkt = nP_ExtAkt = nP_NlfAkt = nP_MatrixAkt = 0;
     880        9082 :     maRangeNames.clear();
     881        9082 :     maExtNames.clear();
     882        9082 :     maExtCellRefs.clear();
     883        9082 :     maExtAreaRefs.clear();
     884        9082 : }
     885             : 
     886          20 : bool TokenPool::IsSingleOp( const TokenId& rId, const DefTokenId eId ) const
     887             : {
     888          20 :     sal_uInt16 nId = (sal_uInt16) rId;
     889          20 :     if( nId && nId <= nElementAkt )
     890             :     {// existent?
     891          20 :         nId--;
     892          20 :         if( T_Id == pType[ nId ] )
     893             :         {// Token-Sequence?
     894          10 :             if( pSize[ nId ] == 1 )
     895             :             {// EXACTLY 1 Token
     896           0 :                 sal_uInt16 nPid = pElement[ nId ];
     897           0 :                 if (nPid < nP_Id)
     898             :                 {
     899           0 :                     sal_uInt16 nSecId = pP_Id[ nPid ];
     900           0 :                     if( nSecId >= nScTokenOff )
     901             :                     {// Default-Token?
     902           0 :                         return ( DefTokenId ) ( nSecId - nScTokenOff ) == eId;  // wanted?
     903             :                     }
     904             :                 }
     905             :             }
     906             :         }
     907             :     }
     908             : 
     909          20 :     return false;
     910             : }
     911             : 
     912         354 : const OUString* TokenPool::GetExternal( const TokenId& rId ) const
     913             : {
     914         354 :     const OUString*   p = NULL;
     915         354 :     sal_uInt16 n = (sal_uInt16) rId;
     916         354 :     if( n && n <= nElementAkt )
     917             :     {
     918         354 :         n--;
     919         354 :         if( pType[ n ] == T_Ext )
     920             :         {
     921         354 :             sal_uInt16 nExt = pElement[ n ];
     922         354 :             if ( nExt < nP_Ext && ppP_Ext[ nExt ] )
     923         354 :                 p = &ppP_Ext[ nExt ]->aText;
     924             :         }
     925             :     }
     926             : 
     927         354 :     return p;
     928             : }
     929             : 
     930          14 : ScMatrix* TokenPool::GetMatrix( unsigned int n ) const
     931             : {
     932          14 :     if( n < nP_MatrixAkt )
     933          14 :         return ppP_Matrix[ n ];
     934             :     else
     935           0 :         printf ("GETMATRIX %d >= %d\n", n, nP_MatrixAkt);
     936           0 :     return NULL;
     937          48 : }
     938             : 
     939             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10