bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / filter / excel / tokstack.cxx
blob49cadd9af4d19341f6f1fe994c85af05c5eb4607
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 <string.h>
22 #include "compiler.hxx"
23 #include "tokstack.hxx"
24 #include "global.hxx"
25 #include "scmatrix.hxx"
27 #include <stdio.h> // printf
29 const sal_uInt16 TokenPool::nScTokenOff = 8192;
32 TokenStack::TokenStack( sal_uInt16 nNewSize )
34 pStack = new TokenId[ nNewSize ];
36 Reset();
37 nSize = nNewSize;
41 TokenStack::~TokenStack()
43 delete[] pStack;
49 //------------------------------------------------------------------------
51 // !ACHTUNG!: nach Aussen hin beginnt die Nummerierung mit 1!
52 // !ACHTUNG!: SC-Token werden mit einem Offset nScTokenOff abgelegt
53 // -> Unterscheidung von anderen Token
56 TokenPool::TokenPool( void )
58 sal_uInt16 nLauf = nScTokenOff;
60 // Sammelstelle fuer Id-Folgen
61 nP_Id = 256;
62 pP_Id = new sal_uInt16[ nP_Id ];
64 // Sammelstelle fuer Ids
65 nElement = 32;
66 pElement = new sal_uInt16[ nElement ];
67 pType = new E_TYPE[ nElement ];
68 pSize = new sal_uInt16[ nElement ];
69 nP_IdLast = 0;
71 // Sammelstelle fuer Strings
72 nP_Str = 4;
73 ppP_Str = new String *[ nP_Str ];
74 for( nLauf = 0 ; nLauf < nP_Str ; nLauf++ )
75 ppP_Str[ nLauf ] = NULL;
77 // Sammelstelle fuer double
78 nP_Dbl = 8;
79 pP_Dbl = new double[ nP_Dbl ];
81 // Sammelstelle fuer error codes
82 nP_Err = 8;
83 pP_Err = new sal_uInt16[ nP_Err ];
85 // Sammelstellen fuer Referenzen
86 nP_RefTr = 32;
87 ppP_RefTr = new ScSingleRefData *[ nP_RefTr ];
88 for( nLauf = 0 ; nLauf < nP_RefTr ; nLauf++ )
89 ppP_RefTr[ nLauf ] = NULL;
91 nP_Ext = 32;
92 ppP_Ext = new EXTCONT*[ nP_Ext ];
93 memset( ppP_Ext, 0, sizeof( EXTCONT* ) * nP_Ext );
95 nP_Nlf = 16;
96 ppP_Nlf = new NLFCONT*[ nP_Nlf ];
97 memset( ppP_Nlf, 0, sizeof( NLFCONT* ) * nP_Nlf );
99 nP_Matrix = 16;
100 ppP_Matrix = new ScMatrix*[ nP_Matrix ];
101 memset( ppP_Matrix, 0, sizeof( ScMatrix* ) * nP_Matrix );
103 pScToken = new ScTokenArray;
105 Reset();
109 TokenPool::~TokenPool()
111 sal_uInt16 n;
113 delete[] pP_Id;
114 delete[] pElement;
115 delete[] pType;
116 delete[] pSize;
117 delete[] pP_Dbl;
118 delete[] pP_Err;
120 for( n = 0 ; n < nP_RefTr ; n++ )
121 delete ppP_RefTr[ n ];
122 delete[] ppP_RefTr;
124 for( n = 0 ; n < nP_Str ; n++ )
125 delete ppP_Str[ n ];
126 delete[] ppP_Str;
128 for( n = 0 ; n < nP_Ext ; n++ )
129 delete ppP_Ext[ n ];
130 delete[] ppP_Ext;
132 for( n = 0 ; n < nP_Nlf ; n++ )
133 delete ppP_Nlf[ n ];
134 delete[] ppP_Nlf;
136 for( n = 0 ; n < nP_Matrix ; n++ )
138 if( ppP_Matrix[ n ] )
139 ppP_Matrix[ n ]->DecRef( );
141 delete[] ppP_Matrix;
143 delete pScToken;
147 /** Returns the new number of elements, or 0 if overflow. */
148 static sal_uInt16 lcl_canGrow( sal_uInt16 nOld, sal_uInt16 nByMin = 1 )
150 if (!nOld)
151 return nByMin ? nByMin : 1;
152 if (nOld == SAL_MAX_UINT16)
153 return 0;
154 sal_uInt32 nNew = ::std::max( static_cast<sal_uInt32>(nOld) * 2,
155 static_cast<sal_uInt32>(nOld) + nByMin);
156 if (nNew > SAL_MAX_UINT16)
157 nNew = SAL_MAX_UINT16;
158 if (nNew - nByMin < nOld)
159 nNew = 0;
160 return static_cast<sal_uInt16>(nNew);
164 bool TokenPool::GrowString( void )
166 sal_uInt16 nP_StrNew = lcl_canGrow( nP_Str);
167 if (!nP_StrNew)
168 return false;
170 sal_uInt16 nL;
172 String** ppP_StrNew = new (::std::nothrow) String *[ nP_StrNew ];
173 if (!ppP_StrNew)
174 return false;
176 for( nL = 0 ; nL < nP_Str ; nL++ )
177 ppP_StrNew[ nL ] = ppP_Str[ nL ];
178 for( nL = nP_Str ; nL < nP_StrNew ; nL++ )
179 ppP_StrNew[ nL ] = NULL;
181 nP_Str = nP_StrNew;
183 delete[] ppP_Str;
184 ppP_Str = ppP_StrNew;
185 return true;
189 bool TokenPool::GrowDouble( void )
191 sal_uInt16 nP_DblNew = lcl_canGrow( nP_Dbl);
192 if (!nP_DblNew)
193 return false;
196 double* pP_DblNew = new (::std::nothrow) double[ nP_DblNew ];
197 if (!pP_DblNew)
198 return false;
200 for( sal_uInt16 nL = 0 ; nL < nP_Dbl ; nL++ )
201 pP_DblNew[ nL ] = pP_Dbl[ nL ];
203 nP_Dbl = nP_DblNew;
205 delete[] pP_Dbl;
206 pP_Dbl = pP_DblNew;
207 return true;
211 /* TODO: in case we had FormulaTokenArray::AddError() */
212 #if 0
213 void TokenPool::GrowError( void )
215 sal_uInt16 nP_ErrNew = lcl_canGrow( nP_Err);
216 if (!nP_ErrNew)
217 return false;
220 sal_uInt16* pP_ErrNew = new (::std::nothrow) sal_uInt16[ nP_ErrNew ];
221 if (!pP_ErrNew)
222 return false;
224 for( sal_uInt16 nL = 0 ; nL < nP_Err ; nL++ )
225 pP_ErrNew[ nL ] = pP_Err[ nL ];
227 nP_Err = nP_ErrNew;
229 delete[] pP_Err;
230 pP_Err = pP_ErrNew;
231 return true;
233 #endif
236 bool TokenPool::GrowTripel( sal_uInt16 nByMin )
238 sal_uInt16 nP_RefTrNew = lcl_canGrow( nP_RefTr, nByMin);
239 if (!nP_RefTrNew)
240 return false;
242 sal_uInt16 nL;
244 ScSingleRefData** ppP_RefTrNew = new (::std::nothrow) ScSingleRefData *[ nP_RefTrNew ];
245 if (!ppP_RefTrNew)
246 return false;
248 for( nL = 0 ; nL < nP_RefTr ; nL++ )
249 ppP_RefTrNew[ nL ] = ppP_RefTr[ nL ];
250 for( nL = nP_RefTr ; nL < nP_RefTrNew ; nL++ )
251 ppP_RefTrNew[ nL ] = NULL;
253 nP_RefTr = nP_RefTrNew;
255 delete[] ppP_RefTr;
256 ppP_RefTr = ppP_RefTrNew;
257 return true;
261 bool TokenPool::GrowId( void )
263 sal_uInt16 nP_IdNew = lcl_canGrow( nP_Id);
264 if (!nP_IdNew)
265 return false;
268 sal_uInt16* pP_IdNew = new (::std::nothrow) sal_uInt16[ nP_IdNew ];
269 if (!pP_IdNew)
270 return false;
272 for( sal_uInt16 nL = 0 ; nL < nP_Id ; nL++ )
273 pP_IdNew[ nL ] = pP_Id[ nL ];
275 nP_Id = nP_IdNew;
277 delete[] pP_Id;
278 pP_Id = pP_IdNew;
279 return true;
283 bool TokenPool::GrowElement( void )
285 sal_uInt16 nElementNew = lcl_canGrow( nElement);
286 if (!nElementNew)
287 return false;
290 sal_uInt16* pElementNew = new (::std::nothrow) sal_uInt16[ nElementNew ];
291 E_TYPE* pTypeNew = new (::std::nothrow) E_TYPE[ nElementNew ];
292 sal_uInt16* pSizeNew = new (::std::nothrow) sal_uInt16[ nElementNew ];
293 if (!pElementNew || !pTypeNew || !pSizeNew)
295 delete [] pElementNew;
296 delete [] pTypeNew;
297 delete [] pSizeNew;
298 return false;
301 for( sal_uInt16 nL = 0 ; nL < nElement ; nL++ )
303 pElementNew[ nL ] = pElement[ nL ];
304 pTypeNew[ nL ] = pType[ nL ];
305 pSizeNew[ nL ] = pSize[ nL ];
308 nElement = nElementNew;
310 delete[] pElement;
311 delete[] pType;
312 delete[] pSize;
313 pElement = pElementNew;
314 pType = pTypeNew;
315 pSize = pSizeNew;
316 return true;
320 bool TokenPool::GrowExt( void )
322 sal_uInt16 nNewSize = lcl_canGrow( nP_Ext);
323 if (!nNewSize)
324 return false;
326 EXTCONT** ppNew = new (::std::nothrow) EXTCONT*[ nNewSize ];
327 if (!ppNew)
328 return false;
330 memset( ppNew, 0, sizeof( EXTCONT* ) * nNewSize );
331 memcpy( ppNew, ppP_Ext, sizeof( EXTCONT* ) * nP_Ext );
333 delete[] ppP_Ext;
334 ppP_Ext = ppNew;
335 nP_Ext = nNewSize;
336 return true;
340 bool TokenPool::GrowNlf( void )
342 sal_uInt16 nNewSize = lcl_canGrow( nP_Nlf);
343 if (!nNewSize)
344 return false;
346 NLFCONT** ppNew = new (::std::nothrow) NLFCONT*[ nNewSize ];
347 if (!ppNew)
348 return false;
350 memset( ppNew, 0, sizeof( NLFCONT* ) * nNewSize );
351 memcpy( ppNew, ppP_Nlf, sizeof( NLFCONT* ) * nP_Nlf );
353 delete[] ppP_Nlf;
354 ppP_Nlf = ppNew;
355 nP_Nlf = nNewSize;
356 return true;
360 bool TokenPool::GrowMatrix( void )
362 sal_uInt16 nNewSize = lcl_canGrow( nP_Matrix);
363 if (!nNewSize)
364 return false;
366 ScMatrix** ppNew = new (::std::nothrow) ScMatrix*[ nNewSize ];
367 if (!ppNew)
368 return false;
370 memset( ppNew, 0, sizeof( ScMatrix* ) * nNewSize );
371 memcpy( ppNew, ppP_Matrix, sizeof( ScMatrix* ) * nP_Matrix );
373 delete[] ppP_Matrix;
374 ppP_Matrix = ppNew;
375 nP_Matrix = nNewSize;
376 return true;
379 bool TokenPool::GetElement( const sal_uInt16 nId )
381 OSL_ENSURE( nId < nElementAkt, "*TokenPool::GetElement(): Id too large!?" );
382 if (nId >= nElementAkt)
383 return false;
385 bool bRet = true;
386 if( pType[ nId ] == T_Id )
387 bRet = GetElementRek( nId );
388 else
390 switch( pType[ nId ] )
392 case T_Str:
394 sal_uInt16 n = pElement[ nId ];
395 String* p = ( n < nP_Str )? ppP_Str[ n ] : NULL;
396 if (p)
397 pScToken->AddString( *p );
398 else
399 bRet = false;
401 break;
402 case T_D:
404 sal_uInt16 n = pElement[ nId ];
405 if (n < nP_Dbl)
406 pScToken->AddDouble( pP_Dbl[ n ] );
407 else
408 bRet = false;
410 break;
411 case T_Err:
412 /* TODO: in case we had FormulaTokenArray::AddError() */
413 #if 0
415 sal_uInt16 n = pElement[ nId ];
416 if (n < nP_Err)
417 pScToken->AddError( pP_Err[ n ] );
418 else
419 bRet = false;
421 #endif
422 break;
423 case T_RefC:
425 sal_uInt16 n = pElement[ nId ];
426 ScSingleRefData* p = ( n < nP_RefTr )? ppP_RefTr[ n ] : NULL;
427 if (p)
428 pScToken->AddSingleReference( *p );
429 else
430 bRet = false;
432 break;
433 case T_RefA:
435 sal_uInt16 n = pElement[ nId ];
436 if (n < nP_RefTr && ppP_RefTr[ n ] && n+1 < nP_RefTr && ppP_RefTr[ n + 1 ])
438 ScComplexRefData aScComplexRefData;
439 aScComplexRefData.Ref1 = *ppP_RefTr[ n ];
440 aScComplexRefData.Ref2 = *ppP_RefTr[ n + 1 ];
441 pScToken->AddDoubleReference( aScComplexRefData );
443 else
444 bRet = false;
446 break;
447 case T_RN:
449 sal_uInt16 n = pElement[nId];
450 if (n < maRangeNames.size())
452 const RangeName& r = maRangeNames[n];
453 pScToken->AddRangeName(r.mnIndex, r.mbGlobal);
456 break;
457 case T_Ext:
459 sal_uInt16 n = pElement[ nId ];
460 EXTCONT* p = ( n < nP_Ext )? ppP_Ext[ n ] : NULL;
462 if( p )
464 if( p->eId == ocEuroConvert )
465 pScToken->AddOpCode( p->eId );
466 else
467 pScToken->AddExternal( p->aText, p->eId );
469 else
470 bRet = false;
472 break;
473 case T_Nlf:
475 sal_uInt16 n = pElement[ nId ];
476 NLFCONT* p = ( n < nP_Nlf )? ppP_Nlf[ n ] : NULL;
478 if( p )
479 pScToken->AddColRowName( p->aRef );
480 else
481 bRet = false;
483 break;
484 case T_Matrix:
486 sal_uInt16 n = pElement[ nId ];
487 ScMatrix* p = ( n < nP_Matrix )? ppP_Matrix[ n ] : NULL;
489 if( p )
490 pScToken->AddMatrix( p );
491 else
492 bRet = false;
494 break;
495 case T_ExtName:
497 sal_uInt16 n = pElement[nId];
498 if (n < maExtNames.size())
500 const ExtName& r = maExtNames[n];
501 pScToken->AddExternalName(r.mnFileId, r.maName);
503 else
504 bRet = false;
506 break;
507 case T_ExtRefC:
509 sal_uInt16 n = pElement[nId];
510 if (n < maExtCellRefs.size())
512 const ExtCellRef& r = maExtCellRefs[n];
513 pScToken->AddExternalSingleReference(r.mnFileId, r.maTabName, r.maRef);
515 else
516 bRet = false;
518 break;
519 case T_ExtRefA:
521 sal_uInt16 n = pElement[nId];
522 if (n < maExtAreaRefs.size())
524 const ExtAreaRef& r = maExtAreaRefs[n];
525 pScToken->AddExternalDoubleReference(r.mnFileId, r.maTabName, r.maRef);
527 else
528 bRet = false;
530 break;
531 default:
532 OSL_FAIL("-TokenPool::GetElement(): undefined state!?");
533 bRet = false;
536 return bRet;
540 bool TokenPool::GetElementRek( const sal_uInt16 nId )
542 #ifdef DBG_UTIL
543 m_nRek++;
544 OSL_ENSURE(m_nRek <= nP_Id, "*TokenPool::GetElement(): recursion loops!?");
545 #endif
547 OSL_ENSURE( nId < nElementAkt, "*TokenPool::GetElementRek(): nId >= nElementAkt" );
549 if (nId >= nElementAkt)
551 DBG_ERRORFILE( "*TokenPool::GetElementRek(): nId >= nElementAkt" );
552 #ifdef DBG_UTIL
553 m_nRek--;
554 #endif
555 return false;
558 if (pType[ nId ] != T_Id)
560 DBG_ERRORFILE( "-TokenPool::GetElementRek(): pType[ nId ] != T_Id" );
561 #ifdef DBG_UTIL
562 m_nRek--;
563 #endif
564 return false;
568 bool bRet = true;
569 sal_uInt16 nAnz = pSize[ nId ];
570 sal_uInt16 nFirstId = pElement[ nId ];
571 if (nFirstId >= nP_Id)
573 DBG_ERRORFILE( "TokenPool::GetElementRek: nFirstId >= nP_Id");
574 nAnz = 0;
575 bRet = false;
577 sal_uInt16* pAkt = nAnz ? &pP_Id[ nFirstId ] : NULL;
578 if (nAnz > nP_Id - nFirstId)
580 DBG_ERRORFILE( "TokenPool::GetElementRek: nAnz > nP_Id - nFirstId");
581 nAnz = nP_Id - nFirstId;
582 bRet = false;
584 for( ; nAnz > 0 ; nAnz--, pAkt++ )
586 if( *pAkt < nScTokenOff )
587 {// Rekursion oder nicht?
588 if (*pAkt >= nElementAkt)
590 DBG_ERRORFILE( "TokenPool::GetElementRek: *pAkt >= nElementAkt");
591 bRet = false;
593 else
595 if (pType[ *pAkt ] == T_Id)
596 bRet = GetElementRek( *pAkt );
597 else
598 bRet = GetElement( *pAkt );
601 else // elementarer SC_Token
602 pScToken->AddOpCode( ( DefTokenId ) ( *pAkt - nScTokenOff ) );
606 #ifdef DBG_UTIL
607 m_nRek--;
608 #endif
609 return bRet;
613 void TokenPool::operator >>( TokenId& rId )
615 rId = ( TokenId ) ( nElementAkt + 1 );
617 if( nElementAkt >= nElement )
618 if (!GrowElement())
619 return;
621 pElement[ nElementAkt ] = nP_IdLast; // Start der Token-Folge
622 pType[ nElementAkt ] = T_Id; // Typinfo eintragen
623 pSize[ nElementAkt ] = nP_IdAkt - nP_IdLast;
624 // von nP_IdLast bis nP_IdAkt-1 geschrieben -> Laenge der Folge
626 nElementAkt++; // Startwerte fuer naechste Folge
627 nP_IdLast = nP_IdAkt;
631 const TokenId TokenPool::Store( const double& rDouble )
633 if( nElementAkt >= nElement )
634 if (!GrowElement())
635 return (const TokenId) nElementAkt+1;
637 if( nP_DblAkt >= nP_Dbl )
638 if (!GrowDouble())
639 return (const TokenId) nElementAkt+1;
641 pElement[ nElementAkt ] = nP_DblAkt; // Index in Double-Array
642 pType[ nElementAkt ] = T_D; // Typinfo Double eintragen
644 pP_Dbl[ nP_DblAkt ] = rDouble;
646 pSize[ nElementAkt ] = 1; // eigentlich Banane
648 nElementAkt++;
649 nP_DblAkt++;
651 return ( const TokenId ) nElementAkt; // Ausgabe von altem Wert + 1!
655 const TokenId TokenPool::Store( const sal_uInt16 nIndex )
657 return StoreName(nIndex, true);
661 const TokenId TokenPool::Store( const String& rString )
663 // weitgehend nach Store( const sal_Char* ) kopiert, zur Vermeidung
664 // eines temporaeren Strings in "
665 if( nElementAkt >= nElement )
666 if (!GrowElement())
667 return (const TokenId) nElementAkt+1;
670 if( nP_StrAkt >= nP_Str )
671 if (!GrowString())
672 return (const TokenId) nElementAkt+1;
675 pElement[ nElementAkt ] = nP_StrAkt; // Index in String-Array
676 pType[ nElementAkt ] = T_Str; // Typinfo String eintragen
678 // String anlegen
679 if( !ppP_Str[ nP_StrAkt ] )
680 //...aber nur, wenn noch nicht vorhanden
681 ppP_Str[ nP_StrAkt ] = new (::std::nothrow) String( rString );
682 else
683 //...ansonsten nur kopieren
684 *ppP_Str[ nP_StrAkt ] = rString;
686 if (ppP_Str[ nP_StrAkt ])
688 DBG_ASSERT( sizeof( xub_StrLen ) <= 2, "*TokenPool::Store(): StrLen doesn't match!" );
689 pSize[ nElementAkt ] = ( sal_uInt16 ) ppP_Str[ nP_StrAkt ]->Len();
692 nElementAkt++;
693 nP_StrAkt++;
695 return ( const TokenId ) nElementAkt; // Ausgabe von altem Wert + 1!
699 const TokenId TokenPool::Store( const ScSingleRefData& rTr )
701 if( nElementAkt >= nElement )
702 if (!GrowElement())
703 return (const TokenId) nElementAkt+1;
705 if( nP_RefTrAkt >= nP_RefTr )
706 if (!GrowTripel())
707 return (const TokenId) nElementAkt+1;
709 pElement[ nElementAkt ] = nP_RefTrAkt;
710 pType[ nElementAkt ] = T_RefC; // Typinfo Cell-Reff eintragen
712 if( !ppP_RefTr[ nP_RefTrAkt ] )
713 ppP_RefTr[ nP_RefTrAkt ] = new ScSingleRefData( rTr );
714 else
715 *ppP_RefTr[ nP_RefTrAkt ] = rTr;
717 nElementAkt++;
718 nP_RefTrAkt++;
720 return ( const TokenId ) nElementAkt; // Ausgabe von altem Wert + 1!
724 const TokenId TokenPool::Store( const ScComplexRefData& rTr )
726 if( nElementAkt >= nElement )
727 if (!GrowElement())
728 return (const TokenId) nElementAkt+1;
730 if( nP_RefTrAkt + 1 >= nP_RefTr )
731 if (!GrowTripel( 2))
732 return (const TokenId) nElementAkt+1;
734 pElement[ nElementAkt ] = nP_RefTrAkt;
735 pType[ nElementAkt ] = T_RefA; // Typinfo Area-Reff eintragen
737 if( !ppP_RefTr[ nP_RefTrAkt ] )
738 ppP_RefTr[ nP_RefTrAkt ] = new ScSingleRefData( rTr.Ref1 );
739 else
740 *ppP_RefTr[ nP_RefTrAkt ] = rTr.Ref1;
741 nP_RefTrAkt++;
743 if( !ppP_RefTr[ nP_RefTrAkt ] )
744 ppP_RefTr[ nP_RefTrAkt ] = new ScSingleRefData( rTr.Ref2 );
745 else
746 *ppP_RefTr[ nP_RefTrAkt ] = rTr.Ref2;
747 nP_RefTrAkt++;
749 nElementAkt++;
751 return ( const TokenId ) nElementAkt; // Ausgabe von altem Wert + 1!
755 const TokenId TokenPool::Store( const DefTokenId e, const String& r )
757 if( nElementAkt >= nElement )
758 if (!GrowElement())
759 return (const TokenId) nElementAkt+1;
761 if( nP_ExtAkt >= nP_Ext )
762 if (!GrowExt())
763 return (const TokenId) nElementAkt+1;
765 pElement[ nElementAkt ] = nP_ExtAkt;
766 pType[ nElementAkt ] = T_Ext; // Typinfo String eintragen
768 if( ppP_Ext[ nP_ExtAkt ] )
770 ppP_Ext[ nP_ExtAkt ]->eId = e;
771 ppP_Ext[ nP_ExtAkt ]->aText = r;
773 else
774 ppP_Ext[ nP_ExtAkt ] = new EXTCONT( e, r );
776 nElementAkt++;
777 nP_ExtAkt++;
779 return ( const TokenId ) nElementAkt; // Ausgabe von altem Wert + 1!
783 const TokenId TokenPool::StoreNlf( const ScSingleRefData& rTr )
785 if( nElementAkt >= nElement )
786 if (!GrowElement())
787 return (const TokenId) nElementAkt+1;
789 if( nP_NlfAkt >= nP_Nlf )
790 if (!GrowNlf())
791 return (const TokenId) nElementAkt+1;
793 pElement[ nElementAkt ] = nP_NlfAkt;
794 pType[ nElementAkt ] = T_Nlf;
796 if( ppP_Nlf[ nP_NlfAkt ] )
798 ppP_Nlf[ nP_NlfAkt ]->aRef = rTr;
800 else
801 ppP_Nlf[ nP_NlfAkt ] = new NLFCONT( rTr );
803 nElementAkt++;
804 nP_NlfAkt++;
806 return ( const TokenId ) nElementAkt;
809 const TokenId TokenPool::StoreMatrix()
811 ScMatrix* pM;
813 if( nElementAkt >= nElement )
814 if (!GrowElement())
815 return (const TokenId) nElementAkt+1;
817 if( nP_MatrixAkt >= nP_Matrix )
818 if (!GrowMatrix())
819 return (const TokenId) nElementAkt+1;
821 pElement[ nElementAkt ] = nP_MatrixAkt;
822 pType[ nElementAkt ] = T_Matrix;
824 pM = new ScMatrix( 0, 0 );
825 pM->IncRef( );
826 ppP_Matrix[ nP_MatrixAkt ] = pM;
828 nElementAkt++;
829 nP_MatrixAkt++;
831 return ( const TokenId ) nElementAkt;
834 const TokenId TokenPool::StoreName( sal_uInt16 nIndex, bool bGlobal )
836 if ( nElementAkt >= nElement )
837 if (!GrowElement())
838 return (const TokenId) nElementAkt+1;
840 pElement[nElementAkt] = static_cast<sal_uInt16>(maRangeNames.size());
841 pType[nElementAkt] = T_RN;
843 maRangeNames.push_back(RangeName());
844 RangeName& r = maRangeNames.back();
845 r.mnIndex = nIndex;
846 r.mbGlobal = bGlobal;
848 ++nElementAkt;
850 return static_cast<const TokenId>(nElementAkt);
853 const TokenId TokenPool::StoreExtName( sal_uInt16 nFileId, const String& rName )
855 if ( nElementAkt >= nElement )
856 if (!GrowElement())
857 return (const TokenId) nElementAkt+1;
859 pElement[nElementAkt] = static_cast<sal_uInt16>(maExtNames.size());
860 pType[nElementAkt] = T_ExtName;
862 maExtNames.push_back(ExtName());
863 ExtName& r = maExtNames.back();
864 r.mnFileId = nFileId;
865 r.maName = rName;
867 ++nElementAkt;
869 return static_cast<const TokenId>(nElementAkt);
872 const TokenId TokenPool::StoreExtRef( sal_uInt16 nFileId, const String& rTabName, const ScSingleRefData& rRef )
874 if ( nElementAkt >= nElement )
875 if (!GrowElement())
876 return (const TokenId) nElementAkt+1;
878 pElement[nElementAkt] = static_cast<sal_uInt16>(maExtCellRefs.size());
879 pType[nElementAkt] = T_ExtRefC;
881 maExtCellRefs.push_back(ExtCellRef());
882 ExtCellRef& r = maExtCellRefs.back();
883 r.mnFileId = nFileId;
884 r.maTabName = rTabName;
885 r.maRef = rRef;
887 ++nElementAkt;
889 return static_cast<const TokenId>(nElementAkt);
892 const TokenId TokenPool::StoreExtRef( sal_uInt16 nFileId, const String& rTabName, const ScComplexRefData& rRef )
894 if ( nElementAkt >= nElement )
895 if (!GrowElement())
896 return (const TokenId) nElementAkt+1;
898 pElement[nElementAkt] = static_cast<sal_uInt16>(maExtAreaRefs.size());
899 pType[nElementAkt] = T_ExtRefA;
901 maExtAreaRefs.push_back(ExtAreaRef());
902 ExtAreaRef& r = maExtAreaRefs.back();
903 r.mnFileId = nFileId;
904 r.maTabName = rTabName;
905 r.maRef = rRef;
907 ++nElementAkt;
909 return static_cast<const TokenId>(nElementAkt);
912 void TokenPool::Reset( void )
914 nP_IdAkt = nP_IdLast = nElementAkt = nP_StrAkt = nP_DblAkt = nP_ErrAkt = nP_RefTrAkt = nP_ExtAkt = nP_NlfAkt = nP_MatrixAkt = 0;
915 maRangeNames.clear();
916 maExtNames.clear();
917 maExtCellRefs.clear();
918 maExtAreaRefs.clear();
922 sal_Bool TokenPool::IsSingleOp( const TokenId& rId, const DefTokenId eId ) const
924 sal_uInt16 nId = (sal_uInt16) rId;
925 if( nId && nId <= nElementAkt )
926 {// existent?
927 nId--;
928 if( T_Id == pType[ nId ] )
929 {// Tokenfolge?
930 if( pSize[ nId ] == 1 )
931 {// GENAU 1 Token
932 sal_uInt16 nPid = pElement[ nId ];
933 if (nPid < nP_Id)
935 sal_uInt16 nSecId = pP_Id[ nPid ];
936 if( nSecId >= nScTokenOff )
937 {// Default-Token?
938 return ( DefTokenId ) ( nSecId - nScTokenOff ) == eId; // Gesuchter?
945 return false;
948 const String* TokenPool::GetExternal( const TokenId& rId ) const
950 const String* p = NULL;
951 sal_uInt16 n = (sal_uInt16) rId;
952 if( n && n <= nElementAkt )
954 n--;
955 if( pType[ n ] == T_Ext )
957 sal_uInt16 nExt = pElement[ n ];
958 if ( nExt < nP_Ext && ppP_Ext[ nExt ] )
959 p = &ppP_Ext[ nExt ]->aText;
963 return p;
966 ScMatrix* TokenPool::GetMatrix( unsigned int n ) const
968 if( n < nP_MatrixAkt )
969 return ppP_Matrix[ n ];
970 else
971 printf ("GETMATRIX %d >= %d\n", n, nP_MatrixAkt);
972 return NULL;
975 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */