Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / inc / tokenstringcontext.hxx
blobd6292e5dcbb5c0d3fb91da37710ad4d0b7582e00
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #pragma once
12 #include "compiler.hxx"
14 #include <unordered_map>
16 class ScDocument;
18 namespace sc
20 /**
21 * Context for creating string from an array of formula tokens, used in
22 * ScTokenArray::CreateString(). You can re-use the same string context
23 * between multiple CreateString() calls as long as the document content is
24 * unmodified.
26 struct SC_DLLPUBLIC TokenStringContext
28 typedef std::unordered_map<sal_uInt16, OUString> IndexNameMapType;
29 typedef std::unordered_map<size_t, std::vector<OUString>> IndexNamesMapType;
30 typedef std::unordered_map<SCTAB, IndexNameMapType> TabIndexMapType;
32 formula::FormulaGrammar::Grammar meGram;
33 formula::FormulaCompiler::OpCodeMapPtr mxOpCodeMap;
34 const ScCompiler::Convention* mpRefConv;
35 OUString maErrRef;
37 std::vector<OUString> maTabNames;
38 IndexNameMapType maGlobalRangeNames;
39 TabIndexMapType maSheetRangeNames;
40 IndexNameMapType maNamedDBs;
42 std::vector<OUString> maExternalFileNames;
43 IndexNamesMapType maExternalCachedTabNames;
45 TokenStringContext(const ScDocument& rDoc, formula::FormulaGrammar::Grammar eGram);
48 class SC_DLLPUBLIC CompileFormulaContext
50 ScDocument& mrDoc;
51 formula::FormulaGrammar::Grammar meGram;
52 std::vector<OUString> maTabNames;
54 void updateTabNames();
56 public:
57 CompileFormulaContext(ScDocument& rDoc);
58 CompileFormulaContext(ScDocument& rDoc, formula::FormulaGrammar::Grammar eGram);
60 formula::FormulaGrammar::Grammar getGrammar() const { return meGram; }
61 void setGrammar(formula::FormulaGrammar::Grammar eGram);
63 const std::vector<OUString>& getTabNames() const { return maTabNames; }
65 ScDocument& getDoc() { return mrDoc; }
69 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */