LCOV - code coverage report
Current view: top level - sc/source/core/tool - tokenstringcontext.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 76 77 98.7 %
Date: 2014-04-11 Functions: 9 9 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          23 : void insertAllNames( TokenStringContext::IndexNameMapType& rMap, const ScRangeName& rNames )
      23             : {
      24          23 :     ScRangeName::const_iterator it = rNames.begin(), itEnd = rNames.end();
      25          48 :     for (; it != itEnd; ++it)
      26             :     {
      27          25 :         const ScRangeData* pData = it->second;
      28             :         rMap.insert(
      29          25 :             TokenStringContext::IndexNameMapType::value_type(pData->GetIndex(), pData->GetName()));
      30             :     }
      31          23 : }
      32             : 
      33             : }
      34             : 
      35          17 : TokenStringContext::TokenStringContext( const ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ) :
      36             :     meGram(eGram),
      37          17 :     mpRefConv(ScCompiler::GetRefConvention(formula::FormulaGrammar::extractRefConvention(eGram)))
      38             : {
      39          17 :     ScCompiler aComp(NULL, ScAddress());
      40          17 :     mxOpCodeMap = aComp.GetOpCodeMap(formula::FormulaGrammar::extractFormulaLanguage(eGram));
      41          17 :     if (mxOpCodeMap)
      42          17 :         maErrRef = mxOpCodeMap->getSymbol(ocErrRef);
      43             : 
      44          17 :     if (!pDoc)
      45          17 :         return;
      46             : 
      47             :     // Fetch all sheet names.
      48          17 :     maTabNames = pDoc->GetAllTableNames();
      49             :     {
      50          17 :         std::vector<OUString>::iterator it = maTabNames.begin(), itEnd = maTabNames.end();
      51          53 :         for (; it != itEnd; ++it)
      52          36 :             ScCompiler::CheckTabQuotes(*it, formula::FormulaGrammar::extractRefConvention(eGram));
      53             :     }
      54             : 
      55             :     // Fetch all named range names.
      56          17 :     const ScRangeName* pNames = pDoc->GetRangeName();
      57          17 :     if (pNames)
      58             :         // global names
      59          17 :         insertAllNames(maGlobalRangeNames, *pNames);
      60             : 
      61             :     {
      62          17 :         ScRangeName::TabNameCopyMap aTabRangeNames;
      63          17 :         pDoc->GetAllTabRangeNames(aTabRangeNames);
      64          17 :         ScRangeName::TabNameCopyMap::const_iterator it = aTabRangeNames.begin(), itEnd = aTabRangeNames.end();
      65          23 :         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          23 :         }
      76             :     }
      77             : 
      78             :     // Fetch all named database ranges names.
      79          17 :     const ScDBCollection* pDBs = pDoc->GetDBCollection();
      80          17 :     if (pDBs)
      81             :     {
      82          17 :         const ScDBCollection::NamedDBs& rNamedDBs = pDBs->getNamedDBs();
      83          17 :         ScDBCollection::NamedDBs::const_iterator it = rNamedDBs.begin(), itEnd = rNamedDBs.end();
      84          20 :         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          17 :     if (pDoc->HasExternalRefManager())
      93             :     {
      94          15 :         const ScExternalRefManager* pRefMgr = pDoc->GetExternalRefManager();
      95          15 :         maExternalFileNames = pRefMgr->getAllCachedExternalFileNames();
      96          16 :         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          17 :     }
     106             : }
     107             : 
     108         275 : CompileFormulaContext::CompileFormulaContext( ScDocument* pDoc ) :
     109         275 :     mpDoc(pDoc), meGram(pDoc->GetGrammar())
     110             : {
     111         275 :     updateTabNames();
     112         275 : }
     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         300 : void CompileFormulaContext::updateTabNames()
     121             : {
     122             :     // Fetch all sheet names.
     123         300 :     maTabNames = mpDoc->GetAllTableNames();
     124             :     {
     125         300 :         std::vector<OUString>::iterator it = maTabNames.begin(), itEnd = maTabNames.end();
     126         963 :         for (; it != itEnd; ++it)
     127         663 :             ScCompiler::CheckTabQuotes(*it, formula::FormulaGrammar::extractRefConvention(meGram));
     128             :     }
     129         300 : }
     130             : 
     131         749 : formula::FormulaGrammar::Grammar CompileFormulaContext::getGrammar() const
     132             : {
     133         749 :     return meGram;
     134             : }
     135             : 
     136         698 : void CompileFormulaContext::setGrammar( formula::FormulaGrammar::Grammar eGram )
     137             : {
     138         698 :     bool bUpdate = (meGram != eGram);
     139         698 :     meGram = eGram;
     140         698 :     if (bUpdate)
     141          22 :         updateTabNames();
     142         698 : }
     143             : 
     144         745 : const std::vector<OUString>& CompileFormulaContext::getTabNames() const
     145             : {
     146         745 :     return maTabNames;
     147             : }
     148             : 
     149         745 : ScDocument* CompileFormulaContext::getDoc()
     150             : {
     151         745 :     return mpDoc;
     152             : }
     153             : 
     154             : }
     155             : 
     156             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10