Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / sc / source / filter / inc / namebuff.hxx
blobbd98a8ab144d92b7b8f5628a71710269ee38811d
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
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>
32 #include <unordered_map>
34 class StringHashEntry
36 private:
37 OUString aString;
38 sal_uInt32 nHash;
40 static sal_uInt32 MakeHashCode( const OUString& );
41 public:
42 inline StringHashEntry( const OUString& );
43 inline bool operator ==( const StringHashEntry& ) const;
46 inline StringHashEntry::StringHashEntry( const OUString& r )
47 : aString( r )
48 , nHash( MakeHashCode(r) )
52 inline bool StringHashEntry::operator ==( const StringHashEntry& r ) const
54 return ( nHash == r.nHash && aString == r.aString );
57 /**
58 * Store and manage shared formula tokens.
60 class SharedFormulaBuffer : public ExcRoot
62 typedef std::unordered_map<ScAddress, ScTokenArray, ScAddressHashFunctor> TokenArraysType;
63 TokenArraysType maTokenArrays;
65 public:
66 SharedFormulaBuffer( RootData* pRD );
67 virtual ~SharedFormulaBuffer();
68 void Clear();
69 void Store( const ScAddress& rPos, const ScTokenArray& rArray );
70 const ScTokenArray* Find( const ScAddress& rRefPos ) const;
73 class RangeNameBufferWK3 final
75 private:
76 struct Entry
78 StringHashEntry aStrHashEntry;
79 ScComplexRefData aScComplexRefDataRel;
80 sal_uInt16 nAbsInd; // == 0 -> no Abs-Name yet!
81 sal_uInt16 nRelInd;
82 bool bSingleRef;
83 Entry( const OUString& rName, const ScComplexRefData& rCRD )
84 : aStrHashEntry( rName )
85 , aScComplexRefDataRel( rCRD )
86 , nAbsInd(0)
87 , nRelInd(0)
88 , bSingleRef(false)
93 std::unique_ptr<ScTokenArray>
94 pScTokenArray;
95 sal_uInt16 nIntCount;
96 std::vector<Entry> maEntries;
98 public:
99 RangeNameBufferWK3(const ScDocument& rDoc);
100 ~RangeNameBufferWK3();
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 );
107 inline void RangeNameBufferWK3::Add( const ScDocument& rDoc, const OUString& rName, const ScRange& aScRange )
109 ScComplexRefData aCRD;
110 ScSingleRefData* pSRD;
112 pSRD = &aCRD.Ref1;
113 pSRD->InitAddress(aScRange.aStart);
114 pSRD->SetFlag3D(true);
116 pSRD = &aCRD.Ref2;
117 pSRD->InitAddress(aScRange.aEnd);
118 pSRD->SetFlag3D(true);
120 Add( rDoc, rName, aCRD );
123 class ExtSheetBuffer : public ExcRoot
125 private:
126 struct Cont
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 ))
139 nTabNum = 0xFFFF; // -> table not created yet
140 bSWB = bSameWB;
144 std::vector<Cont> maEntries;
146 public:
147 inline ExtSheetBuffer( RootData* );
149 sal_Int16 Add( const OUString& rFilePathAndName,
150 const OUString& rTabName, const bool bSameWorkbook );
152 bool GetScTabIndex( sal_uInt16 nExcSheetIndex, sal_uInt16& rIn_LastTab_Out_ScIndex );
154 void Reset();
157 inline ExtSheetBuffer::ExtSheetBuffer( RootData* p ) : ExcRoot( p )
161 struct ExtName
163 sal_uInt32 nStorageId;
164 sal_uInt16 nFlags;
166 ExtName( sal_uInt16 n ) : nStorageId( 0 ), nFlags( n ) {}
168 bool IsOLE() const;
171 class ExtNameBuff : protected XclImpRoot
173 public:
174 explicit ExtNameBuff( const XclImpRoot& rRoot );
176 void AddDDE( sal_Int16 nRefIdx );
177 void AddOLE( sal_Int16 nRefIdx, sal_uInt32 nStorageId );
178 void AddName( sal_Int16 nRefIdx );
180 const ExtName* GetNameByIndex( sal_Int16 nRefIdx, sal_uInt16 nNameIdx ) const;
182 void Reset();
184 private:
185 typedef ::std::vector< ExtName > ExtNameVec;
186 typedef ::std::map< sal_Int16, ExtNameVec > ExtNameMap;
188 ExtNameMap maExtNames;
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */