LCOV - code coverage report
Current view: top level - sc/source/filter/excel - namebuff.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 50 105 47.6 %
Date: 2015-06-13 12:38:46 Functions: 16 25 64.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 "namebuff.hxx"
      21             : 
      22             : #include "document.hxx"
      23             : #include "compiler.hxx"
      24             : #include "scextopt.hxx"
      25             : 
      26             : #include "root.hxx"
      27             : #include "tokstack.hxx"
      28             : #include "xltools.hxx"
      29             : #include "xiroot.hxx"
      30             : 
      31             : #include <string.h>
      32             : 
      33         129 : sal_uInt32 StringHashEntry::MakeHashCode( const OUString& r )
      34             : {
      35         129 :     sal_uInt32             n = 0;
      36         129 :     const sal_Unicode*     pAkt = r.getStr();
      37         129 :     sal_Unicode            cAkt = *pAkt;
      38             : 
      39        1016 :     while( cAkt )
      40             :     {
      41         758 :         n *= 70;
      42         758 :         n += ( sal_uInt32 ) cAkt;
      43         758 :         pAkt++;
      44         758 :         cAkt = *pAkt;
      45             :     }
      46             : 
      47         129 :     return n;
      48             : }
      49             : 
      50         855 : NameBuffer::~NameBuffer()
      51             : {
      52         285 :     std::vector<StringHashEntry*>::iterator pIter;
      53         414 :     for ( pIter = maHashes.begin(); pIter != maHashes.end(); ++pIter )
      54         129 :         delete *pIter;
      55         570 : }
      56             : 
      57             : //void NameBuffer::operator <<( const SpString &rNewString )
      58         129 : void NameBuffer::operator <<( const OUString &rNewString )
      59             : {
      60             :     OSL_ENSURE( maHashes.size() + nBase < 0xFFFF,
      61             :         "*NameBuffer::GetLastIndex(): Ich hab' die Nase voll!" );
      62             : 
      63         129 :     maHashes.push_back( new StringHashEntry( rNewString ) );
      64         129 : }
      65             : 
      66          84 : SharedFormulaBuffer::SharedFormulaBuffer( RootData* pRD ) : ExcRoot(pRD) {}
      67             : 
      68         252 : SharedFormulaBuffer::~SharedFormulaBuffer()
      69             : {
      70          84 :     Clear();
      71         168 : }
      72             : 
      73         308 : void SharedFormulaBuffer::Clear()
      74             : {
      75         308 :     TokenArraysType::iterator it = maTokenArrays.begin(), itEnd = maTokenArrays.end();
      76         430 :     for (; it != itEnd; ++it)
      77         122 :         delete it->second;
      78             : 
      79         308 :     maTokenArrays.clear();
      80         308 : }
      81             : 
      82         122 : void SharedFormulaBuffer::Store( const ScAddress& rPos, const ScTokenArray& rArray )
      83             : {
      84         122 :     ScTokenArray* pCode = rArray.Clone();
      85         122 :     pCode->GenHash();
      86         122 :     maTokenArrays.insert(TokenArraysType::value_type(rPos, pCode));
      87         122 : }
      88             : 
      89         966 : const ScTokenArray* SharedFormulaBuffer::Find( const ScAddress& rRefPos ) const
      90             : {
      91         966 :     TokenArraysType::const_iterator it = maTokenArrays.find(rRefPos);
      92         966 :     if (it == maTokenArrays.end())
      93         122 :         return NULL;
      94             : 
      95         844 :     return it->second;
      96             : }
      97             : 
      98           4 : sal_Int16 ExtSheetBuffer::Add( const OUString& rFPAN, const OUString& rTN, const bool bSWB )
      99             : {
     100           4 :     maEntries.push_back( Cont( rFPAN, rTN, bSWB ) );
     101             :     // return 1-based index of EXTERNSHEET
     102           4 :     return static_cast< sal_Int16 >( maEntries.size() );
     103             : }
     104             : 
     105           0 : bool ExtSheetBuffer::GetScTabIndex( sal_uInt16 nExcIndex, sal_uInt16& rScIndex )
     106             : {
     107             :     OSL_ENSURE( nExcIndex,
     108             :         "*ExtSheetBuffer::GetScTabIndex(): Sheet-Index == 0!" );
     109             : 
     110           0 :     if ( !nExcIndex || nExcIndex > maEntries.size() )
     111           0 :         return false;
     112             : 
     113           0 :     Cont*       pCur = &maEntries[ nExcIndex - 1 ];
     114           0 :     sal_uInt16&     rTabNum = pCur->nTabNum;
     115             : 
     116           0 :     if( rTabNum < 0xFFFD )
     117             :     {
     118           0 :         rScIndex = rTabNum;
     119           0 :         return true;
     120             :     }
     121             : 
     122           0 :     if( rTabNum == 0xFFFF )
     123             :     {// create new table
     124             :         SCTAB   nNewTabNum;
     125           0 :         if( pCur->bSWB )
     126             :         {// table is in the same workbook!
     127           0 :             if( pExcRoot->pIR->GetDoc().GetTable( pCur->aTab, nNewTabNum ) )
     128             :             {
     129           0 :                 rScIndex = rTabNum = static_cast<sal_uInt16>(nNewTabNum);
     130           0 :                 return true;
     131             :             }
     132             :             else
     133           0 :                 rTabNum = 0xFFFD;
     134             :         }
     135           0 :         else if( pExcRoot->pIR->GetDocShell() )
     136             :         {// table is 'really' external
     137           0 :             if( pExcRoot->pIR->GetExtDocOptions().GetDocSettings().mnLinkCnt == 0 )
     138             :             {
     139             :                 OUString      aURL( ScGlobal::GetAbsDocName( pCur->aFile,
     140           0 :                                     pExcRoot->pIR->GetDocShell() ) );
     141           0 :                 OUString      aTabName( ScGlobal::GetDocTabName( aURL, pCur->aTab ) );
     142           0 :                 if( pExcRoot->pIR->GetDoc().LinkExternalTab( nNewTabNum, aTabName, aURL, pCur->aTab ) )
     143             :                 {
     144           0 :                     rScIndex = rTabNum = static_cast<sal_uInt16>(nNewTabNum);
     145           0 :                     return true;
     146             :                 }
     147             :                 else
     148           0 :                     rTabNum = 0xFFFE;       // no table is created for now -> and likely
     149             :                                             //  will not be created later...
     150             :             }
     151             :             else
     152           0 :                 rTabNum = 0xFFFE;
     153             : 
     154             :         }
     155             :     }
     156             : 
     157           0 :     return false;
     158             : }
     159             : 
     160           0 : bool ExtSheetBuffer::IsLink( const sal_uInt16 nExcIndex ) const
     161             : {
     162             :     OSL_ENSURE( nExcIndex > 0, "*ExtSheetBuffer::IsLink(): Index has to be >0!" );
     163             : 
     164           0 :     if (!nExcIndex || nExcIndex > maEntries.size() )
     165           0 :         return false;
     166             : 
     167           0 :     return maEntries[ nExcIndex -1 ].bLink;
     168             : }
     169             : 
     170           0 : bool ExtSheetBuffer::GetLink( const sal_uInt16 nExcIndex, OUString& rAppl, OUString& rDoc ) const
     171             : {
     172             :     OSL_ENSURE( nExcIndex > 0, "*ExtSheetBuffer::GetLink(): Index has to be >0!" );
     173             : 
     174           0 :     if (!nExcIndex || nExcIndex > maEntries.size() )
     175           0 :         return false;
     176             : 
     177           0 :     const Cont &rRet = maEntries[ nExcIndex -1 ];
     178             : 
     179           0 :     rAppl = rRet.aFile;
     180           0 :     rDoc = rRet.aTab;
     181             : 
     182           0 :     return true;
     183             : }
     184             : 
     185         224 : void ExtSheetBuffer::Reset()
     186             : {
     187         224 :     maEntries.clear();
     188         224 : }
     189             : 
     190           0 : bool ExtName::IsDDE() const
     191             : {
     192           0 :     return ( nFlags & 0x0001 ) != 0;
     193             : }
     194             : 
     195           0 : bool ExtName::IsOLE() const
     196             : {
     197           0 :     return ( nFlags & 0x0002 ) != 0;
     198             : }
     199             : 
     200          84 : ExtNameBuff::ExtNameBuff( const XclImpRoot& rRoot ) :
     201          84 :     XclImpRoot( rRoot )
     202             : {
     203          84 : }
     204             : 
     205           0 : void ExtNameBuff::AddDDE( const OUString& rName, sal_Int16 nRefIdx )
     206             : {
     207           0 :     ExtName aNew( rName, 0x0001 );
     208           0 :     maExtNames[ nRefIdx ].push_back( aNew );
     209           0 : }
     210             : 
     211           0 : void ExtNameBuff::AddOLE( const OUString& rName, sal_Int16 nRefIdx, sal_uInt32 nStorageId )
     212             : {
     213           0 :     ExtName aNew( rName, 0x0002 );
     214           0 :     aNew.nStorageId = nStorageId;
     215           0 :     maExtNames[ nRefIdx ].push_back( aNew );
     216           0 : }
     217             : 
     218           0 : void ExtNameBuff::AddName( const OUString& rName, sal_Int16 nRefIdx )
     219             : {
     220           0 :     ExtName aNew( GetScAddInName( rName ), 0x0004 );
     221           0 :     maExtNames[ nRefIdx ].push_back( aNew );
     222           0 : }
     223             : 
     224           0 : const ExtName* ExtNameBuff::GetNameByIndex( sal_Int16 nRefIdx, sal_uInt16 nNameIdx ) const
     225             : {
     226             :     OSL_ENSURE( nNameIdx > 0, "ExtNameBuff::GetNameByIndex() - invalid name index" );
     227           0 :     ExtNameMap::const_iterator aIt = maExtNames.find( nRefIdx );
     228           0 :     return ((aIt != maExtNames.end()) && (0 < nNameIdx) && (nNameIdx <= aIt->second.size())) ? &aIt->second[ nNameIdx - 1 ] : 0;
     229             : }
     230             : 
     231           6 : void ExtNameBuff::Reset()
     232             : {
     233           6 :     maExtNames.clear();
     234          36 : }
     235             : 
     236             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11