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

Generated by: LCOV version 1.10