xref: /aoo4110/main/sc/source/filter/inc/namebuff.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_NAMEBUFF_HXX
25 #define SC_NAMEBUFF_HXX
26 
27 #include <tools/debug.hxx>
28 #include <tools/string.hxx>
29 #include "compiler.hxx"
30 #include "root.hxx"
31 #include "xiroot.hxx"
32 
33 #include "rangenam.hxx"
34 #include <hash_map>
35 #include <list>
36 
37 class ScDocument;
38 class ScTokenArray;
39 class NameBuffer;
40 
41 
42 
43 
44 class StringHashEntry
45 {
46 private:
47 	friend class NameBuffer;
48 	String			aString;
49 	sal_uInt32			nHash;
50 
51 	static sal_uInt32	MakeHashCode( const String& );
52 public:
53 	inline			StringHashEntry( const String& );
54 	inline			StringHashEntry( void );
55 	inline void		operator =(	const sal_Char* );
56 	inline void		operator =(	const String& );
57 	inline void		operator =( const StringHashEntry& );
58 	inline sal_Bool		operator ==( const StringHashEntry& ) const;
59 };
60 
61 
StringHashEntry(void)62 inline StringHashEntry::StringHashEntry( void )
63 {
64 }
65 
66 
StringHashEntry(const String & r)67 inline StringHashEntry::StringHashEntry( const String& r ) : aString( r )
68 {
69 	nHash = MakeHashCode( r );
70 }
71 
72 
operator =(const sal_Char * p)73 inline void StringHashEntry::operator =( const sal_Char* p )
74 {
75 	aString.AssignAscii( p );
76 	nHash = MakeHashCode( aString );
77 }
78 
79 
operator =(const String & r)80 inline void StringHashEntry::operator =( const String& r )
81 {
82 	aString = r;
83 	nHash = MakeHashCode( r );
84 }
85 
86 
operator =(const StringHashEntry & r)87 inline void StringHashEntry::operator =( const StringHashEntry& r )
88 {
89 	nHash = r.nHash;
90 	aString = r.aString;
91 }
92 
93 
operator ==(const StringHashEntry & r) const94 inline sal_Bool StringHashEntry::operator ==( const StringHashEntry& r ) const
95 {
96 	return ( nHash == r.nHash && aString ==  r.aString );
97 }
98 
99 
100 
101 class NameBuffer : private List, public ExcRoot
102 {
103 private:
104 	sal_uInt16					nBase;		// Index-Basis
105 public:
106 //    inline                  NameBuffer( void );   //#94039# prevent empty rootdata
107 	inline					NameBuffer( RootData* );
108 	inline					NameBuffer( RootData*, sal_uInt16 nNewBase );
109 
110 	virtual					~NameBuffer();
111 	inline const String*	Get( sal_uInt16 nIndex );
112 	inline sal_uInt16			GetLastIndex( void );
113 	inline void				SetBase( sal_uInt16 nNewBase = 0 );
114 	void					operator <<( const String& rNewString );
115 };
116 
117 //#94039# prevent empty rootdata
118 //inline NameBuffer::NameBuffer( void )
119 //{
120 //    nBase = 0;
121 //}
122 
123 
NameBuffer(RootData * p)124 inline NameBuffer::NameBuffer( RootData* p ) : ExcRoot( p )
125 {
126 	nBase = 0;
127 }
128 
129 
NameBuffer(RootData * p,sal_uInt16 nNewBase)130 inline NameBuffer::NameBuffer( RootData* p, sal_uInt16 nNewBase ) : ExcRoot( p )
131 {
132 	nBase = nNewBase;
133 }
134 
135 
Get(sal_uInt16 n)136 inline const String* NameBuffer::Get( sal_uInt16 n )
137 {
138 	if( n < nBase )
139 		return NULL;
140 	else
141 	{
142 		StringHashEntry* pObj = ( StringHashEntry* ) List::GetObject( n );
143 
144 		if( pObj )
145 			return &pObj->aString;
146 		else
147 			return NULL;
148 	}
149 }
150 
151 
GetLastIndex(void)152 inline sal_uInt16 NameBuffer::GetLastIndex( void )
153 {
154 	DBG_ASSERT( Count() + nBase <= 0xFFFF, "*NameBuffer::GetLastIndex(): Ich hab' die Nase voll!" );
155 
156 	return ( sal_uInt16 ) ( Count() + nBase );
157 }
158 
159 
SetBase(sal_uInt16 nNewBase)160 inline void NameBuffer::SetBase( sal_uInt16 nNewBase )
161 {
162 	nBase = nNewBase;
163 }
164 
165 
166 
167 
168 class ShrfmlaBuffer : public ExcRoot
169 {
170 	struct ScAddressHashFunc : public std::unary_function< const ScAddress &, size_t >
171 	{
172 		size_t operator() (const ScAddress &addr) const;
173 	};
174     typedef std::hash_map <ScAddress, sal_uInt16, ScAddressHashFunc> ShrfmlaHash;
175 	typedef	std::list <ScRange>									 ShrfmlaList;
176 
177 	ShrfmlaHash	 index_hash;
178 	ShrfmlaList	 index_list;
179     size_t                  mnCurrIdx;
180 
181 public:
182 							ShrfmlaBuffer( RootData* pRD );
183 	virtual					~ShrfmlaBuffer();
184     void                    Clear();
185 	void					Store( const ScRange& rRange, const ScTokenArray& );
186     sal_uInt16                  Find (const ScAddress & rAddress ) const;
187 
188 	static String			CreateName( const ScRange& );
189 	};
190 
191 
192 
193 
194 class RangeNameBufferWK3 : private List
195 {
196 private:
197 	struct ENTRY
198 		{
199 		StringHashEntry		aStrHashEntry;
200 		ScComplexRefData		aScComplexRefDataRel;
201 		String				aScAbsName;
202 		sal_uInt16				nAbsInd;		// == 0 -> noch keine Abs-Name!
203 		sal_uInt16				nRelInd;
204 		sal_Bool				bSingleRef;
ENTRYRangeNameBufferWK3::ENTRY205 							ENTRY( const String& rName, const String& rScName, const ScComplexRefData& rCRD ) :
206 								aStrHashEntry( rName ),
207 								aScComplexRefDataRel( rCRD ),
208 								aScAbsName( rScName )
209 							{
210 								nAbsInd = 0;
211 								aScAbsName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "_ABS" ) );
212 							}
213 		};
214 
215 	ScTokenArray*			pScTokenArray;
216 	sal_uInt16					nIntCount;
217 public:
218 							RangeNameBufferWK3( void );
219 	virtual					~RangeNameBufferWK3();
220 	void					Add( const String& rName, const ScComplexRefData& rCRD );
221 	inline void				Add( const String& rName, const ScRange& aScRange );
222 	sal_Bool					FindRel( const String& rRef, sal_uInt16& rIndex );
223 	sal_Bool					FindAbs( const String& rRef, sal_uInt16& rIndex );
224 };
225 
226 
Add(const String & rName,const ScRange & aScRange)227 inline void RangeNameBufferWK3::Add( const String& rName, const ScRange& aScRange )
228 {
229 	ScComplexRefData		aCRD;
230 	ScSingleRefData*		pSRD;
231 	const ScAddress*	pScAddr;
232 
233 	pSRD = &aCRD.Ref1;
234 	pScAddr = &aScRange.aStart;
235 	pSRD->SetFlag3D( sal_True );
236 	pSRD->nCol = pScAddr->Col();
237 	pSRD->nRow = pScAddr->Row();
238 	pSRD->nTab = pScAddr->Tab();
239 
240 	// zunaechst ALLE Refs nur absolut
241 	pSRD->SetColRel( sal_False );
242 	pSRD->SetRowRel( sal_False );
243 	pSRD->SetTabRel( sal_False );
244 
245 	pSRD = &aCRD.Ref2;
246 	pScAddr = &aScRange.aEnd;
247 	pSRD->SetFlag3D( sal_True );
248 	pSRD->nCol = pScAddr->Col();
249 	pSRD->nRow = pScAddr->Row();
250 	pSRD->nTab = pScAddr->Tab();
251 
252 	// zunaechst ALLE Refs nur absolut
253 	pSRD->SetColRel( sal_False );
254 	pSRD->SetRowRel( sal_False );
255 	pSRD->SetTabRel( sal_False );
256 
257 	Add( rName, aCRD );
258 }
259 
260 
261 
262 
263 class ExtSheetBuffer : private List, public ExcRoot
264 {
265 private:
266 	struct Cont
267 		{
268 		String		aFile;
269 		String		aTab;
270 		sal_uInt16		nTabNum;	// 0xFFFF -> noch nicht angelegt
271 								// 0xFFFE -> versucht anzulegen, ging aber schief
272 								// 0xFFFD -> soll im selben Workbook sein, findet's aber nicht
273 		sal_Bool		bSWB;
274 		sal_Bool		bLink;
ContExtSheetBuffer::Cont275 					Cont( const String& rFilePathAndName, const String& rTabName ) :
276 						aFile( rFilePathAndName ),
277 						aTab( rTabName )
278 					{
279 						nTabNum = 0xFFFF;	// -> Tabelle noch nicht erzeugt
280 						bSWB = bLink = sal_False;
281 					}
ContExtSheetBuffer::Cont282 					Cont( const String& rFilePathAndName, const String& rTabName,
283 						const sal_Bool bSameWB ) :
284 						aFile( rFilePathAndName ),
285 						aTab( rTabName )
286 					{
287 						nTabNum = 0xFFFF;	// -> Tabelle noch nicht erzeugt
288 						bSWB = bSameWB;
289 						bLink = sal_False;
290 					}
291 		};
292 public:
293 	inline			ExtSheetBuffer( RootData* );
294 	virtual			~ExtSheetBuffer();
295 
296     sal_Int16       Add( const String& rFilePathAndName,
297 						const String& rTabName, const sal_Bool bSameWorkbook = sal_False );
298 
299 	sal_Bool			GetScTabIndex( sal_uInt16 nExcSheetIndex, sal_uInt16& rIn_LastTab_Out_ScIndex );
300 	sal_Bool			IsLink( const sal_uInt16 nExcSheetIndex ) const;
301 	sal_Bool			GetLink( const sal_uInt16 nExcSheetIndex, String &rAppl, String &rDoc ) const;
302 
303 	void			Reset( void );
304 };
305 
306 
ExtSheetBuffer(RootData * p)307 inline ExtSheetBuffer::ExtSheetBuffer( RootData* p ) : ExcRoot( p )
308 {
309 }
310 
311 
312 
313 
314 struct ExtName
315 {
316 	String			aName;
317 	sal_uInt32			nStorageId;
318 	sal_uInt16			nFlags;
319 
ExtNameExtName320     inline          ExtName( const String& r, sal_uInt16 n ) : aName( r ), nStorageId( 0 ), nFlags( n ) {}
321 
322 	sal_Bool			IsDDE( void ) const;
323     sal_Bool            IsOLE( void ) const;
324 };
325 
326 
327 
328 
329 class ExtNameBuff : protected XclImpRoot
330 {
331 public:
332     explicit        ExtNameBuff( const XclImpRoot& rRoot );
333 
334     void            AddDDE( const String& rName, sal_Int16 nRefIdx );
335     void            AddOLE( const String& rName, sal_Int16 nRefIdx, sal_uInt32 nStorageId );
336     void            AddName( const String& rName, sal_Int16 nRefIdx );
337 
338     const ExtName*  GetNameByIndex( sal_Int16 nRefIdx, sal_uInt16 nNameIdx ) const;
339 
340     void            Reset();
341 
342 private:
343     typedef ::std::vector< ExtName >            ExtNameVec;
344     typedef ::std::map< sal_Int16, ExtNameVec > ExtNameMap;
345 
346     ExtNameMap      maExtNames;
347 };
348 
349 
350 #endif
351 
352 
353