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 <vector>
25 #include <rtl/ustring.hxx>
26 #include "root.hxx"
27 #include "xiroot.hxx"
28 #include <refdata.hxx>
29 
30 #include <unordered_map>
31 
32 class ScTokenArray;
33 
35 {
36 private:
37  OUString aString;
38  sal_uInt32 nHash;
39 
40  static sal_uInt32 MakeHashCode( const OUString& );
41 public:
42  inline StringHashEntry( const OUString& );
43  inline bool operator ==( const StringHashEntry& ) const;
44 };
45 
46 inline StringHashEntry::StringHashEntry( const OUString& r )
47  : aString( r )
48  , nHash( MakeHashCode(r) )
49 {
50 }
51 
52 inline 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, std::unique_ptr<ScTokenArray>, ScAddressHashFunctor> TokenArraysType;
63  TokenArraysType maTokenArrays;
64 
65 public:
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 
73 class RangeNameBufferWK3 final
74 {
75 private:
76  struct Entry
77  {
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)
89  {
90  }
91  };
92 
93  std::unique_ptr<ScTokenArray>
95  sal_uInt16 nIntCount;
96  std::vector<Entry> maEntries;
97 
98 public:
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( const OUString& rRef, sal_uInt16& rIndex );
105 };
106 
107 inline 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 
123 class ExtSheetBuffer : public ExcRoot
124 {
125 private:
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( const OUString& rFilePathAndName, const OUString& rTabName,
135  const bool bSameWB ) :
136  aFile( rFilePathAndName ),
137  aTab( rTabName )
138  {
139  nTabNum = 0xFFFF; // -> table not created yet
140  bSWB = bSameWB;
141  }
142  };
143 
144  std::vector<Cont> maEntries;
145 
146 public:
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 
161 struct ExtName
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 
171 class ExtNameBuff : protected XclImpRoot
172 {
173 public:
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 
184 private:
185  typedef ::std::vector< ExtName > ExtNameVec;
186  typedef ::std::map< sal_Int16, ExtNameVec > ExtNameMap;
187 
188  ExtNameMap maExtNames;
189 };
190 
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::vector< ExtName > ExtNameVec
Definition: namebuff.hxx:185
OUString aString
Definition: namebuff.hxx:37
ScAddress aStart
Definition: address.hxx:499
ExtSheetBuffer(RootData *)
Definition: namebuff.hxx:157
const ExtName * GetNameByIndex(sal_Int16 nRefIdx, sal_uInt16 nNameIdx) const
Definition: namebuff.cxx:175
::std::map< sal_Int16, ExtNameVec > ExtNameMap
Definition: namebuff.hxx:186
Single reference (one address) into the sheet.
Definition: refdata.hxx:29
TokenArraysType maTokenArrays
Definition: namebuff.hxx:63
void AddDDE(sal_Int16 nRefIdx)
Definition: namebuff.cxx:156
void Add(const ScDocument &rDoc, const OUString &rName, const ScComplexRefData &rCRD)
Definition: tool.cxx:438
ScAddress aEnd
Definition: address.hxx:500
sal_uInt16 nIntCount
Definition: namebuff.hxx:95
ExtNameBuff(const XclImpRoot &rRoot)
Definition: namebuff.cxx:151
Entry(const OUString &rName, const ScComplexRefData &rCRD)
Definition: namebuff.hxx:83
const ScTokenArray * Find(const ScAddress &rRefPos) const
Definition: namebuff.cxx:70
virtual ~SharedFormulaBuffer()
Definition: namebuff.cxx:53
ExtName(sal_uInt16 n)
Definition: namebuff.hxx:166
void Reset()
Definition: namebuff.cxx:182
sal_uInt16 nTabNum
Definition: namebuff.hxx:130
bool FindAbs(const OUString &rRef, sal_uInt16 &rIndex)
Definition: tool.cxx:480
void Store(const ScAddress &rPos, const ScTokenArray &rArray)
Definition: namebuff.cxx:63
void AddOLE(sal_Int16 nRefIdx, sal_uInt32 nStorageId)
Definition: namebuff.cxx:162
void SetFlag3D(bool bVal)
Definition: refdata.hxx:89
void InitAddress(const ScAddress &rAdr)
InitAddress: InitFlags and set address.
Definition: refdata.cxx:27
Definition: root.hxx:70
ScSingleRefData Ref1
Definition: refdata.hxx:124
sal_Int16 Add(const OUString &rFilePathAndName, const OUString &rTabName, const bool bSameWorkbook)
Definition: namebuff.cxx:79
ScSingleRefData Ref2
Definition: refdata.hxx:125
void AddName(sal_Int16 nRefIdx)
Definition: namebuff.cxx:169
static sal_uInt32 MakeHashCode(const OUString &)
Definition: namebuff.cxx:31
StringHashEntry(const OUString &)
Definition: namebuff.hxx:46
Cont(const OUString &rFilePathAndName, const OUString &rTabName, const bool bSameWB)
Definition: namebuff.hxx:134
sal_uInt32 nStorageId
Definition: namebuff.hxx:163
StringHashEntry aStrHashEntry
Definition: namebuff.hxx:78
bool IsOLE() const
Definition: namebuff.cxx:146
bool GetScTabIndex(sal_uInt16 nExcSheetIndex, sal_uInt16 &rIn_LastTab_Out_ScIndex)
Definition: namebuff.cxx:86
sal_uInt16 nFlags
Definition: namebuff.hxx:164
SharedFormulaBuffer(RootData *pRD)
Definition: namebuff.cxx:48
Store and manage shared formula tokens.
Definition: namebuff.hxx:60
bool FindRel(const OUString &rRef, sal_uInt16 &rIndex)
Definition: tool.cxx:465
RangeNameBufferWK3(const ScDocument &rDoc)
Definition: tool.cxx:428
std::vector< Entry > maEntries
Definition: namebuff.hxx:96
ScComplexRefData aScComplexRefDataRel
Definition: namebuff.hxx:79
Complex reference (a range) into the sheet.
Definition: refdata.hxx:122
std::unordered_map< ScAddress, std::unique_ptr< ScTokenArray >, ScAddressHashFunctor > TokenArraysType
Definition: namebuff.hxx:62
bool operator==(const StringHashEntry &) const
Definition: namebuff.hxx:52
std::vector< Cont > maEntries
Definition: namebuff.hxx:144
ExtNameMap maExtNames
Definition: namebuff.hxx:188
Access to global data from other classes.
Definition: xiroot.hxx:125
sal_uInt32 nHash
Definition: namebuff.hxx:38
std::unique_ptr< ScTokenArray > pScTokenArray
Definition: namebuff.hxx:94