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