LibreOffice Module sc (master) 1
namebuff.hxx
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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <memory>
23#include <map>
24#include <utility>
25#include <vector>
26#include <rtl/ustring.hxx>
27#include "root.hxx"
28#include "xiroot.hxx"
29#include <refdata.hxx>
30#include <tokenarray.hxx>
31
32#include <unordered_map>
33
35{
36private:
37 OUString aString;
38 sal_uInt32 nHash;
39
40 static sal_uInt32 MakeHashCode( const OUString& );
41public:
42 inline StringHashEntry( const OUString& );
43 inline bool operator ==( const StringHashEntry& ) const;
44};
45
46inline StringHashEntry::StringHashEntry( const OUString& r )
47 : aString( r )
48 , nHash( MakeHashCode(r) )
49{
50}
51
52inline bool StringHashEntry::operator ==( const StringHashEntry& r ) const
53{
54 return ( nHash == r.nHash && aString == r.aString );
55}
56
61{
62 typedef std::unordered_map<ScAddress, ScTokenArray, ScAddressHashFunctor> TokenArraysType;
64
65public:
67 virtual ~SharedFormulaBuffer();
68 void Clear();
69 void Store( const ScAddress& rPos, const ScTokenArray& rArray );
70 const ScTokenArray* Find( const ScAddress& rRefPos ) const;
71};
72
74{
75private:
76 struct Entry
77 {
80 sal_uInt16 nAbsInd; // == 0 -> no Abs-Name yet!
81 sal_uInt16 nRelInd;
83 Entry( const OUString& rName, const ScComplexRefData& rCRD )
84 : aStrHashEntry( rName )
85 , aScComplexRefDataRel( rCRD )
86 , nAbsInd(0)
87 , nRelInd(0)
88 , bSingleRef(false)
89 {
90 }
91 };
92
93 std::unique_ptr<ScTokenArray>
95 sal_uInt16 nIntCount;
96 std::vector<Entry> maEntries;
97
98public:
99 RangeNameBufferWK3(const ScDocument& rDoc);
101 void Add( const ScDocument& rDoc, const OUString& rName, const ScComplexRefData& rCRD );
102 inline void Add( const ScDocument& rDoc, const OUString& rName, const ScRange& aScRange );
103 bool FindRel( const OUString& rRef, sal_uInt16& rIndex );
104 bool FindAbs( std::u16string_view rRef, sal_uInt16& rIndex );
105};
106
107inline void RangeNameBufferWK3::Add( const ScDocument& rDoc, const OUString& rName, const ScRange& aScRange )
108{
109 ScComplexRefData aCRD;
110 ScSingleRefData* pSRD;
111
112 pSRD = &aCRD.Ref1;
113 pSRD->InitAddress(aScRange.aStart);
114 pSRD->SetFlag3D(true);
115
116 pSRD = &aCRD.Ref2;
117 pSRD->InitAddress(aScRange.aEnd);
118 pSRD->SetFlag3D(true);
119
120 Add( rDoc, rName, aCRD );
121}
122
124{
125private:
126 struct Cont
127 {
128 OUString aFile;
129 OUString aTab;
130 sal_uInt16 nTabNum; // 0xFFFF -> not set yet
131 // 0xFFFE -> tried to set, but failed
132 // 0xFFFD -> should be in the same workbook, but not found
133 bool bSWB;
134 Cont( OUString aFilePathAndName, OUString aTabName,
135 const bool bSameWB ) :
136 aFile(std::move( aFilePathAndName )),
137 aTab(std::move( aTabName ))
138 {
139 nTabNum = 0xFFFF; // -> table not created yet
140 bSWB = bSameWB;
141 }
142 };
143
144 std::vector<Cont> maEntries;
145
146public:
147 inline ExtSheetBuffer( RootData* );
148
149 sal_Int16 Add( const OUString& rFilePathAndName,
150 const OUString& rTabName, const bool bSameWorkbook );
151
152 bool GetScTabIndex( sal_uInt16 nExcSheetIndex, sal_uInt16& rIn_LastTab_Out_ScIndex );
153
154 void Reset();
155};
156
158{
159}
160
162{
163 sal_uInt32 nStorageId;
164 sal_uInt16 nFlags;
165
166 ExtName( sal_uInt16 n ) : nStorageId( 0 ), nFlags( n ) {}
167
168 bool IsOLE() const;
169};
170
171class ExtNameBuff : protected XclImpRoot
172{
173public:
174 explicit ExtNameBuff( const XclImpRoot& rRoot );
175
176 void AddDDE( sal_Int16 nRefIdx );
177 void AddOLE( sal_Int16 nRefIdx, sal_uInt32 nStorageId );
178 void AddName( sal_Int16 nRefIdx );
179
180 const ExtName* GetNameByIndex( sal_Int16 nRefIdx, sal_uInt16 nNameIdx ) const;
181
182 void Reset();
183
184private:
185 typedef ::std::vector< ExtName > ExtNameVec;
186 typedef ::std::map< sal_Int16, ExtNameVec > ExtNameMap;
187
189};
190
191/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: root.hxx:67
ExtNameBuff(const XclImpRoot &rRoot)
Definition: namebuff.cxx:151
void AddDDE(sal_Int16 nRefIdx)
Definition: namebuff.cxx:156
::std::vector< ExtName > ExtNameVec
Definition: namebuff.hxx:185
void AddOLE(sal_Int16 nRefIdx, sal_uInt32 nStorageId)
Definition: namebuff.cxx:162
::std::map< sal_Int16, ExtNameVec > ExtNameMap
Definition: namebuff.hxx:186
const ExtName * GetNameByIndex(sal_Int16 nRefIdx, sal_uInt16 nNameIdx) const
Definition: namebuff.cxx:175
void AddName(sal_Int16 nRefIdx)
Definition: namebuff.cxx:169
ExtNameMap maExtNames
Definition: namebuff.hxx:188
void Reset()
Definition: namebuff.cxx:182
std::vector< Cont > maEntries
Definition: namebuff.hxx:144
ExtSheetBuffer(RootData *)
Definition: namebuff.hxx:157
sal_Int16 Add(const OUString &rFilePathAndName, const OUString &rTabName, const bool bSameWorkbook)
Definition: namebuff.cxx:79
bool GetScTabIndex(sal_uInt16 nExcSheetIndex, sal_uInt16 &rIn_LastTab_Out_ScIndex)
Definition: namebuff.cxx:86
void Add(const ScDocument &rDoc, const OUString &rName, const ScComplexRefData &rCRD)
Definition: tool.cxx:439
std::unique_ptr< ScTokenArray > pScTokenArray
Definition: namebuff.hxx:94
std::vector< Entry > maEntries
Definition: namebuff.hxx:96
sal_uInt16 nIntCount
Definition: namebuff.hxx:95
bool FindAbs(std::u16string_view rRef, sal_uInt16 &rIndex)
Definition: tool.cxx:481
bool FindRel(const OUString &rRef, sal_uInt16 &rIndex)
Definition: tool.cxx:466
RangeNameBufferWK3(const ScDocument &rDoc)
Definition: tool.cxx:429
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
Store and manage shared formula tokens.
Definition: namebuff.hxx:61
virtual ~SharedFormulaBuffer()
Definition: namebuff.cxx:53
SharedFormulaBuffer(RootData *pRD)
Definition: namebuff.cxx:48
const ScTokenArray * Find(const ScAddress &rRefPos) const
Definition: namebuff.cxx:70
std::unordered_map< ScAddress, ScTokenArray, ScAddressHashFunctor > TokenArraysType
Definition: namebuff.hxx:62
void Store(const ScAddress &rPos, const ScTokenArray &rArray)
Definition: namebuff.cxx:63
TokenArraysType maTokenArrays
Definition: namebuff.hxx:63
StringHashEntry(const OUString &)
Definition: namebuff.hxx:46
sal_uInt32 nHash
Definition: namebuff.hxx:38
static sal_uInt32 MakeHashCode(const OUString &)
Definition: namebuff.cxx:31
OUString aString
Definition: namebuff.hxx:37
bool operator==(const StringHashEntry &) const
Definition: namebuff.hxx:52
Access to global data from other classes.
Definition: xiroot.hxx:129
void * p
sal_Int64 n
ExtName(sal_uInt16 n)
Definition: namebuff.hxx:166
sal_uInt32 nStorageId
Definition: namebuff.hxx:163
sal_uInt16 nFlags
Definition: namebuff.hxx:164
bool IsOLE() const
Definition: namebuff.cxx:146
sal_uInt16 nTabNum
Definition: namebuff.hxx:130
Cont(OUString aFilePathAndName, OUString aTabName, const bool bSameWB)
Definition: namebuff.hxx:134
ScComplexRefData aScComplexRefDataRel
Definition: namebuff.hxx:79
StringHashEntry aStrHashEntry
Definition: namebuff.hxx:78
Entry(const OUString &rName, const ScComplexRefData &rCRD)
Definition: namebuff.hxx:83
Complex reference (a range) into the sheet.
Definition: refdata.hxx:123
ScSingleRefData Ref2
Definition: refdata.hxx:125
ScSingleRefData Ref1
Definition: refdata.hxx:124
Single reference (one address) into the sheet.
Definition: refdata.hxx:30
void InitAddress(const ScAddress &rAdr)
InitAddress: InitFlags and set address.
Definition: refdata.cxx:27
void SetFlag3D(bool bVal)
Definition: refdata.hxx:89