LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/excel - namebuff.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 62 128 48.4 %
Date: 2012-12-27 Functions: 14 25 56.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             : 
      21             : #include "namebuff.hxx"
      22             : 
      23             : #include <string.h>
      24             : 
      25             : #include "rangenam.hxx"
      26             : #include "document.hxx"
      27             : #include "compiler.hxx"
      28             : #include "scextopt.hxx"
      29             : 
      30             : #include "root.hxx"
      31             : #include "tokstack.hxx"
      32             : #include "xltools.hxx"
      33             : #include "xiroot.hxx"
      34             : 
      35             : 
      36           1 : sal_uInt32 StringHashEntry::MakeHashCode( const String& r )
      37             : {
      38           1 :     register sal_uInt32                 n = 0;
      39           1 :     const sal_Unicode*              pAkt = r.GetBuffer();
      40           1 :     register sal_Unicode            cAkt = *pAkt;
      41             : 
      42           8 :     while( cAkt )
      43             :     {
      44           6 :         n *= 70;
      45           6 :         n += ( sal_uInt32 ) cAkt;
      46           6 :         pAkt++;
      47           6 :         cAkt = *pAkt;
      48             :     }
      49             : 
      50           1 :     return n;
      51             : }
      52             : 
      53             : 
      54             : 
      55             : 
      56          66 : NameBuffer::~NameBuffer()
      57             : {
      58          22 :     std::vector<StringHashEntry*>::iterator pIter;
      59          23 :     for ( pIter = maHashes.begin(); pIter != maHashes.end(); ++pIter )
      60           1 :         delete *pIter;
      61          44 : }
      62             : 
      63             : 
      64             : //void NameBuffer::operator <<( const SpString &rNewString )
      65           1 : void NameBuffer::operator <<( const String &rNewString )
      66             : {
      67             :     OSL_ENSURE( maHashes.size() + nBase < 0xFFFF,
      68             :         "*NameBuffer::GetLastIndex(): Ich hab' die Nase voll!" );
      69             : 
      70           1 :     maHashes.push_back( new StringHashEntry( rNewString ) );
      71           1 : }
      72             : 
      73             : 
      74             : #if OSL_DEBUG_LEVEL > 0
      75             : sal_uInt16  nShrCnt;
      76             : #endif
      77             : 
      78             : 
      79          92 : size_t ShrfmlaBuffer::ScAddressHashFunc::operator() (const ScAddress &addr) const
      80             : {
      81             :     // Use something simple, it is just a hash.
      82          92 :     return static_cast< sal_uInt16 >( addr.Row() ) | (static_cast< sal_uInt8 >( addr.Col() ) << 16);
      83             : }
      84             : 
      85             : const size_t nBase = 16384; // Range~ und Shared~ Dingens mit jeweils der Haelfte Ids
      86          20 : ShrfmlaBuffer::ShrfmlaBuffer( RootData* pRD ) :
      87             :     ExcRoot( pRD ),
      88          20 :     mnCurrIdx (nBase)
      89             : {
      90             : #if OSL_DEBUG_LEVEL > 0
      91             :     nShrCnt = 0;
      92             : #endif
      93          20 : }
      94             : 
      95          40 : ShrfmlaBuffer::~ShrfmlaBuffer()
      96             : {
      97          40 : }
      98             : 
      99          75 : void ShrfmlaBuffer::Clear()
     100             : {
     101          75 :     index_hash.clear();
     102             :     // do not clear index_list, index calculation depends on complete list size...
     103             :     // do not change mnCurrIdx
     104          75 : }
     105             : 
     106          12 : void ShrfmlaBuffer::Store( const ScRange& rRange, const ScTokenArray& rToken )
     107             : {
     108          12 :     String          aName( CreateName( rRange.aStart ) );
     109             : 
     110             :     OSL_ENSURE( mnCurrIdx <= 0xFFFF, "*ShrfmlaBuffer::Store(): Gleich wird mir schlecht...!" );
     111             : 
     112          12 :     ScRangeData* pData = new ScRangeData( pExcRoot->pIR->GetDocPtr(), aName, rToken, rRange.aStart, RT_SHARED );
     113          12 :     const ScAddress& rMaxPos = pExcRoot->pIR->GetMaxPos();
     114          12 :     pData->SetMaxCol(rMaxPos.Col());
     115          12 :     pData->SetMaxRow(rMaxPos.Row());
     116          12 :     pData->SetIndex( static_cast< sal_uInt16 >( mnCurrIdx ) );
     117          12 :     pExcRoot->pIR->GetNamedRanges().insert( pData );
     118          12 :     index_hash[rRange.aStart] = static_cast< sal_uInt16 >( mnCurrIdx );
     119          12 :     index_list.push_front (rRange);
     120          12 :     ++mnCurrIdx;
     121          12 : }
     122             : 
     123             : 
     124          80 : sal_uInt16 ShrfmlaBuffer::Find( const ScAddress & aAddr ) const
     125             : {
     126          80 :     ShrfmlaHash::const_iterator hash = index_hash.find (aAddr);
     127          80 :     if (hash != index_hash.end())
     128          80 :         return hash->second;
     129             : 
     130             :     // It was not hashed on the top left corner ?  do a brute force search
     131           0 :     unsigned int ind = nBase;
     132           0 :     for (ShrfmlaList::const_iterator ptr = index_list.end(); ptr != index_list.begin() ; ind++)
     133           0 :         if ((--ptr)->In (aAddr))
     134           0 :             return static_cast< sal_uInt16 >( ind );
     135           0 :     return static_cast< sal_uInt16 >( mnCurrIdx );
     136             : }
     137             : 
     138             : 
     139             : #define SHRFMLA_BASENAME    "SHARED_FORMULA_"
     140             : 
     141          12 : String ShrfmlaBuffer::CreateName( const ScRange& r )
     142             : {
     143          12 :     String          aName( RTL_CONSTASCII_USTRINGPARAM( SHRFMLA_BASENAME ) );
     144          12 :     aName += String::CreateFromInt32( r.aStart.Col() );
     145          12 :     aName.Append( '_' );
     146          12 :     aName += String::CreateFromInt32( r.aStart.Row() );
     147          12 :     aName.Append( '_' );
     148          12 :     aName += String::CreateFromInt32( r.aEnd.Col() );
     149          12 :     aName.Append( '_' );
     150          12 :     aName += String::CreateFromInt32( r.aEnd.Row() );
     151          12 :     aName.Append( '_' );
     152          12 :     aName += String::CreateFromInt32( r.aStart.Tab() );
     153             : 
     154          12 :     return aName;
     155             : }
     156             : 
     157           0 : sal_Int16 ExtSheetBuffer::Add( const String& rFPAN, const String& rTN, const sal_Bool bSWB )
     158             : {
     159           0 :     maEntries.push_back( Cont( rFPAN, rTN, bSWB ) );
     160             :     // return 1-based index of EXTERNSHEET
     161           0 :     return static_cast< sal_Int16 >( maEntries.size() );
     162             : }
     163             : 
     164             : 
     165           0 : sal_Bool ExtSheetBuffer::GetScTabIndex( sal_uInt16 nExcIndex, sal_uInt16& rScIndex )
     166             : {
     167             :     OSL_ENSURE( nExcIndex,
     168             :         "*ExtSheetBuffer::GetScTabIndex(): Sheet-Index == 0!" );
     169             : 
     170           0 :     if ( !nExcIndex || nExcIndex > maEntries.size() )
     171           0 :         return false;
     172             : 
     173           0 :     Cont*       pCur = &maEntries[ nExcIndex - 1 ];
     174           0 :     sal_uInt16&     rTabNum = pCur->nTabNum;
     175             : 
     176           0 :     if( rTabNum < 0xFFFD )
     177             :     {
     178           0 :         rScIndex = rTabNum;
     179           0 :         return sal_True;
     180             :     }
     181             : 
     182           0 :     if( rTabNum == 0xFFFF )
     183             :     {// neue Tabelle erzeugen
     184             :         SCTAB   nNewTabNum;
     185           0 :         if( pCur->bSWB )
     186             :         {// Tabelle ist im selben Workbook!
     187           0 :             if( pExcRoot->pIR->GetDoc().GetTable( pCur->aTab, nNewTabNum ) )
     188             :             {
     189           0 :                 rScIndex = rTabNum = static_cast<sal_uInt16>(nNewTabNum);
     190           0 :                 return sal_True;
     191             :             }
     192             :             else
     193           0 :                 rTabNum = 0xFFFD;
     194             :         }
     195           0 :         else if( pExcRoot->pIR->GetDocShell() )
     196             :         {// Tabelle ist 'echt' extern
     197           0 :             if( pExcRoot->pIR->GetExtDocOptions().GetDocSettings().mnLinkCnt == 0 )
     198             :             {
     199             :                 String      aURL( ScGlobal::GetAbsDocName( pCur->aFile,
     200           0 :                                     pExcRoot->pIR->GetDocShell() ) );
     201           0 :                 String      aTabName( ScGlobal::GetDocTabName( aURL, pCur->aTab ) );
     202           0 :                 if( pExcRoot->pIR->GetDoc().LinkExternalTab( nNewTabNum, aTabName, aURL, pCur->aTab ) )
     203             :                 {
     204           0 :                     rScIndex = rTabNum = static_cast<sal_uInt16>(nNewTabNum);
     205           0 :                     return sal_True;
     206             :                 }
     207             :                 else
     208           0 :                     rTabNum = 0xFFFE;       // Tabelle einmal nicht angelegt -> wird
     209             :                                             //  wohl auch nicht mehr gehen...
     210             :             }
     211             :             else
     212           0 :                 rTabNum = 0xFFFE;
     213             : 
     214             :         }
     215             :     }
     216             : 
     217           0 :     return false;
     218             : }
     219             : 
     220             : 
     221           0 : sal_Bool ExtSheetBuffer::IsLink( const sal_uInt16 nExcIndex ) const
     222             : {
     223             :     OSL_ENSURE( nExcIndex > 0, "*ExtSheetBuffer::IsLink(): Index muss >0 sein!" );
     224             : 
     225           0 :     if (!nExcIndex || nExcIndex > maEntries.size() )
     226           0 :         return false;
     227             : 
     228           0 :     return maEntries[ nExcIndex -1 ].bLink;
     229             : }
     230             : 
     231             : 
     232           0 : sal_Bool ExtSheetBuffer::GetLink( const sal_uInt16 nExcIndex, String& rAppl, String& rDoc ) const
     233             : {
     234             :     OSL_ENSURE( nExcIndex > 0, "*ExtSheetBuffer::GetLink(): Index muss >0 sein!" );
     235             : 
     236           0 :     if (!nExcIndex || nExcIndex > maEntries.size() )
     237           0 :         return false;
     238             : 
     239           0 :     const Cont &rRet = maEntries[ nExcIndex -1 ];
     240             : 
     241           0 :     rAppl = rRet.aFile;
     242           0 :     rDoc = rRet.aTab;
     243             : 
     244           0 :     return true;
     245             : }
     246             : 
     247             : 
     248          75 : void ExtSheetBuffer::Reset( void )
     249             : {
     250          75 :     maEntries.clear();
     251          75 : }
     252             : 
     253             : 
     254             : 
     255             : 
     256           0 : sal_Bool ExtName::IsDDE( void ) const
     257             : {
     258           0 :     return ( nFlags & 0x0001 ) != 0;
     259             : }
     260             : 
     261             : 
     262           0 : sal_Bool ExtName::IsOLE( void ) const
     263             : {
     264           0 :     return ( nFlags & 0x0002 ) != 0;
     265             : }
     266             : 
     267             : 
     268          20 : ExtNameBuff::ExtNameBuff( const XclImpRoot& rRoot ) :
     269          20 :     XclImpRoot( rRoot )
     270             : {
     271          20 : }
     272             : 
     273             : 
     274           0 : void ExtNameBuff::AddDDE( const String& rName, sal_Int16 nRefIdx )
     275             : {
     276           0 :     ExtName aNew( rName, 0x0001 );
     277           0 :     maExtNames[ nRefIdx ].push_back( aNew );
     278           0 : }
     279             : 
     280             : 
     281           0 : void ExtNameBuff::AddOLE( const String& rName, sal_Int16 nRefIdx, sal_uInt32 nStorageId )
     282             : {
     283           0 :     ExtName aNew( rName, 0x0002 );
     284           0 :     aNew.nStorageId = nStorageId;
     285           0 :     maExtNames[ nRefIdx ].push_back( aNew );
     286           0 : }
     287             : 
     288             : 
     289           0 : void ExtNameBuff::AddName( const String& rName, sal_Int16 nRefIdx )
     290             : {
     291           0 :     ExtName aNew( GetScAddInName( rName ), 0x0004 );
     292           0 :     maExtNames[ nRefIdx ].push_back( aNew );
     293           0 : }
     294             : 
     295             : 
     296           0 : const ExtName* ExtNameBuff::GetNameByIndex( sal_Int16 nRefIdx, sal_uInt16 nNameIdx ) const
     297             : {
     298             :     OSL_ENSURE( nNameIdx > 0, "ExtNameBuff::GetNameByIndex() - invalid name index" );
     299           0 :     ExtNameMap::const_iterator aIt = maExtNames.find( nRefIdx );
     300           0 :     return ((aIt != maExtNames.end()) && (0 < nNameIdx) && (nNameIdx <= aIt->second.size())) ? &aIt->second[ nNameIdx - 1 ] : 0;
     301             : }
     302             : 
     303             : 
     304           0 : void ExtNameBuff::Reset( void )
     305             : {
     306           0 :     maExtNames.clear();
     307           0 : }
     308             : 
     309             : 
     310             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10