Update ooo320-m1
[ooovba.git] / sc / source / filter / inc / namebuff.hxx
blob40cef3d5bb135db191dc6300924e593a8b20a784
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: namebuff.hxx,v $
10 * $Revision: 1.15.32.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_NAMEBUFF_HXX
32 #define SC_NAMEBUFF_HXX
34 #include <tools/debug.hxx>
35 #include <tools/string.hxx>
36 #include "compiler.hxx"
37 #include "root.hxx"
38 #include "xiroot.hxx"
40 #include "rangenam.hxx"
41 #include <hash_map>
42 #include <list>
44 class ScDocument;
45 class ScTokenArray;
46 class NameBuffer;
51 class StringHashEntry
53 private:
54 friend class NameBuffer;
55 String aString;
56 UINT32 nHash;
58 static UINT32 MakeHashCode( const String& );
59 public:
60 inline StringHashEntry( const String& );
61 inline StringHashEntry( void );
62 inline void operator =( const sal_Char* );
63 inline void operator =( const String& );
64 inline void operator =( const StringHashEntry& );
65 inline BOOL operator ==( const StringHashEntry& ) const;
69 inline StringHashEntry::StringHashEntry( void )
74 inline StringHashEntry::StringHashEntry( const String& r ) : aString( r )
76 nHash = MakeHashCode( r );
80 inline void StringHashEntry::operator =( const sal_Char* p )
82 aString.AssignAscii( p );
83 nHash = MakeHashCode( aString );
87 inline void StringHashEntry::operator =( const String& r )
89 aString = r;
90 nHash = MakeHashCode( r );
94 inline void StringHashEntry::operator =( const StringHashEntry& r )
96 nHash = r.nHash;
97 aString = r.aString;
101 inline BOOL StringHashEntry::operator ==( const StringHashEntry& r ) const
103 return ( nHash == r.nHash && aString == r.aString );
108 class NameBuffer : private List, public ExcRoot
110 private:
111 UINT16 nBase; // Index-Basis
112 public:
113 // inline NameBuffer( void ); //#94039# prevent empty rootdata
114 inline NameBuffer( RootData* );
115 inline NameBuffer( RootData*, UINT16 nNewBase );
117 virtual ~NameBuffer();
118 inline const String* Get( UINT16 nIndex );
119 inline UINT16 GetLastIndex( void );
120 inline void SetBase( UINT16 nNewBase = 0 );
121 void operator <<( const String& rNewString );
124 //#94039# prevent empty rootdata
125 //inline NameBuffer::NameBuffer( void )
127 // nBase = 0;
131 inline NameBuffer::NameBuffer( RootData* p ) : ExcRoot( p )
133 nBase = 0;
137 inline NameBuffer::NameBuffer( RootData* p, UINT16 nNewBase ) : ExcRoot( p )
139 nBase = nNewBase;
143 inline const String* NameBuffer::Get( UINT16 n )
145 if( n < nBase )
146 return NULL;
147 else
149 StringHashEntry* pObj = ( StringHashEntry* ) List::GetObject( n );
151 if( pObj )
152 return &pObj->aString;
153 else
154 return NULL;
159 inline UINT16 NameBuffer::GetLastIndex( void )
161 DBG_ASSERT( Count() + nBase <= 0xFFFF, "*NameBuffer::GetLastIndex(): Ich hab' die Nase voll!" );
163 return ( UINT16 ) ( Count() + nBase );
167 inline void NameBuffer::SetBase( UINT16 nNewBase )
169 nBase = nNewBase;
175 class ShrfmlaBuffer : public ExcRoot
177 struct ScAddressHashFunc : public std::unary_function< const ScAddress &, size_t >
179 size_t operator() (const ScAddress &addr) const;
181 typedef std::hash_map <ScAddress, USHORT, ScAddressHashFunc> ShrfmlaHash;
182 typedef std::list <ScRange> ShrfmlaList;
184 ShrfmlaHash index_hash;
185 ShrfmlaList index_list;
186 size_t mnCurrIdx;
188 public:
189 ShrfmlaBuffer( RootData* pRD );
190 virtual ~ShrfmlaBuffer();
191 void Clear();
192 void Store( const ScRange& rRange, const ScTokenArray& );
193 USHORT Find (const ScAddress & rAddress ) const;
195 static String CreateName( const ScRange& );
201 class RangeNameBufferWK3 : private List
203 private:
204 struct ENTRY
206 StringHashEntry aStrHashEntry;
207 ScComplexRefData aScComplexRefDataRel;
208 String aScAbsName;
209 UINT16 nAbsInd; // == 0 -> noch keine Abs-Name!
210 UINT16 nRelInd;
211 BOOL bSingleRef;
212 ENTRY( const String& rName, const String& rScName, const ScComplexRefData& rCRD ) :
213 aStrHashEntry( rName ),
214 aScComplexRefDataRel( rCRD ),
215 aScAbsName( rScName )
217 nAbsInd = 0;
218 aScAbsName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "_ABS" ) );
222 ScTokenArray* pScTokenArray;
223 UINT16 nIntCount;
224 public:
225 RangeNameBufferWK3( void );
226 virtual ~RangeNameBufferWK3();
227 void Add( const String& rName, const ScComplexRefData& rCRD );
228 inline void Add( const String& rName, const ScRange& aScRange );
229 BOOL FindRel( const String& rRef, UINT16& rIndex );
230 BOOL FindAbs( const String& rRef, UINT16& rIndex );
234 inline void RangeNameBufferWK3::Add( const String& rName, const ScRange& aScRange )
236 ScComplexRefData aCRD;
237 ScSingleRefData* pSRD;
238 const ScAddress* pScAddr;
240 pSRD = &aCRD.Ref1;
241 pScAddr = &aScRange.aStart;
242 pSRD->SetFlag3D( TRUE );
243 pSRD->nCol = pScAddr->Col();
244 pSRD->nRow = pScAddr->Row();
245 pSRD->nTab = pScAddr->Tab();
247 // zunaechst ALLE Refs nur absolut
248 pSRD->SetColRel( FALSE );
249 pSRD->SetRowRel( FALSE );
250 pSRD->SetTabRel( FALSE );
252 pSRD = &aCRD.Ref2;
253 pScAddr = &aScRange.aEnd;
254 pSRD->SetFlag3D( TRUE );
255 pSRD->nCol = pScAddr->Col();
256 pSRD->nRow = pScAddr->Row();
257 pSRD->nTab = pScAddr->Tab();
259 // zunaechst ALLE Refs nur absolut
260 pSRD->SetColRel( FALSE );
261 pSRD->SetRowRel( FALSE );
262 pSRD->SetTabRel( FALSE );
264 Add( rName, aCRD );
270 class ExtSheetBuffer : private List, public ExcRoot
272 private:
273 struct Cont
275 String aFile;
276 String aTab;
277 UINT16 nTabNum; // 0xFFFF -> noch nicht angelegt
278 // 0xFFFE -> versucht anzulegen, ging aber schief
279 // 0xFFFD -> soll im selben Workbook sein, findet's aber nicht
280 BOOL bSWB;
281 BOOL bLink;
282 Cont( const String& rFilePathAndName, const String& rTabName ) :
283 aFile( rFilePathAndName ),
284 aTab( rTabName )
286 nTabNum = 0xFFFF; // -> Tabelle noch nicht erzeugt
287 bSWB = bLink = FALSE;
289 Cont( const String& rFilePathAndName, const String& rTabName,
290 const BOOL bSameWB ) :
291 aFile( rFilePathAndName ),
292 aTab( rTabName )
294 nTabNum = 0xFFFF; // -> Tabelle noch nicht erzeugt
295 bSWB = bSameWB;
296 bLink = FALSE;
299 public:
300 inline ExtSheetBuffer( RootData* );
301 virtual ~ExtSheetBuffer();
303 sal_Int16 Add( const String& rFilePathAndName,
304 const String& rTabName, const BOOL bSameWorkbook = FALSE );
306 BOOL GetScTabIndex( UINT16 nExcSheetIndex, UINT16& rIn_LastTab_Out_ScIndex );
307 BOOL IsLink( const UINT16 nExcSheetIndex ) const;
308 BOOL GetLink( const UINT16 nExcSheetIndex, String &rAppl, String &rDoc ) const;
310 void Reset( void );
314 inline ExtSheetBuffer::ExtSheetBuffer( RootData* p ) : ExcRoot( p )
321 struct ExtName
323 String aName;
324 UINT32 nStorageId;
325 UINT16 nFlags;
327 inline ExtName( const String& r, sal_uInt16 n ) : aName( r ), nStorageId( 0 ), nFlags( n ) {}
329 BOOL IsDDE( void ) const;
330 BOOL IsOLE( void ) const;
336 class ExtNameBuff : protected XclImpRoot
338 public:
339 explicit ExtNameBuff( const XclImpRoot& rRoot );
341 void AddDDE( const String& rName, sal_Int16 nRefIdx );
342 void AddOLE( const String& rName, sal_Int16 nRefIdx, UINT32 nStorageId );
343 void AddName( const String& rName, sal_Int16 nRefIdx );
345 const ExtName* GetNameByIndex( sal_Int16 nRefIdx, sal_uInt16 nNameIdx ) const;
347 void Reset();
349 private:
350 typedef ::std::vector< ExtName > ExtNameVec;
351 typedef ::std::map< sal_Int16, ExtNameVec > ExtNameMap;
353 ExtNameMap maExtNames;
357 #endif