LCOV - code coverage report
Current view: top level - sc/source/filter/excel - tokstack.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 505 0.0 %
Date: 2014-04-14 Functions: 0 32 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10