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 #include <tokenarray.hxx>
30 
31 #include <unordered_map>
32 
34 {
35 private:
36  OUString aString;
37  sal_uInt32 nHash;
38 
39  static sal_uInt32 MakeHashCode( const OUString& );
40 public:
41  inline StringHashEntry( const OUString& );
42  inline bool operator ==( const StringHashEntry& ) const;
43 };
44 
45 inline StringHashEntry::StringHashEntry( const OUString& r )
46  : aString( r )
47  , nHash( MakeHashCode(r) )
48 {
49 }
50 
51 inline bool StringHashEntry::operator ==( const StringHashEntry& r ) const
52 {
53  return ( nHash == r.nHash && aString == r.aString );
54 }
55 
60 {
61  typedef std::unordered_map<ScAddress, ScTokenArray, ScAddressHashFunctor> TokenArraysType;
62  TokenArraysType maTokenArrays;
63 
64 public:
66  virtual ~SharedFormulaBuffer();
67  void Clear();
68  void Store( const ScAddress& rPos, const ScTokenArray& rArray );
69  const ScTokenArray* Find( const ScAddress& rRefPos ) const;
70 };
71 
72 class RangeNameBufferWK3 final
73 {
74 private:
75  struct Entry
76  {
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)
88  {
89  }
90  };
91 
92  std::unique_ptr<ScTokenArray>
94  sal_uInt16 nIntCount;
95  std::vector<Entry> maEntries;
96 
97 public:
98  RangeNameBufferWK3(const ScDocument& rDoc);
100  void Add( const ScDocument& rDoc, const OUString& rName, const ScComplexRefData& rCRD );
101  inline void Add( const ScDocument& rDoc, const OUString& rName, const ScRange& aScRange );
102  bool FindRel( const OUString& rRef, sal_uInt16& rIndex );
103  bool FindAbs( const OUString& rRef, sal_uInt16& rIndex );
104 };
105 
106 inline void RangeNameBufferWK3::Add( const ScDocument& rDoc, const OUString& rName, const ScRange& aScRange )
107 {
108  ScComplexRefData aCRD;
109  ScSingleRefData* pSRD;
110 
111  pSRD = &aCRD.Ref1;
112  pSRD->InitAddress(aScRange.aStart);
113  pSRD->SetFlag3D(true);
114 
115  pSRD = &aCRD.Ref2;
116  pSRD->InitAddress(aScRange.aEnd);
117  pSRD->SetFlag3D(true);
118 
119  Add( rDoc, rName, aCRD );
120 }
121 
122 class ExtSheetBuffer : public ExcRoot
123 {
124 private:
125  struct Cont
126  {
127  OUString aFile;
128  OUString 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 )
137  {
138  nTabNum = 0xFFFF; // -> table not created yet
139  bSWB = bSameWB;
140  }
141  };
142 
143  std::vector<Cont> maEntries;
144 
145 public:
146  inline ExtSheetBuffer( RootData* );
147 
148  sal_Int16 Add( const OUString& rFilePathAndName,
149  const OUString& rTabName, const bool bSameWorkbook );
150 
151  bool GetScTabIndex( sal_uInt16 nExcSheetIndex, sal_uInt16& rIn_LastTab_Out_ScIndex );
152 
153  void Reset();
154 };
155 
157 {
158 }
159 
160 struct ExtName
161 {
162  sal_uInt32 nStorageId;
163  sal_uInt16 nFlags;
164 
165  ExtName( sal_uInt16 n ) : nStorageId( 0 ), nFlags( n ) {}
166 
167  bool IsOLE() const;
168 };
169 
170 class ExtNameBuff : protected XclImpRoot
171 {
172 public:
173  explicit ExtNameBuff( const XclImpRoot& rRoot );
174 
175  void AddDDE( sal_Int16 nRefIdx );
176  void AddOLE( sal_Int16 nRefIdx, sal_uInt32 nStorageId );
177  void AddName( sal_Int16 nRefIdx );
178 
179  const ExtName* GetNameByIndex( sal_Int16 nRefIdx, sal_uInt16 nNameIdx ) const;
180 
181  void Reset();
182 
183 private:
184  typedef ::std::vector< ExtName > ExtNameVec;
185  typedef ::std::map< sal_Int16, ExtNameVec > ExtNameMap;
186 
187  ExtNameMap maExtNames;
188 };
189 
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::vector< ExtName > ExtNameVec
Definition: namebuff.hxx:184
OUString aString
Definition: namebuff.hxx:36
ScAddress aStart
Definition: address.hxx:499
ExtSheetBuffer(RootData *)
Definition: namebuff.hxx:156
const ExtName * GetNameByIndex(sal_Int16 nRefIdx, sal_uInt16 nNameIdx) const
Definition: namebuff.cxx:175
std::unordered_map< ScAddress, ScTokenArray, ScAddressHashFunctor > TokenArraysType
Definition: namebuff.hxx:61
::std::map< sal_Int16, ExtNameVec > ExtNameMap
Definition: namebuff.hxx:185
Single reference (one address) into the sheet.
Definition: refdata.hxx:29
TokenArraysType maTokenArrays
Definition: namebuff.hxx:62
void AddDDE(sal_Int16 nRefIdx)
Definition: namebuff.cxx:156
void Add(const ScDocument &rDoc, const OUString &rName, const ScComplexRefData &rCRD)
Definition: tool.cxx:439
ScAddress aEnd
Definition: address.hxx:500
sal_uInt16 nIntCount
Definition: namebuff.hxx:94
ExtNameBuff(const XclImpRoot &rRoot)
Definition: namebuff.cxx:151
Entry(const OUString &rName, const ScComplexRefData &rCRD)
Definition: namebuff.hxx:82
const ScTokenArray * Find(const ScAddress &rRefPos) const
Definition: namebuff.cxx:70
virtual ~SharedFormulaBuffer()
Definition: namebuff.cxx:53
ExtName(sal_uInt16 n)
Definition: namebuff.hxx:165
void Reset()
Definition: namebuff.cxx:182
sal_uInt16 nTabNum
Definition: namebuff.hxx:129
bool FindAbs(const OUString &rRef, sal_uInt16 &rIndex)
Definition: tool.cxx:481
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:45
Cont(const OUString &rFilePathAndName, const OUString &rTabName, const bool bSameWB)
Definition: namebuff.hxx:133
sal_uInt32 nStorageId
Definition: namebuff.hxx:162
StringHashEntry aStrHashEntry
Definition: namebuff.hxx:77
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:163
SharedFormulaBuffer(RootData *pRD)
Definition: namebuff.cxx:48
Store and manage shared formula tokens.
Definition: namebuff.hxx:59
bool FindRel(const OUString &rRef, sal_uInt16 &rIndex)
Definition: tool.cxx:466
RangeNameBufferWK3(const ScDocument &rDoc)
Definition: tool.cxx:429
std::vector< Entry > maEntries
Definition: namebuff.hxx:95
ScComplexRefData aScComplexRefDataRel
Definition: namebuff.hxx:78
Complex reference (a range) into the sheet.
Definition: refdata.hxx:122
bool operator==(const StringHashEntry &) const
Definition: namebuff.hxx:51
std::vector< Cont > maEntries
Definition: namebuff.hxx:143
ExtNameMap maExtNames
Definition: namebuff.hxx:187
Access to global data from other classes.
Definition: xiroot.hxx:125
sal_uInt32 nHash
Definition: namebuff.hxx:37
std::unique_ptr< ScTokenArray > pScTokenArray
Definition: namebuff.hxx:93