LCOV - code coverage report
Current view: top level - sc/source/core/tool - tokenstringcontext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 71 72 98.6 %
Date: 2015-06-13 12:38:46 Functions: 8 8 100.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             : 
      10             : #include "tokenstringcontext.hxx"
      11             : #include "compiler.hxx"
      12             : #include "document.hxx"
      13             : #include "dbdata.hxx"
      14             : #include "externalrefmgr.hxx"
      15             : 
      16             : using namespace com::sun::star;
      17             : 
      18             : namespace sc {
      19             : 
      20             : namespace {
      21             : 
      22          38 : void insertAllNames( TokenStringContext::IndexNameMapType& rMap, const ScRangeName& rNames )
      23             : {
      24          38 :     ScRangeName::const_iterator it = rNames.begin(), itEnd = rNames.end();
      25          65 :     for (; it != itEnd; ++it)
      26             :     {
      27          27 :         const ScRangeData* pData = it->second;
      28             :         rMap.insert(
      29          27 :             TokenStringContext::IndexNameMapType::value_type(pData->GetIndex(), pData->GetName()));
      30             :     }
      31          38 : }
      32             : 
      33             : }
      34             : 
      35          32 : TokenStringContext::TokenStringContext( const ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ) :
      36             :     meGram(eGram),
      37          32 :     mpRefConv(ScCompiler::GetRefConvention(formula::FormulaGrammar::extractRefConvention(eGram)))
      38             : {
      39          32 :     ScCompiler aComp(NULL, ScAddress());
      40          32 :     mxOpCodeMap = aComp.GetOpCodeMap(formula::FormulaGrammar::extractFormulaLanguage(eGram));
      41          32 :     if (mxOpCodeMap)
      42          32 :         maErrRef = mxOpCodeMap->getSymbol(ocErrRef);
      43             : 
      44          32 :     if (!pDoc)
      45          32 :         return;
      46             : 
      47             :     // Fetch all sheet names.
      48          32 :     maTabNames = pDoc->GetAllTableNames();
      49             :     {
      50          32 :         std::vector<OUString>::iterator it = maTabNames.begin(), itEnd = maTabNames.end();
      51          96 :         for (; it != itEnd; ++it)
      52          64 :             ScCompiler::CheckTabQuotes(*it, formula::FormulaGrammar::extractRefConvention(eGram));
      53             :     }
      54             : 
      55             :     // Fetch all named range names.
      56          32 :     const ScRangeName* pNames = pDoc->GetRangeName();
      57          32 :     if (pNames)
      58             :         // global names
      59          32 :         insertAllNames(maGlobalRangeNames, *pNames);
      60             : 
      61             :     {
      62          32 :         ScRangeName::TabNameCopyMap aTabRangeNames;
      63          32 :         pDoc->GetAllTabRangeNames(aTabRangeNames);
      64          32 :         ScRangeName::TabNameCopyMap::const_iterator it = aTabRangeNames.begin(), itEnd = aTabRangeNames.end();
      65          38 :         for (; it != itEnd; ++it)
      66             :         {
      67           6 :             const ScRangeName* pSheetNames = it->second;
      68           6 :             if (!pSheetNames)
      69           0 :                 continue;
      70             : 
      71           6 :             SCTAB nTab = it->first;
      72           6 :             IndexNameMapType aNames;
      73           6 :             insertAllNames(aNames, *pSheetNames);
      74           6 :             maSheetRangeNames.insert(TabIndexMapType::value_type(nTab, aNames));
      75          38 :         }
      76             :     }
      77             : 
      78             :     // Fetch all named database ranges names.
      79          32 :     const ScDBCollection* pDBs = pDoc->GetDBCollection();
      80          32 :     if (pDBs)
      81             :     {
      82          32 :         const ScDBCollection::NamedDBs& rNamedDBs = pDBs->getNamedDBs();
      83          32 :         ScDBCollection::NamedDBs::const_iterator it = rNamedDBs.begin(), itEnd = rNamedDBs.end();
      84          35 :         for (; it != itEnd; ++it)
      85             :         {
      86           3 :             const ScDBData& rData = *it;
      87           3 :             maNamedDBs.insert(IndexNameMapType::value_type(rData.GetIndex(), rData.GetName()));
      88             :         }
      89             :     }
      90             : 
      91             :     // Fetch all relevant bits for external references.
      92          32 :     if (pDoc->HasExternalRefManager())
      93             :     {
      94          28 :         const ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
      95          28 :         maExternalFileNames = pRefMgr->getAllCachedExternalFileNames();
      96          29 :         for (size_t i = 0, n = maExternalFileNames.size(); i < n; ++i)
      97             :         {
      98           1 :             sal_uInt16 nFileId = static_cast<sal_uInt16>(i);
      99           1 :             std::vector<OUString> aTabNames;
     100           1 :             pRefMgr->getAllCachedTableNames(nFileId, aTabNames);
     101           1 :             if (!aTabNames.empty())
     102             :                 maExternalCachedTabNames.insert(
     103           1 :                     IndexNamesMapType::value_type(nFileId, aTabNames));
     104           1 :         }
     105          32 :     }
     106             : }
     107             : 
     108         453 : CompileFormulaContext::CompileFormulaContext( ScDocument* pDoc ) :
     109         453 :     mpDoc(pDoc), meGram(pDoc->GetGrammar())
     110             : {
     111         453 :     updateTabNames();
     112         453 : }
     113             : 
     114           3 : CompileFormulaContext::CompileFormulaContext( ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ) :
     115           3 :     mpDoc(pDoc), meGram(eGram)
     116             : {
     117           3 :     updateTabNames();
     118           3 : }
     119             : 
     120         498 : void CompileFormulaContext::updateTabNames()
     121             : {
     122             :     // Fetch all sheet names.
     123         498 :     maTabNames = mpDoc->GetAllTableNames();
     124             :     {
     125         498 :         std::vector<OUString>::iterator it = maTabNames.begin(), itEnd = maTabNames.end();
     126        1505 :         for (; it != itEnd; ++it)
     127        1007 :             ScCompiler::CheckTabQuotes(*it, formula::FormulaGrammar::extractRefConvention(meGram));
     128             :     }
     129         498 : }
     130             : 
     131        1551 : void CompileFormulaContext::setGrammar( formula::FormulaGrammar::Grammar eGram )
     132             : {
     133        1551 :     bool bUpdate = (meGram != eGram);
     134        1551 :     meGram = eGram;
     135        1551 :     if (bUpdate)
     136          42 :         updateTabNames();
     137        1551 : }
     138             : 
     139         156 : }
     140             : 
     141             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11