Line data Source code
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 SC_NAMEBUFF_HXX
21 : #define SC_NAMEBUFF_HXX
22 :
23 : #include <rtl/ustring.hxx>
24 : #include "compiler.hxx"
25 : #include "root.hxx"
26 : #include "xiroot.hxx"
27 :
28 : #include "rangenam.hxx"
29 : #include "formulacell.hxx"
30 :
31 : #include <boost/unordered_map.hpp>
32 : #include <list>
33 :
34 : class ScTokenArray;
35 : class NameBuffer;
36 :
37 :
38 0 : class StringHashEntry
39 : {
40 : private:
41 : friend class NameBuffer;
42 : OUString aString;
43 : sal_uInt32 nHash;
44 :
45 : static sal_uInt32 MakeHashCode( const OUString& );
46 : public:
47 : inline StringHashEntry( const OUString& );
48 : inline StringHashEntry( void );
49 : inline void operator =( const sal_Char* );
50 : inline void operator =( const OUString& );
51 : inline void operator =( const StringHashEntry& );
52 : inline bool operator ==( const StringHashEntry& ) const;
53 : };
54 :
55 :
56 : inline StringHashEntry::StringHashEntry( void )
57 : {
58 : }
59 :
60 :
61 0 : inline StringHashEntry::StringHashEntry( const OUString& r ) : aString( r )
62 : {
63 0 : nHash = MakeHashCode( r );
64 0 : }
65 :
66 :
67 : inline void StringHashEntry::operator =( const sal_Char* p )
68 : {
69 : aString = OUString(p, strlen(p), RTL_TEXTENCODING_ASCII_US);
70 : nHash = MakeHashCode( aString );
71 : }
72 :
73 :
74 : inline void StringHashEntry::operator =( const OUString& r )
75 : {
76 : aString = r;
77 : nHash = MakeHashCode( r );
78 : }
79 :
80 :
81 : inline void StringHashEntry::operator =( const StringHashEntry& r )
82 : {
83 : nHash = r.nHash;
84 : aString = r.aString;
85 : }
86 :
87 :
88 0 : inline bool StringHashEntry::operator ==( const StringHashEntry& r ) const
89 : {
90 0 : return ( nHash == r.nHash && aString == r.aString );
91 : }
92 :
93 : class NameBuffer : public ExcRoot
94 : {
95 : private:
96 : sal_uInt16 nBase; // Index-Basis
97 : std::vector<StringHashEntry*> maHashes;
98 :
99 : public:
100 :
101 : inline NameBuffer( RootData* );
102 : inline NameBuffer( RootData*, sal_uInt16 nNewBase );
103 :
104 : virtual ~NameBuffer();
105 : inline const OUString* Get( sal_uInt16 nIndex ) const;
106 : inline sal_uInt16 GetLastIndex() const;
107 : inline void SetBase( sal_uInt16 nNewBase = 0 );
108 : void operator <<( const OUString& rNewString );
109 : };
110 :
111 0 : inline NameBuffer::NameBuffer( RootData* p ) : ExcRoot( p )
112 : {
113 0 : nBase = 0;
114 0 : }
115 :
116 :
117 0 : inline NameBuffer::NameBuffer( RootData* p, sal_uInt16 nNewBase ) : ExcRoot( p )
118 : {
119 0 : nBase = nNewBase;
120 0 : }
121 :
122 :
123 : inline const OUString* NameBuffer::Get ( sal_uInt16 n ) const
124 : {
125 : if( n < nBase || n >= maHashes.size() )
126 : return NULL;
127 :
128 : return &(maHashes[n]->aString);
129 : }
130 :
131 :
132 : inline sal_uInt16 NameBuffer::GetLastIndex () const
133 : {
134 : int size = maHashes.size() + nBase;
135 :
136 : OSL_ENSURE( size <= 0xFFFF, "*NameBuffer::GetLastIndex(): I'm sick and tired!" );
137 :
138 : return static_cast<sal_uInt16>( size );
139 : }
140 :
141 :
142 0 : inline void NameBuffer::SetBase( sal_uInt16 nNewBase )
143 : {
144 0 : nBase = nNewBase;
145 0 : }
146 :
147 : /**
148 : * Store and manage shared formula tokens.
149 : */
150 : class SharedFormulaBuffer : public ExcRoot
151 : {
152 : typedef boost::unordered_map<ScAddress, ScTokenArray*, ScAddressHashFunctor> TokenArraysType;
153 : TokenArraysType maTokenArrays;
154 :
155 : public:
156 : SharedFormulaBuffer( RootData* pRD );
157 : virtual ~SharedFormulaBuffer();
158 : void Clear();
159 : void Store( const ScAddress& rPos, const ScTokenArray& rArray );
160 : const ScTokenArray* Find( const ScAddress& rRefPos ) const;
161 : };
162 :
163 : class RangeNameBufferWK3
164 : {
165 : private:
166 0 : struct Entry
167 : {
168 : StringHashEntry aStrHashEntry;
169 : ScComplexRefData aScComplexRefDataRel;
170 : OUString aScAbsName;
171 : sal_uInt16 nAbsInd; // == 0 -> noch keine Abs-Name!
172 : sal_uInt16 nRelInd;
173 : bool bSingleRef;
174 0 : Entry( const OUString& rName, const OUString& rScName, const ScComplexRefData& rCRD )
175 : : aStrHashEntry( rName )
176 : , aScComplexRefDataRel( rCRD )
177 : , aScAbsName( rScName )
178 : , nAbsInd(0)
179 : , nRelInd(0)
180 0 : , bSingleRef(false)
181 : {
182 0 : aScAbsName = "_ABS";
183 0 : }
184 : };
185 :
186 : ScTokenArray* pScTokenArray;
187 : sal_uInt16 nIntCount;
188 : std::vector<Entry> maEntries;
189 :
190 : public:
191 : RangeNameBufferWK3( void );
192 : virtual ~RangeNameBufferWK3();
193 : void Add( const OUString& rName, const ScComplexRefData& rCRD );
194 : inline void Add( const OUString& rName, const ScRange& aScRange );
195 : bool FindRel( const OUString& rRef, sal_uInt16& rIndex );
196 : bool FindAbs( const OUString& rRef, sal_uInt16& rIndex );
197 : };
198 :
199 :
200 0 : inline void RangeNameBufferWK3::Add( const OUString& rName, const ScRange& aScRange )
201 : {
202 : ScComplexRefData aCRD;
203 : ScSingleRefData* pSRD;
204 :
205 0 : pSRD = &aCRD.Ref1;
206 0 : pSRD->InitAddress(aScRange.aStart);
207 0 : pSRD->SetFlag3D(true);
208 :
209 0 : pSRD = &aCRD.Ref2;
210 0 : pSRD->InitAddress(aScRange.aEnd);
211 0 : pSRD->SetFlag3D(true);
212 :
213 0 : Add( rName, aCRD );
214 0 : }
215 :
216 :
217 0 : class ExtSheetBuffer : public ExcRoot
218 : {
219 : private:
220 0 : struct Cont
221 : {
222 : OUString aFile;
223 : OUString aTab;
224 : sal_uInt16 nTabNum; // 0xFFFF -> noch nicht angelegt
225 : // 0xFFFE -> versucht anzulegen, ging aber schief
226 : // 0xFFFD -> soll im selben Workbook sein, findet's aber nicht
227 : bool bSWB;
228 : bool bLink;
229 : Cont( const OUString& rFilePathAndName, const OUString& rTabName ) :
230 : aFile( rFilePathAndName ),
231 : aTab( rTabName )
232 : {
233 : nTabNum = 0xFFFF; // -> Tabelle noch nicht erzeugt
234 : bSWB = bLink = false;
235 : }
236 0 : Cont( const OUString& rFilePathAndName, const OUString& rTabName,
237 : const bool bSameWB ) :
238 : aFile( rFilePathAndName ),
239 0 : aTab( rTabName )
240 : {
241 0 : nTabNum = 0xFFFF; // -> Tabelle noch nicht erzeugt
242 0 : bSWB = bSameWB;
243 0 : bLink = false;
244 0 : }
245 : };
246 :
247 : std::vector<Cont> maEntries;
248 :
249 : public:
250 : inline ExtSheetBuffer( RootData* );
251 :
252 : sal_Int16 Add( const OUString& rFilePathAndName,
253 : const OUString& rTabName, const bool bSameWorkbook = false );
254 :
255 : bool GetScTabIndex( sal_uInt16 nExcSheetIndex, sal_uInt16& rIn_LastTab_Out_ScIndex );
256 : bool IsLink( const sal_uInt16 nExcSheetIndex ) const;
257 : bool GetLink( const sal_uInt16 nExcSheetIndex, OUString &rAppl, OUString &rDoc ) const;
258 :
259 : void Reset( void );
260 : };
261 :
262 :
263 0 : inline ExtSheetBuffer::ExtSheetBuffer( RootData* p ) : ExcRoot( p )
264 : {
265 0 : }
266 :
267 :
268 0 : struct ExtName
269 : {
270 : OUString aName;
271 : sal_uInt32 nStorageId;
272 : sal_uInt16 nFlags;
273 :
274 0 : inline ExtName( const OUString& r, sal_uInt16 n ) : aName( r ), nStorageId( 0 ), nFlags( n ) {}
275 :
276 : bool IsDDE( void ) const;
277 : bool IsOLE( void ) const;
278 : };
279 :
280 :
281 0 : class ExtNameBuff : protected XclImpRoot
282 : {
283 : public:
284 : explicit ExtNameBuff( const XclImpRoot& rRoot );
285 :
286 : void AddDDE( const OUString& rName, sal_Int16 nRefIdx );
287 : void AddOLE( const OUString& rName, sal_Int16 nRefIdx, sal_uInt32 nStorageId );
288 : void AddName( const OUString& rName, sal_Int16 nRefIdx );
289 :
290 : const ExtName* GetNameByIndex( sal_Int16 nRefIdx, sal_uInt16 nNameIdx ) const;
291 :
292 : void Reset();
293 :
294 : private:
295 : typedef ::std::vector< ExtName > ExtNameVec;
296 : typedef ::std::map< sal_Int16, ExtNameVec > ExtNameMap;
297 :
298 : ExtNameMap maExtNames;
299 : };
300 :
301 :
302 : #endif
303 :
304 :
305 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|