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
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
18using namespace com::sun::star;
19
20namespace sc {
21
22namespace {
23
24void 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
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{
108}
109
111 mrDoc(rDoc), meGram(eGram)
112{
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)
132}
133
134}
135
136/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static void CheckTabQuotes(OUString &aTabName, const formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO)
all
Definition: compiler.cxx:1954
Stores global named database ranges.
Definition: dbdata.hxx:243
NamedDBs & getNamedDBs()
Definition: dbdata.hxx:324
const OUString & GetName() const
Definition: dbdata.hxx:127
sal_uInt16 GetIndex() const
Definition: dbdata.hxx:141
SC_DLLPUBLIC std::vector< OUString > GetAllTableNames() const
Definition: document.cxx:270
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
Definition: documen3.cxx:625
SC_DLLPUBLIC void GetAllTabRangeNames(ScRangeName::TabNameCopyMap &rRangeNames) const
Get all range names that are local to each table.
Definition: documen3.cxx:107
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:827
SC_DLLPUBLIC ScRangeName * GetRangeName(SCTAB nTab) const
Definition: documen3.cxx:171
bool HasExternalRefManager() const
Definition: document.hxx:1028
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.
std::vector< OUString > getAllCachedExternalFileNames() const
Get all cached external file names as an array.
::std::map< SCTAB, const ScRangeName * > TabNameCopyMap
Map that stores non-managed pointers to ScRangeName instances.
Definition: rangenam.hxx:201
OpCodeMapPtr GetOpCodeMap(const sal_Int32 nLanguage) const
static sal_Int32 extractFormulaLanguage(const Grammar eGrammar)
static AddressConvention extractRefConvention(const Grammar eGrammar)
CompileFormulaContext(ScDocument &rDoc)
formula::FormulaGrammar::Grammar meGram
std::vector< OUString > maTabNames
void setGrammar(formula::FormulaGrammar::Grammar eGram)
sal_Int64 n
std::unique_ptr< sal_Int32[]> pData
int i
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
ocErrRef
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
formula::FormulaCompiler::OpCodeMapPtr mxOpCodeMap
std::vector< OUString > maExternalFileNames
TokenStringContext(const ScDocument &rDoc, formula::FormulaGrammar::Grammar eGram)
IndexNamesMapType maExternalCachedTabNames
TabIndexMapType maSheetRangeNames
std::vector< OUString > maTabNames
IndexNameMapType maGlobalRangeNames
std::unordered_map< sal_uInt16, OUString > IndexNameMapType