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