fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / excel / tokstack.cxx
blob7837b6d6046d6d09e5bfeb64b8479cc01b57c3e0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "tokstack.hxx"
21 #include "compiler.hxx"
22 #include "global.hxx"
23 #include "scmatrix.hxx"
25 #include <svl/sharedstringpool.hxx>
27 #include <stdio.h>
28 #include <string.h>
30 const sal_uInt16 TokenPool::nScTokenOff = 8192;
32 TokenStack::TokenStack( sal_uInt16 nNewSize )
34 pStack = new TokenId[ nNewSize ];
36 Reset();
37 nSize = nNewSize;
40 TokenStack::~TokenStack()
42 delete[] pStack;
45 // !ATTENTION!": to the outside the numbering starts with 1!
46 // !ATTENTION!": SC-Token are stored with an offset nScTokenOff
47 // -> to distinguish from other tokens
49 TokenPool::TokenPool( svl::SharedStringPool& rSPool ) :
50 mrStringPool(rSPool)
52 sal_uInt16 nLauf = nScTokenOff;
54 // pool for Id-sequences
55 nP_Id = 256;
56 pP_Id = new sal_uInt16[ nP_Id ];
58 // pool for Ids
59 nElement = 32;
60 pElement = new sal_uInt16[ nElement ];
61 pType = new E_TYPE[ nElement ];
62 pSize = new sal_uInt16[ nElement ];
63 nP_IdLast = 0;
65 // pool for strings
66 nP_Str = 4;
67 ppP_Str = new OUString *[ nP_Str ];
68 for( nLauf = 0 ; nLauf < nP_Str ; nLauf++ )
69 ppP_Str[ nLauf ] = NULL;
71 // pool for double
72 nP_Dbl = 8;
73 pP_Dbl = new double[ nP_Dbl ];
75 // pool for error codes
76 nP_Err = 8;
77 pP_Err = new sal_uInt16[ nP_Err ];
79 // pool for References
80 nP_RefTr = 32;
81 ppP_RefTr = new ScSingleRefData *[ nP_RefTr ];
82 for( nLauf = 0 ; nLauf < nP_RefTr ; nLauf++ )
83 ppP_RefTr[ nLauf ] = NULL;
85 nP_Ext = 32;
86 ppP_Ext = new EXTCONT*[ nP_Ext ];
87 memset( ppP_Ext, 0, sizeof( EXTCONT* ) * nP_Ext );
89 nP_Nlf = 16;
90 ppP_Nlf = new NLFCONT*[ nP_Nlf ];
91 memset( ppP_Nlf, 0, sizeof( NLFCONT* ) * nP_Nlf );
93 nP_Matrix = 16;
94 ppP_Matrix = new ScMatrix*[ nP_Matrix ];
95 memset( ppP_Matrix, 0, sizeof( ScMatrix* ) * nP_Matrix );
97 pScToken = new ScTokenArray;
99 Reset();
102 TokenPool::~TokenPool()
104 sal_uInt16 n;
106 delete[] pP_Id;
107 delete[] pElement;
108 delete[] pType;
109 delete[] pSize;
110 delete[] pP_Dbl;
111 delete[] pP_Err;
113 for( n = 0 ; n < nP_RefTr ; n++ )
114 delete ppP_RefTr[ n ];
115 delete[] ppP_RefTr;
117 for( n = 0 ; n < nP_Str ; n++ )
118 delete ppP_Str[ n ];
119 delete[] ppP_Str;
121 for( n = 0 ; n < nP_Ext ; n++ )
122 delete ppP_Ext[ n ];
123 delete[] ppP_Ext;
125 for( n = 0 ; n < nP_Nlf ; n++ )
126 delete ppP_Nlf[ n ];
127 delete[] ppP_Nlf;
129 for( n = 0 ; n < nP_Matrix ; n++ )
131 if( ppP_Matrix[ n ] )
132 ppP_Matrix[ n ]->DecRef( );
134 delete[] ppP_Matrix;
136 delete pScToken;
139 /** Returns the new number of elements, or 0 if overflow. */
140 static sal_uInt16 lcl_canGrow( sal_uInt16 nOld, sal_uInt16 nByMin = 1 )
142 if (!nOld)
143 return nByMin ? nByMin : 1;
144 if (nOld == SAL_MAX_UINT16)
145 return 0;
146 sal_uInt32 nNew = ::std::max( static_cast<sal_uInt32>(nOld) * 2,
147 static_cast<sal_uInt32>(nOld) + nByMin);
148 if (nNew > SAL_MAX_UINT16)
149 nNew = SAL_MAX_UINT16;
150 if (nNew - nByMin < nOld)
151 nNew = 0;
152 return static_cast<sal_uInt16>(nNew);
155 bool TokenPool::GrowString()
157 sal_uInt16 nP_StrNew = lcl_canGrow( nP_Str);
158 if (!nP_StrNew)
159 return false;
161 sal_uInt16 nL;
163 OUString** ppP_StrNew = new (::std::nothrow) OUString *[ nP_StrNew ];
164 if (!ppP_StrNew)
165 return false;
167 for( nL = 0 ; nL < nP_Str ; nL++ )
168 ppP_StrNew[ nL ] = ppP_Str[ nL ];
169 for( nL = nP_Str ; nL < nP_StrNew ; nL++ )
170 ppP_StrNew[ nL ] = NULL;
172 nP_Str = nP_StrNew;
174 delete[] ppP_Str;
175 ppP_Str = ppP_StrNew;
176 return true;
179 bool TokenPool::GrowDouble()
181 sal_uInt16 nP_DblNew = lcl_canGrow( nP_Dbl);
182 if (!nP_DblNew)
183 return false;
185 double* pP_DblNew = new (::std::nothrow) double[ nP_DblNew ];
186 if (!pP_DblNew)
187 return false;
189 for( sal_uInt16 nL = 0 ; nL < nP_Dbl ; nL++ )
190 pP_DblNew[ nL ] = pP_Dbl[ nL ];
192 nP_Dbl = nP_DblNew;
194 delete[] pP_Dbl;
195 pP_Dbl = pP_DblNew;
196 return true;
199 /* TODO: in case we had FormulaTokenArray::AddError() */
200 #if 0
201 void TokenPool::GrowError()
203 sal_uInt16 nP_ErrNew = lcl_canGrow( nP_Err);
204 if (!nP_ErrNew)
205 return false;
207 sal_uInt16* pP_ErrNew = new (::std::nothrow) sal_uInt16[ nP_ErrNew ];
208 if (!pP_ErrNew)
209 return false;
211 for( sal_uInt16 nL = 0 ; nL < nP_Err ; nL++ )
212 pP_ErrNew[ nL ] = pP_Err[ nL ];
214 nP_Err = nP_ErrNew;
216 delete[] pP_Err;
217 pP_Err = pP_ErrNew;
218 return true;
220 #endif
222 bool TokenPool::GrowTripel( sal_uInt16 nByMin )
224 sal_uInt16 nP_RefTrNew = lcl_canGrow( nP_RefTr, nByMin);
225 if (!nP_RefTrNew)
226 return false;
228 sal_uInt16 nL;
230 ScSingleRefData** ppP_RefTrNew = new (::std::nothrow) ScSingleRefData *[ nP_RefTrNew ];
231 if (!ppP_RefTrNew)
232 return false;
234 for( nL = 0 ; nL < nP_RefTr ; nL++ )
235 ppP_RefTrNew[ nL ] = ppP_RefTr[ nL ];
236 for( nL = nP_RefTr ; nL < nP_RefTrNew ; nL++ )
237 ppP_RefTrNew[ nL ] = NULL;
239 nP_RefTr = nP_RefTrNew;
241 delete[] ppP_RefTr;
242 ppP_RefTr = ppP_RefTrNew;
243 return true;
246 bool TokenPool::GrowId()
248 sal_uInt16 nP_IdNew = lcl_canGrow( nP_Id);
249 if (!nP_IdNew)
250 return false;
252 sal_uInt16* pP_IdNew = new (::std::nothrow) sal_uInt16[ nP_IdNew ];
253 if (!pP_IdNew)
254 return false;
256 for( sal_uInt16 nL = 0 ; nL < nP_Id ; nL++ )
257 pP_IdNew[ nL ] = pP_Id[ nL ];
259 nP_Id = nP_IdNew;
261 delete[] pP_Id;
262 pP_Id = pP_IdNew;
263 return true;
266 bool TokenPool::GrowElement()
268 sal_uInt16 nElementNew = lcl_canGrow( nElement);
269 if (!nElementNew)
270 return false;
272 sal_uInt16* pElementNew = new (::std::nothrow) sal_uInt16[ nElementNew ];
273 E_TYPE* pTypeNew = new (::std::nothrow) E_TYPE[ nElementNew ];
274 sal_uInt16* pSizeNew = new (::std::nothrow) sal_uInt16[ nElementNew ];
275 if (!pElementNew || !pTypeNew || !pSizeNew)
277 delete [] pElementNew;
278 delete [] pTypeNew;
279 delete [] pSizeNew;
280 return false;
283 for( sal_uInt16 nL = 0 ; nL < nElement ; nL++ )
285 pElementNew[ nL ] = pElement[ nL ];
286 pTypeNew[ nL ] = pType[ nL ];
287 pSizeNew[ nL ] = pSize[ nL ];
290 nElement = nElementNew;
292 delete[] pElement;
293 delete[] pType;
294 delete[] pSize;
295 pElement = pElementNew;
296 pType = pTypeNew;
297 pSize = pSizeNew;
298 return true;
301 bool TokenPool::GrowExt()
303 sal_uInt16 nNewSize = lcl_canGrow( nP_Ext);
304 if (!nNewSize)
305 return false;
307 EXTCONT** ppNew = new (::std::nothrow) EXTCONT*[ nNewSize ];
308 if (!ppNew)
309 return false;
311 memset( ppNew, 0, sizeof( EXTCONT* ) * nNewSize );
312 memcpy( ppNew, ppP_Ext, sizeof( EXTCONT* ) * nP_Ext );
314 delete[] ppP_Ext;
315 ppP_Ext = ppNew;
316 nP_Ext = nNewSize;
317 return true;
320 bool TokenPool::GrowNlf()
322 sal_uInt16 nNewSize = lcl_canGrow( nP_Nlf);
323 if (!nNewSize)
324 return false;
326 NLFCONT** ppNew = new (::std::nothrow) NLFCONT*[ nNewSize ];
327 if (!ppNew)
328 return false;
330 memset( ppNew, 0, sizeof( NLFCONT* ) * nNewSize );
331 memcpy( ppNew, ppP_Nlf, sizeof( NLFCONT* ) * nP_Nlf );
333 delete[] ppP_Nlf;
334 ppP_Nlf = ppNew;
335 nP_Nlf = nNewSize;
336 return true;
339 bool TokenPool::GrowMatrix()
341 sal_uInt16 nNewSize = lcl_canGrow( nP_Matrix);
342 if (!nNewSize)
343 return false;
345 ScMatrix** ppNew = new (::std::nothrow) ScMatrix*[ nNewSize ];
346 if (!ppNew)
347 return false;
349 memset( ppNew, 0, sizeof( ScMatrix* ) * nNewSize );
350 memcpy( ppNew, ppP_Matrix, sizeof( ScMatrix* ) * nP_Matrix );
352 delete[] ppP_Matrix;
353 ppP_Matrix = ppNew;
354 nP_Matrix = nNewSize;
355 return true;
358 bool TokenPool::GetElement( const sal_uInt16 nId )
360 OSL_ENSURE( nId < nElementAkt, "*TokenPool::GetElement(): Id too large!?" );
361 if (nId >= nElementAkt)
362 return false;
364 bool bRet = true;
365 if( pType[ nId ] == T_Id )
366 bRet = GetElementRek( nId );
367 else
369 switch( pType[ nId ] )
371 case T_Str:
373 sal_uInt16 n = pElement[ nId ];
374 OUString* p = ( n < nP_Str )? ppP_Str[ n ] : NULL;
375 if (p)
376 pScToken->AddString(mrStringPool.intern(*p));
377 else
378 bRet = false;
380 break;
381 case T_D:
383 sal_uInt16 n = pElement[ nId ];
384 if (n < nP_Dbl)
385 pScToken->AddDouble( pP_Dbl[ n ] );
386 else
387 bRet = false;
389 break;
390 case T_Err:
391 /* TODO: in case we had FormulaTokenArray::AddError() */
392 #if 0
394 sal_uInt16 n = pElement[ nId ];
395 if (n < nP_Err)
396 pScToken->AddError( pP_Err[ n ] );
397 else
398 bRet = false;
400 #endif
401 break;
402 case T_RefC:
404 sal_uInt16 n = pElement[ nId ];
405 ScSingleRefData* p = ( n < nP_RefTr )? ppP_RefTr[ n ] : NULL;
406 if (p)
407 pScToken->AddSingleReference( *p );
408 else
409 bRet = false;
411 break;
412 case T_RefA:
414 sal_uInt16 n = pElement[ nId ];
415 if (n < nP_RefTr && ppP_RefTr[ n ] && n+1 < nP_RefTr && ppP_RefTr[ n + 1 ])
417 ScComplexRefData aScComplexRefData;
418 aScComplexRefData.Ref1 = *ppP_RefTr[ n ];
419 aScComplexRefData.Ref2 = *ppP_RefTr[ n + 1 ];
420 pScToken->AddDoubleReference( aScComplexRefData );
422 else
423 bRet = false;
425 break;
426 case T_RN:
428 sal_uInt16 n = pElement[nId];
429 if (n < maRangeNames.size())
431 const RangeName& r = maRangeNames[n];
432 pScToken->AddRangeName(r.mnIndex, r.mbGlobal);
435 break;
436 case T_Ext:
438 sal_uInt16 n = pElement[ nId ];
439 EXTCONT* p = ( n < nP_Ext )? ppP_Ext[ n ] : NULL;
441 if( p )
443 if( p->eId == ocEuroConvert )
444 pScToken->AddOpCode( p->eId );
445 else
446 pScToken->AddExternal( p->aText, p->eId );
448 else
449 bRet = false;
451 break;
452 case T_Nlf:
454 sal_uInt16 n = pElement[ nId ];
455 NLFCONT* p = ( n < nP_Nlf )? ppP_Nlf[ n ] : NULL;
457 if( p )
458 pScToken->AddColRowName( p->aRef );
459 else
460 bRet = false;
462 break;
463 case T_Matrix:
465 sal_uInt16 n = pElement[ nId ];
466 ScMatrix* p = ( n < nP_Matrix )? ppP_Matrix[ n ] : NULL;
468 if( p )
469 pScToken->AddMatrix( p );
470 else
471 bRet = false;
473 break;
474 case T_ExtName:
476 sal_uInt16 n = pElement[nId];
477 if (n < maExtNames.size())
479 const ExtName& r = maExtNames[n];
480 pScToken->AddExternalName(r.mnFileId, r.maName);
482 else
483 bRet = false;
485 break;
486 case T_ExtRefC:
488 sal_uInt16 n = pElement[nId];
489 if (n < maExtCellRefs.size())
491 const ExtCellRef& r = maExtCellRefs[n];
492 pScToken->AddExternalSingleReference(r.mnFileId, r.maTabName, r.maRef);
494 else
495 bRet = false;
497 break;
498 case T_ExtRefA:
500 sal_uInt16 n = pElement[nId];
501 if (n < maExtAreaRefs.size())
503 const ExtAreaRef& r = maExtAreaRefs[n];
504 pScToken->AddExternalDoubleReference(r.mnFileId, r.maTabName, r.maRef);
506 else
507 bRet = false;
509 break;
510 default:
511 OSL_FAIL("-TokenPool::GetElement(): undefined state!?");
512 bRet = false;
515 return bRet;
518 bool TokenPool::GetElementRek( const sal_uInt16 nId )
520 #ifdef DBG_UTIL
521 m_nRek++;
522 OSL_ENSURE(m_nRek <= nP_Id, "*TokenPool::GetElement(): recursion loops!?");
523 #endif
525 OSL_ENSURE( nId < nElementAkt, "*TokenPool::GetElementRek(): nId >= nElementAkt" );
527 if (nId >= nElementAkt)
529 SAL_WARN("sc.filter", "*TokenPool::GetElementRek(): nId >= nElementAkt");
530 #ifdef DBG_UTIL
531 m_nRek--;
532 #endif
533 return false;
536 if (pType[ nId ] != T_Id)
538 SAL_WARN("sc.filter", "-TokenPool::GetElementRek(): pType[ nId ] != T_Id");
539 #ifdef DBG_UTIL
540 m_nRek--;
541 #endif
542 return false;
545 bool bRet = true;
546 sal_uInt16 nAnz = pSize[ nId ];
547 sal_uInt16 nFirstId = pElement[ nId ];
548 if (nFirstId >= nP_Id)
550 SAL_WARN("sc.filter", "TokenPool::GetElementRek: nFirstId >= nP_Id");
551 nAnz = 0;
552 bRet = false;
554 sal_uInt16* pAkt = nAnz ? &pP_Id[ nFirstId ] : NULL;
555 if (nAnz > nP_Id - nFirstId)
557 SAL_WARN("sc.filter", "TokenPool::GetElementRek: nAnz > nP_Id - nFirstId");
558 nAnz = nP_Id - nFirstId;
559 bRet = false;
561 for( ; nAnz > 0 ; nAnz--, pAkt++ )
563 if( *pAkt < nScTokenOff )
564 {// recursion or not?
565 if (*pAkt >= nElementAkt)
567 SAL_WARN("sc.filter", "TokenPool::GetElementRek: *pAkt >= nElementAkt");
568 bRet = false;
570 else
572 if (pType[ *pAkt ] == T_Id)
573 bRet = GetElementRek( *pAkt );
574 else
575 bRet = GetElement( *pAkt );
578 else // elementary SC_Token
579 pScToken->AddOpCode( ( DefTokenId ) ( *pAkt - nScTokenOff ) );
582 #ifdef DBG_UTIL
583 m_nRek--;
584 #endif
585 return bRet;
588 void TokenPool::operator >>( TokenId& rId )
590 rId = static_cast<TokenId>( nElementAkt + 1 );
592 if( nElementAkt >= nElement )
593 if (!GrowElement())
594 return;
596 pElement[ nElementAkt ] = nP_IdLast; // Start of Token-sequence
597 pType[ nElementAkt ] = T_Id; // set Typeinfo
598 pSize[ nElementAkt ] = nP_IdAkt - nP_IdLast;
599 // write from nP_IdLast to nP_IdAkt-1 -> length of the sequence
601 nElementAkt++; // start value for next sequence
602 nP_IdLast = nP_IdAkt;
605 const TokenId TokenPool::Store( const double& rDouble )
607 if( nElementAkt >= nElement )
608 if (!GrowElement())
609 return static_cast<const TokenId>(nElementAkt+1);
611 if( nP_DblAkt >= nP_Dbl )
612 if (!GrowDouble())
613 return static_cast<const TokenId>(nElementAkt+1);
615 pElement[ nElementAkt ] = nP_DblAkt; // Index in Double-Array
616 pType[ nElementAkt ] = T_D; // set Typeinfo Double
618 pP_Dbl[ nP_DblAkt ] = rDouble;
620 pSize[ nElementAkt ] = 1; // does not matter
622 nElementAkt++;
623 nP_DblAkt++;
625 return static_cast<const TokenId>(nElementAkt); // return old value + 1!
628 const TokenId TokenPool::Store( const sal_uInt16 nIndex )
630 return StoreName(nIndex, true);
633 const TokenId TokenPool::Store( const OUString& rString )
635 // mostly copied to Store( const sal_Char* ), to avoid a temporary string
636 if( nElementAkt >= nElement )
637 if (!GrowElement())
638 return static_cast<const TokenId>(nElementAkt+1);
640 if( nP_StrAkt >= nP_Str )
641 if (!GrowString())
642 return static_cast<const TokenId>(nElementAkt+1);
644 pElement[ nElementAkt ] = nP_StrAkt; // Index in String-Array
645 pType[ nElementAkt ] = T_Str; // set Typeinfo String
647 // create String
648 if( !ppP_Str[ nP_StrAkt ] )
649 //...but only, if it does not exist already
650 ppP_Str[ nP_StrAkt ] = new (::std::nothrow) OUString( rString );
651 else
652 //...copy otherwise
653 *ppP_Str[ nP_StrAkt ] = rString;
655 if (ppP_Str[ nP_StrAkt ])
657 /* attention trucate to 16 bits */
658 pSize[ nElementAkt ] = ( sal_uInt16 ) ppP_Str[ nP_StrAkt ]->getLength();
661 nElementAkt++;
662 nP_StrAkt++;
664 return static_cast<const TokenId>(nElementAkt); // return old value + 1!
667 const TokenId TokenPool::Store( const ScSingleRefData& rTr )
669 if( nElementAkt >= nElement )
670 if (!GrowElement())
671 return static_cast<const TokenId>(nElementAkt+1);
673 if( nP_RefTrAkt >= nP_RefTr )
674 if (!GrowTripel())
675 return static_cast<const TokenId>(nElementAkt+1);
677 pElement[ nElementAkt ] = nP_RefTrAkt;
678 pType[ nElementAkt ] = T_RefC; // set Typeinfo Cell-Ref
680 if( !ppP_RefTr[ nP_RefTrAkt ] )
681 ppP_RefTr[ nP_RefTrAkt ] = new ScSingleRefData( rTr );
682 else
683 *ppP_RefTr[ nP_RefTrAkt ] = rTr;
685 nElementAkt++;
686 nP_RefTrAkt++;
688 return static_cast<const TokenId>(nElementAkt); // return old value + 1!
691 const TokenId TokenPool::Store( const ScComplexRefData& rTr )
693 if( nElementAkt >= nElement )
694 if (!GrowElement())
695 return static_cast<const TokenId>(nElementAkt+1);
697 if( nP_RefTrAkt + 1 >= nP_RefTr )
698 if (!GrowTripel( 2))
699 return static_cast<const TokenId>(nElementAkt+1);
701 pElement[ nElementAkt ] = nP_RefTrAkt;
702 pType[ nElementAkt ] = T_RefA; // setTypeinfo Area-Ref
704 if( !ppP_RefTr[ nP_RefTrAkt ] )
705 ppP_RefTr[ nP_RefTrAkt ] = new ScSingleRefData( rTr.Ref1 );
706 else
707 *ppP_RefTr[ nP_RefTrAkt ] = rTr.Ref1;
708 nP_RefTrAkt++;
710 if( !ppP_RefTr[ nP_RefTrAkt ] )
711 ppP_RefTr[ nP_RefTrAkt ] = new ScSingleRefData( rTr.Ref2 );
712 else
713 *ppP_RefTr[ nP_RefTrAkt ] = rTr.Ref2;
714 nP_RefTrAkt++;
716 nElementAkt++;
718 return static_cast<const TokenId>(nElementAkt); // return old value + 1!
721 const TokenId TokenPool::Store( const DefTokenId e, const OUString& r )
723 if( nElementAkt >= nElement )
724 if (!GrowElement())
725 return static_cast<const TokenId>(nElementAkt+1);
727 if( nP_ExtAkt >= nP_Ext )
728 if (!GrowExt())
729 return static_cast<const TokenId>(nElementAkt+1);
731 pElement[ nElementAkt ] = nP_ExtAkt;
732 pType[ nElementAkt ] = T_Ext; // set Typeinfo String
734 if( ppP_Ext[ nP_ExtAkt ] )
736 ppP_Ext[ nP_ExtAkt ]->eId = e;
737 ppP_Ext[ nP_ExtAkt ]->aText = r;
739 else
740 ppP_Ext[ nP_ExtAkt ] = new EXTCONT( e, r );
742 nElementAkt++;
743 nP_ExtAkt++;
745 return static_cast<const TokenId>(nElementAkt); // return old value + 1!
748 const TokenId TokenPool::StoreNlf( const ScSingleRefData& rTr )
750 if( nElementAkt >= nElement )
751 if (!GrowElement())
752 return static_cast<const TokenId>(nElementAkt+1);
754 if( nP_NlfAkt >= nP_Nlf )
755 if (!GrowNlf())
756 return static_cast<const TokenId>(nElementAkt+1);
758 pElement[ nElementAkt ] = nP_NlfAkt;
759 pType[ nElementAkt ] = T_Nlf;
761 if( ppP_Nlf[ nP_NlfAkt ] )
763 ppP_Nlf[ nP_NlfAkt ]->aRef = rTr;
765 else
766 ppP_Nlf[ nP_NlfAkt ] = new NLFCONT( rTr );
768 nElementAkt++;
769 nP_NlfAkt++;
771 return static_cast<const TokenId>(nElementAkt);
774 const TokenId TokenPool::StoreMatrix()
776 ScMatrix* pM;
778 if( nElementAkt >= nElement )
779 if (!GrowElement())
780 return static_cast<const TokenId>(nElementAkt+1);
782 if( nP_MatrixAkt >= nP_Matrix )
783 if (!GrowMatrix())
784 return static_cast<const TokenId>(nElementAkt+1);
786 pElement[ nElementAkt ] = nP_MatrixAkt;
787 pType[ nElementAkt ] = T_Matrix;
789 pM = new ScMatrix( 0, 0 );
790 pM->IncRef( );
791 ppP_Matrix[ nP_MatrixAkt ] = pM;
793 nElementAkt++;
794 nP_MatrixAkt++;
796 return static_cast<const TokenId>(nElementAkt);
799 const TokenId TokenPool::StoreName( sal_uInt16 nIndex, bool bGlobal )
801 if ( nElementAkt >= nElement )
802 if (!GrowElement())
803 return static_cast<const TokenId>(nElementAkt+1);
805 pElement[nElementAkt] = static_cast<sal_uInt16>(maRangeNames.size());
806 pType[nElementAkt] = T_RN;
808 maRangeNames.push_back(RangeName());
809 RangeName& r = maRangeNames.back();
810 r.mnIndex = nIndex;
811 r.mbGlobal = bGlobal;
813 ++nElementAkt;
815 return static_cast<const TokenId>(nElementAkt);
818 const TokenId TokenPool::StoreExtName( sal_uInt16 nFileId, const OUString& rName )
820 if ( nElementAkt >= nElement )
821 if (!GrowElement())
822 return static_cast<const TokenId>(nElementAkt+1);
824 pElement[nElementAkt] = static_cast<sal_uInt16>(maExtNames.size());
825 pType[nElementAkt] = T_ExtName;
827 maExtNames.push_back(ExtName());
828 ExtName& r = maExtNames.back();
829 r.mnFileId = nFileId;
830 r.maName = rName;
832 ++nElementAkt;
834 return static_cast<const TokenId>(nElementAkt);
837 const TokenId TokenPool::StoreExtRef( sal_uInt16 nFileId, const OUString& rTabName, const ScSingleRefData& rRef )
839 if ( nElementAkt >= nElement )
840 if (!GrowElement())
841 return static_cast<const TokenId>(nElementAkt+1);
843 pElement[nElementAkt] = static_cast<sal_uInt16>(maExtCellRefs.size());
844 pType[nElementAkt] = T_ExtRefC;
846 maExtCellRefs.push_back(ExtCellRef());
847 ExtCellRef& r = maExtCellRefs.back();
848 r.mnFileId = nFileId;
849 r.maTabName = rTabName;
850 r.maRef = rRef;
852 ++nElementAkt;
854 return static_cast<const TokenId>(nElementAkt);
857 const TokenId TokenPool::StoreExtRef( sal_uInt16 nFileId, const OUString& rTabName, const ScComplexRefData& rRef )
859 if ( nElementAkt >= nElement )
860 if (!GrowElement())
861 return static_cast<const TokenId>(nElementAkt+1);
863 pElement[nElementAkt] = static_cast<sal_uInt16>(maExtAreaRefs.size());
864 pType[nElementAkt] = T_ExtRefA;
866 maExtAreaRefs.push_back(ExtAreaRef());
867 ExtAreaRef& r = maExtAreaRefs.back();
868 r.mnFileId = nFileId;
869 r.maTabName = rTabName;
870 r.maRef = rRef;
872 ++nElementAkt;
874 return static_cast<const TokenId>(nElementAkt);
877 void TokenPool::Reset()
879 nP_IdAkt = nP_IdLast = nElementAkt = nP_StrAkt = nP_DblAkt = nP_ErrAkt = nP_RefTrAkt = nP_ExtAkt = nP_NlfAkt = nP_MatrixAkt = 0;
880 maRangeNames.clear();
881 maExtNames.clear();
882 maExtCellRefs.clear();
883 maExtAreaRefs.clear();
886 bool TokenPool::IsSingleOp( const TokenId& rId, const DefTokenId eId ) const
888 sal_uInt16 nId = (sal_uInt16) rId;
889 if( nId && nId <= nElementAkt )
890 {// existent?
891 nId--;
892 if( T_Id == pType[ nId ] )
893 {// Token-Sequence?
894 if( pSize[ nId ] == 1 )
895 {// EXACTLY 1 Token
896 sal_uInt16 nPid = pElement[ nId ];
897 if (nPid < nP_Id)
899 sal_uInt16 nSecId = pP_Id[ nPid ];
900 if( nSecId >= nScTokenOff )
901 {// Default-Token?
902 return ( DefTokenId ) ( nSecId - nScTokenOff ) == eId; // wanted?
909 return false;
912 const OUString* TokenPool::GetExternal( const TokenId& rId ) const
914 const OUString* p = NULL;
915 sal_uInt16 n = (sal_uInt16) rId;
916 if( n && n <= nElementAkt )
918 n--;
919 if( pType[ n ] == T_Ext )
921 sal_uInt16 nExt = pElement[ n ];
922 if ( nExt < nP_Ext && ppP_Ext[ nExt ] )
923 p = &ppP_Ext[ nExt ]->aText;
927 return p;
930 ScMatrix* TokenPool::GetMatrix( unsigned int n ) const
932 if( n < nP_MatrixAkt )
933 return ppP_Matrix[ n ];
934 else
935 printf ("GETMATRIX %d >= %d\n", n, nP_MatrixAkt);
936 return NULL;
939 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */