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

Generated by: LCOV version 1.10