Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / inc / namebuff.hxx
blob1f174b46e65cd31ae90a73b7204c71c5e7163106
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 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_NAMEBUFF_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_NAMEBUFF_HXX
23 #include <memory>
24 #include <map>
25 #include <rtl/ustring.hxx>
26 #include "root.hxx"
27 #include "xiroot.hxx"
29 #include <unordered_map>
31 class ScTokenArray;
33 class StringHashEntry
35 private:
36 OUString const aString;
37 sal_uInt32 const nHash;
39 static sal_uInt32 MakeHashCode( const OUString& );
40 public:
41 inline StringHashEntry( const OUString& );
42 inline bool operator ==( const StringHashEntry& ) const;
45 inline StringHashEntry::StringHashEntry( const OUString& r )
46 : aString( r )
47 , nHash( MakeHashCode(r) )
51 inline bool StringHashEntry::operator ==( const StringHashEntry& r ) const
53 return ( nHash == r.nHash && aString == r.aString );
56 /**
57 * Store and manage shared formula tokens.
59 class SharedFormulaBuffer : public ExcRoot
61 typedef std::unordered_map<ScAddress, std::unique_ptr<ScTokenArray>, ScAddressHashFunctor> TokenArraysType;
62 TokenArraysType maTokenArrays;
64 public:
65 SharedFormulaBuffer( RootData* pRD );
66 virtual ~SharedFormulaBuffer();
67 void Clear();
68 void Store( const ScAddress& rPos, const ScTokenArray& rArray );
69 const ScTokenArray* Find( const ScAddress& rRefPos ) const;
72 class RangeNameBufferWK3 final
74 private:
75 struct Entry
77 StringHashEntry const aStrHashEntry;
78 ScComplexRefData aScComplexRefDataRel;
79 sal_uInt16 nAbsInd; // == 0 -> no Abs-Name yet!
80 sal_uInt16 nRelInd;
81 bool bSingleRef;
82 Entry( const OUString& rName, const ScComplexRefData& rCRD )
83 : aStrHashEntry( rName )
84 , aScComplexRefDataRel( rCRD )
85 , nAbsInd(0)
86 , nRelInd(0)
87 , bSingleRef(false)
92 std::unique_ptr<ScTokenArray>
93 pScTokenArray;
94 sal_uInt16 nIntCount;
95 std::vector<Entry> maEntries;
97 public:
98 RangeNameBufferWK3();
99 ~RangeNameBufferWK3();
100 void Add( const OUString& rName, const ScComplexRefData& rCRD );
101 inline void Add( const OUString& rName, const ScRange& aScRange );
102 bool FindRel( const OUString& rRef, sal_uInt16& rIndex );
103 bool FindAbs( const OUString& rRef, sal_uInt16& rIndex );
106 inline void RangeNameBufferWK3::Add( const OUString& rName, const ScRange& aScRange )
108 ScComplexRefData aCRD;
109 ScSingleRefData* pSRD;
111 pSRD = &aCRD.Ref1;
112 pSRD->InitAddress(aScRange.aStart);
113 pSRD->SetFlag3D(true);
115 pSRD = &aCRD.Ref2;
116 pSRD->InitAddress(aScRange.aEnd);
117 pSRD->SetFlag3D(true);
119 Add( rName, aCRD );
122 class ExtSheetBuffer : public ExcRoot
124 private:
125 struct Cont
127 OUString const aFile;
128 OUString const aTab;
129 sal_uInt16 nTabNum; // 0xFFFF -> not set yet
130 // 0xFFFE -> tried to set, but failed
131 // 0xFFFD -> should be in the same workbook, but not found
132 bool bSWB;
133 Cont( const OUString& rFilePathAndName, const OUString& rTabName,
134 const bool bSameWB ) :
135 aFile( rFilePathAndName ),
136 aTab( rTabName )
138 nTabNum = 0xFFFF; // -> table not created yet
139 bSWB = bSameWB;
143 std::vector<Cont> maEntries;
145 public:
146 inline ExtSheetBuffer( RootData* );
148 sal_Int16 Add( const OUString& rFilePathAndName,
149 const OUString& rTabName, const bool bSameWorkbook );
151 bool GetScTabIndex( sal_uInt16 nExcSheetIndex, sal_uInt16& rIn_LastTab_Out_ScIndex );
153 void Reset();
156 inline ExtSheetBuffer::ExtSheetBuffer( RootData* p ) : ExcRoot( p )
160 struct ExtName
162 sal_uInt32 nStorageId;
163 sal_uInt16 const nFlags;
165 ExtName( sal_uInt16 n ) : nStorageId( 0 ), nFlags( n ) {}
167 bool IsOLE() const;
170 class ExtNameBuff : protected XclImpRoot
172 public:
173 explicit ExtNameBuff( const XclImpRoot& rRoot );
175 void AddDDE( sal_Int16 nRefIdx );
176 void AddOLE( sal_Int16 nRefIdx, sal_uInt32 nStorageId );
177 void AddName( sal_Int16 nRefIdx );
179 const ExtName* GetNameByIndex( sal_Int16 nRefIdx, sal_uInt16 nNameIdx ) const;
181 void Reset();
183 private:
184 typedef ::std::vector< ExtName > ExtNameVec;
185 typedef ::std::map< sal_Int16, ExtNameVec > ExtNameMap;
187 ExtNameMap maExtNames;
190 #endif
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */