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

Generated by: LCOV version 1.10