LibreOffice Module sc (master)  1
tokenstringcontext.cxx
Go to the documentation of this file.
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 #include <globstr.hrc>
16 #include <scresid.hxx>
17 
18 using namespace com::sun::star;
19 
20 namespace sc {
21 
22 namespace {
23 
24 void insertAllNames( TokenStringContext::IndexNameMapType& rMap, const ScRangeName& rNames )
25 {
26  for (auto const& it : rNames)
27  {
28  const ScRangeData *const pData = it.second.get();
29  rMap.emplace(pData->GetIndex(), pData->GetName());
30  }
31 }
32 
33 }
34 
35 TokenStringContext::TokenStringContext( const ScDocument& rDoc, formula::FormulaGrammar::Grammar eGram ) :
36  meGram(eGram),
37  mpRefConv(ScCompiler::GetRefConvention(formula::FormulaGrammar::extractRefConvention(eGram)))
38 {
41  if (mxOpCodeMap)
42  maErrRef = mxOpCodeMap->getSymbol(ocErrRef);
43  else
44  {
45  assert(!"TokenStringContext - no OpCodeMap?!?");
46  maErrRef = ScResId(STR_NO_REF_TABLE);
47  }
48 
49  // Fetch all sheet names.
51  {
52  for (auto& rTabName : maTabNames)
54  }
55 
56  // Fetch all named range names.
57  const ScRangeName* pNames = rDoc.GetRangeName();
58  if (pNames)
59  // global names
60  insertAllNames(maGlobalRangeNames, *pNames);
61 
62  {
63  ScRangeName::TabNameCopyMap aTabRangeNames;
64  rDoc.GetAllTabRangeNames(aTabRangeNames);
65  for (const auto& [nTab, pSheetNames] : aTabRangeNames)
66  {
67  if (!pSheetNames)
68  continue;
69 
70  IndexNameMapType aNames;
71  insertAllNames(aNames, *pSheetNames);
72  maSheetRangeNames.emplace(nTab, aNames);
73  }
74  }
75 
76  // Fetch all named database ranges names.
77  const ScDBCollection* pDBs = rDoc.GetDBCollection();
78  if (pDBs)
79  {
80  const ScDBCollection::NamedDBs& rNamedDBs = pDBs->getNamedDBs();
81  for (const auto& rxNamedDB : rNamedDBs)
82  {
83  const ScDBData& rData = *rxNamedDB;
84  maNamedDBs.emplace(rData.GetIndex(), rData.GetName());
85  }
86  }
87 
88  // Fetch all relevant bits for external references.
89  if (!rDoc.HasExternalRefManager())
90  return;
91 
92  const ScExternalRefManager* pRefMgr = rDoc.GetExternalRefManager();
94  for (size_t i = 0, n = maExternalFileNames.size(); i < n; ++i)
95  {
96  sal_uInt16 nFileId = static_cast<sal_uInt16>(i);
97  std::vector<OUString> aTabNames;
98  pRefMgr->getAllCachedTableNames(nFileId, aTabNames);
99  if (!aTabNames.empty())
100  maExternalCachedTabNames.emplace(nFileId, aTabNames);
101  }
102 }
103 
105  mrDoc(rDoc), meGram(rDoc.GetGrammar())
106 {
107  updateTabNames();
108 }
109 
111  mrDoc(rDoc), meGram(eGram)
112 {
113  updateTabNames();
114 }
115 
117 {
118  // Fetch all sheet names.
120  {
121  for (auto& rTabName : maTabNames)
123  }
124 }
125 
127 {
128  bool bUpdate = (meGram != eGram);
129  meGram = eGram;
130  if (bUpdate)
131  updateTabNames();
132 }
133 
134 }
135 
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool HasExternalRefManager() const
Definition: document.hxx:1009
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:822
std::unique_ptr< ContentProperties > pData
formula::FormulaGrammar::Grammar meGram
sal_uInt16 GetIndex() const
Definition: rangenam.hxx:117
SC_DLLPUBLIC std::vector< OUString > GetAllTableNames() const
Definition: document.cxx:287
SC_DLLPUBLIC ScRangeName * GetRangeName(SCTAB nTab) const
Definition: documen3.cxx:168
std::vector< OUString > getAllCachedExternalFileNames() const
Get all cached external file names as an array.
sal_Int64 n
const ContentProperties & rData
::std::map< SCTAB, const ScRangeName * > TabNameCopyMap
Map that stores non-managed pointers to ScRangeName instances.
Definition: rangenam.hxx:194
CompileFormulaContext(ScDocument &rDoc)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
std::vector< OUString > maTabNames
formula::FormulaCompiler::OpCodeMapPtr mxOpCodeMap
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
Definition: documen3.cxx:618
static AddressConvention extractRefConvention(const Grammar eGrammar)
void GetName(OUString &rName) const
Definition: rangenam.hxx:111
sal_uInt16 GetIndex() const
Definition: dbdata.hxx:135
OpCodeMapPtr GetOpCodeMap(const sal_Int32 nLanguage) const
std::unordered_map< sal_uInt16, OUString > IndexNameMapType
std::vector< OUString > maTabNames
static sal_Int32 extractFormulaLanguage(const Grammar eGrammar)
int i
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
const OUString & GetName() const
Definition: dbdata.hxx:122
std::vector< OUString > maExternalFileNames
void getAllCachedTableNames(sal_uInt16 nFileId,::std::vector< OUString > &rTabNames) const
Returns a vector containing all (real) table names and cache tables of the specified file...
IndexNameMapType maGlobalRangeNames
void setGrammar(formula::FormulaGrammar::Grammar eGram)
TabIndexMapType maSheetRangeNames
Stores global named database ranges.
Definition: dbdata.hxx:235
IndexNamesMapType maExternalCachedTabNames
NamedDBs & getNamedDBs()
Definition: dbdata.hxx:315
ocErrRef
static void CheckTabQuotes(OUString &aTabName, const formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO)
all
Definition: compiler.cxx:1933
SC_DLLPUBLIC void GetAllTabRangeNames(ScRangeName::TabNameCopyMap &rRangeNames) const
Get all range names that are local to each table.
Definition: documen3.cxx:102