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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_scfilt.hxx"
26
27
28 #ifndef PCH
29 #include <string.h>
30 #endif
31
32 #include "compiler.hxx"
33 #include "tokstack.hxx"
34 #include "global.hxx"
35 #include "scmatrix.hxx"
36
37 #include <stdio.h> // printf
38
39 const sal_uInt16 TokenPool::nScTokenOff = 8192;
40
41
TokenStack(sal_uInt16 nNewSize)42 TokenStack::TokenStack( sal_uInt16 nNewSize )
43 {
44 pStack = new TokenId[ nNewSize ];
45
46 Reset();
47 nSize = nNewSize;
48 }
49
50
~TokenStack()51 TokenStack::~TokenStack()
52 {
53 delete[] pStack;
54 }
55
56
57
58
59 //------------------------------------------------------------------------
60
61 // !ACHTUNG!: nach Aussen hin beginnt die Nummerierung mit 1!
62 // !ACHTUNG!: SC-Token werden mit einem Offset nScTokenOff abgelegt
63 // -> Unterscheidung von anderen Token
64
65
TokenPool(void)66 TokenPool::TokenPool( void )
67 {
68 sal_uInt16 nLauf = nScTokenOff;
69
70 // Sammelstelle fuer Id-Folgen
71 nP_Id = 256;
72 pP_Id = new sal_uInt16[ nP_Id ];
73
74 // Sammelstelle fuer Ids
75 nElement = 32;
76 pElement = new sal_uInt16[ nElement ];
77 pType = new E_TYPE[ nElement ];
78 pSize = new sal_uInt16[ nElement ];
79 nP_IdLast = 0;
80
81 // Sammelstelle fuer Strings
82 nP_Str = 4;
83 ppP_Str = new String *[ nP_Str ];
84 for( nLauf = 0 ; nLauf < nP_Str ; nLauf++ )
85 ppP_Str[ nLauf ] = NULL;
86
87 // Sammelstelle fuer double
88 nP_Dbl = 8;
89 pP_Dbl = new double[ nP_Dbl ];
90
91 // Sammelstelle fuer error codes
92 nP_Err = 8;
93 pP_Err = new sal_uInt16[ nP_Err ];
94
95 // Sammelstellen fuer Referenzen
96 nP_RefTr = 32;
97 ppP_RefTr = new ScSingleRefData *[ nP_RefTr ];
98 for( nLauf = 0 ; nLauf < nP_RefTr ; nLauf++ )
99 ppP_RefTr[ nLauf ] = NULL;
100
101 nP_Ext = 32;
102 ppP_Ext = new EXTCONT*[ nP_Ext ];
103 memset( ppP_Ext, 0, sizeof( EXTCONT* ) * nP_Ext );
104
105 nP_Nlf = 16;
106 ppP_Nlf = new NLFCONT*[ nP_Nlf ];
107 memset( ppP_Nlf, 0, sizeof( NLFCONT* ) * nP_Nlf );
108
109 nP_Matrix = 16;
110 ppP_Matrix = new ScMatrix*[ nP_Matrix ];
111 memset( ppP_Matrix, 0, sizeof( ScMatrix* ) * nP_Matrix );
112
113 pScToken = new ScTokenArray;
114
115 Reset();
116 }
117
118
~TokenPool()119 TokenPool::~TokenPool()
120 {
121 sal_uInt16 n;
122
123 delete[] pP_Id;
124 delete[] pElement;
125 delete[] pType;
126 delete[] pSize;
127 delete[] pP_Dbl;
128 delete[] pP_Err;
129
130 for( n = 0 ; n < nP_RefTr ; n++ )
131 delete ppP_RefTr[ n ];
132 delete[] ppP_RefTr;
133
134 for( n = 0 ; n < nP_Str ; n++ )
135 delete ppP_Str[ n ];
136 delete[] ppP_Str;
137
138 for( n = 0 ; n < nP_Ext ; n++ )
139 delete ppP_Ext[ n ];
140 delete[] ppP_Ext;
141
142 for( n = 0 ; n < nP_Nlf ; n++ )
143 delete ppP_Nlf[ n ];
144 delete[] ppP_Nlf;
145
146 for( n = 0 ; n < nP_Matrix ; n++ )
147 {
148 if( ppP_Matrix[ n ] )
149 ppP_Matrix[ n ]->DecRef( );
150 }
151 delete[] ppP_Matrix;
152
153 delete pScToken;
154 }
155
156
157 /** Returns the new number of elements, or 0 if overflow. */
lcl_canGrow(sal_uInt16 nOld,sal_uInt16 nByMin=1)158 static sal_uInt16 lcl_canGrow( sal_uInt16 nOld, sal_uInt16 nByMin = 1 )
159 {
160 if (!nOld)
161 return nByMin ? nByMin : 1;
162 if (nOld == SAL_MAX_UINT16)
163 return 0;
164 sal_uInt32 nNew = ::std::max( static_cast<sal_uInt32>(nOld) * 2,
165 static_cast<sal_uInt32>(nOld) + nByMin);
166 if (nNew > SAL_MAX_UINT16)
167 nNew = SAL_MAX_UINT16;
168 if (nNew - nByMin < nOld)
169 nNew = 0;
170 return static_cast<sal_uInt16>(nNew);
171 }
172
173
GrowString(void)174 bool TokenPool::GrowString( void )
175 {
176 sal_uInt16 nP_StrNew = lcl_canGrow( nP_Str);
177 if (!nP_StrNew)
178 return false;
179
180 sal_uInt16 nL;
181
182 String** ppP_StrNew = new (::std::nothrow) String *[ nP_StrNew ];
183 if (!ppP_StrNew)
184 return false;
185
186 for( nL = 0 ; nL < nP_Str ; nL++ )
187 ppP_StrNew[ nL ] = ppP_Str[ nL ];
188 for( nL = nP_Str ; nL < nP_StrNew ; nL++ )
189 ppP_StrNew[ nL ] = NULL;
190
191 nP_Str = nP_StrNew;
192
193 delete[] ppP_Str;
194 ppP_Str = ppP_StrNew;
195 return true;
196 }
197
198
GrowDouble(void)199 bool TokenPool::GrowDouble( void )
200 {
201 sal_uInt16 nP_DblNew = lcl_canGrow( nP_Dbl);
202 if (!nP_DblNew)
203 return false;
204
205
206 double* pP_DblNew = new (::std::nothrow) double[ nP_DblNew ];
207 if (!pP_DblNew)
208 return false;
209
210 for( sal_uInt16 nL = 0 ; nL < nP_Dbl ; nL++ )
211 pP_DblNew[ nL ] = pP_Dbl[ nL ];
212
213 nP_Dbl = nP_DblNew;
214
215 delete[] pP_Dbl;
216 pP_Dbl = pP_DblNew;
217 return true;
218 }
219
220
221 /* TODO: in case we had FormulaTokenArray::AddError() */
222 #if 0
223 void TokenPool::GrowError( void )
224 {
225 sal_uInt16 nP_ErrNew = lcl_canGrow( nP_Err);
226 if (!nP_ErrNew)
227 return false;
228
229
230 sal_uInt16* pP_ErrNew = new (::std::nothrow) sal_uInt16[ nP_ErrNew ];
231 if (!pP_ErrNew)
232 return false;
233
234 for( sal_uInt16 nL = 0 ; nL < nP_Err ; nL++ )
235 pP_ErrNew[ nL ] = pP_Err[ nL ];
236
237 nP_Err = nP_ErrNew;
238
239 delete[] pP_Err;
240 pP_Err = pP_ErrNew;
241 return true;
242 }
243 #endif
244
245
GrowTripel(sal_uInt16 nByMin)246 bool TokenPool::GrowTripel( sal_uInt16 nByMin )
247 {
248 sal_uInt16 nP_RefTrNew = lcl_canGrow( nP_RefTr, nByMin);
249 if (!nP_RefTrNew)
250 return false;
251
252 sal_uInt16 nL;
253
254 ScSingleRefData** ppP_RefTrNew = new (::std::nothrow) ScSingleRefData *[ nP_RefTrNew ];
255 if (!ppP_RefTrNew)
256 return false;
257
258 for( nL = 0 ; nL < nP_RefTr ; nL++ )
259 ppP_RefTrNew[ nL ] = ppP_RefTr[ nL ];
260 for( nL = nP_RefTr ; nL < nP_RefTrNew ; nL++ )
261 ppP_RefTrNew[ nL ] = NULL;
262
263 nP_RefTr = nP_RefTrNew;
264
265 delete[] ppP_RefTr;
266 ppP_RefTr = ppP_RefTrNew;
267 return true;
268 }
269
270
GrowId(void)271 bool TokenPool::GrowId( void )
272 {
273 sal_uInt16 nP_IdNew = lcl_canGrow( nP_Id);
274 if (!nP_IdNew)
275 return false;
276
277
278 sal_uInt16* pP_IdNew = new (::std::nothrow) sal_uInt16[ nP_IdNew ];
279 if (!pP_IdNew)
280 return false;
281
282 for( sal_uInt16 nL = 0 ; nL < nP_Id ; nL++ )
283 pP_IdNew[ nL ] = pP_Id[ nL ];
284
285 nP_Id = nP_IdNew;
286
287 delete[] pP_Id;
288 pP_Id = pP_IdNew;
289 return true;
290 }
291
292
GrowElement(void)293 bool TokenPool::GrowElement( void )
294 {
295 sal_uInt16 nElementNew = lcl_canGrow( nElement);
296 if (!nElementNew)
297 return false;
298
299
300 sal_uInt16* pElementNew = new (::std::nothrow) sal_uInt16[ nElementNew ];
301 E_TYPE* pTypeNew = new (::std::nothrow) E_TYPE[ nElementNew ];
302 sal_uInt16* pSizeNew = new (::std::nothrow) sal_uInt16[ nElementNew ];
303 if (!pElementNew || !pTypeNew || !pSizeNew)
304 {
305 delete [] pElementNew;
306 delete [] pTypeNew;
307 delete [] pSizeNew;
308 return false;
309 }
310
311 for( sal_uInt16 nL = 0 ; nL < nElement ; nL++ )
312 {
313 pElementNew[ nL ] = pElement[ nL ];
314 pTypeNew[ nL ] = pType[ nL ];
315 pSizeNew[ nL ] = pSize[ nL ];
316 }
317
318 nElement = nElementNew;
319
320 delete[] pElement;
321 delete[] pType;
322 delete[] pSize;
323 pElement = pElementNew;
324 pType = pTypeNew;
325 pSize = pSizeNew;
326 return true;
327 }
328
329
GrowExt(void)330 bool TokenPool::GrowExt( void )
331 {
332 sal_uInt16 nNewSize = lcl_canGrow( nP_Ext);
333 if (!nNewSize)
334 return false;
335
336 EXTCONT** ppNew = new (::std::nothrow) EXTCONT*[ nNewSize ];
337 if (!ppNew)
338 return false;
339
340 memset( ppNew, 0, sizeof( EXTCONT* ) * nNewSize );
341 memcpy( ppNew, ppP_Ext, sizeof( EXTCONT* ) * nP_Ext );
342
343 delete[] ppP_Ext;
344 ppP_Ext = ppNew;
345 nP_Ext = nNewSize;
346 return true;
347 }
348
349
GrowNlf(void)350 bool TokenPool::GrowNlf( void )
351 {
352 sal_uInt16 nNewSize = lcl_canGrow( nP_Nlf);
353 if (!nNewSize)
354 return false;
355
356 NLFCONT** ppNew = new (::std::nothrow) NLFCONT*[ nNewSize ];
357 if (!ppNew)
358 return false;
359
360 memset( ppNew, 0, sizeof( NLFCONT* ) * nNewSize );
361 memcpy( ppNew, ppP_Nlf, sizeof( NLFCONT* ) * nP_Nlf );
362
363 delete[] ppP_Nlf;
364 ppP_Nlf = ppNew;
365 nP_Nlf = nNewSize;
366 return true;
367 }
368
369
GrowMatrix(void)370 bool TokenPool::GrowMatrix( void )
371 {
372 sal_uInt16 nNewSize = lcl_canGrow( nP_Matrix);
373 if (!nNewSize)
374 return false;
375
376 ScMatrix** ppNew = new (::std::nothrow) ScMatrix*[ nNewSize ];
377 if (!ppNew)
378 return false;
379
380 memset( ppNew, 0, sizeof( ScMatrix* ) * nNewSize );
381 memcpy( ppNew, ppP_Matrix, sizeof( ScMatrix* ) * nP_Matrix );
382
383 delete[] ppP_Matrix;
384 ppP_Matrix = ppNew;
385 nP_Matrix = nNewSize;
386 return true;
387 }
388
GetElement(const sal_uInt16 nId)389 bool TokenPool::GetElement( const sal_uInt16 nId )
390 {
391 DBG_ASSERT( nId < nElementAkt, "*TokenPool::GetElement(): Id too large!?" );
392 if (nId >= nElementAkt)
393 return false;
394
395 bool bRet = true;
396 if( pType[ nId ] == T_Id )
397 bRet = GetElementRek( nId );
398 else
399 {
400 switch( pType[ nId ] )
401 {
402 case T_Str:
403 {
404 sal_uInt16 n = pElement[ nId ];
405 String* p = ( n < nP_Str )? ppP_Str[ n ] : NULL;
406 if (p)
407 pScToken->AddString( *p );
408 else
409 bRet = false;
410 }
411 break;
412 case T_D:
413 {
414 sal_uInt16 n = pElement[ nId ];
415 if (n < nP_Dbl)
416 pScToken->AddDouble( pP_Dbl[ n ] );
417 else
418 bRet = false;
419 }
420 break;
421 case T_Err:
422 /* TODO: in case we had FormulaTokenArray::AddError() */
423 #if 0
424 {
425 sal_uInt16 n = pElement[ nId ];
426 if (n < nP_Err)
427 pScToken->AddError( pP_Err[ n ] );
428 else
429 bRet = false;
430 }
431 #endif
432 break;
433 case T_RefC:
434 {
435 sal_uInt16 n = pElement[ nId ];
436 ScSingleRefData* p = ( n < nP_RefTr )? ppP_RefTr[ n ] : NULL;
437 if (p)
438 pScToken->AddSingleReference( *p );
439 else
440 bRet = false;
441 }
442 break;
443 case T_RefA:
444 {
445 sal_uInt16 n = pElement[ nId ];
446 if (n < nP_RefTr && ppP_RefTr[ n ] && n+1 < nP_RefTr && ppP_RefTr[ n + 1 ])
447 {
448 ScComplexRefData aScComplexRefData;
449 aScComplexRefData.Ref1 = *ppP_RefTr[ n ];
450 aScComplexRefData.Ref2 = *ppP_RefTr[ n + 1 ];
451 pScToken->AddDoubleReference( aScComplexRefData );
452 }
453 else
454 bRet = false;
455 }
456 break;
457 case T_RN:
458 pScToken->AddName( pElement[ nId ] );
459 break;
460 case T_Ext:
461 {
462 sal_uInt16 n = pElement[ nId ];
463 EXTCONT* p = ( n < nP_Ext )? ppP_Ext[ n ] : NULL;
464
465 if( p )
466 {
467 if( p->eId == ocEuroConvert )
468 pScToken->AddOpCode( p->eId );
469 else
470 pScToken->AddExternal( p->aText, p->eId );
471 }
472 else
473 bRet = false;
474 }
475 break;
476 case T_Nlf:
477 {
478 sal_uInt16 n = pElement[ nId ];
479 NLFCONT* p = ( n < nP_Nlf )? ppP_Nlf[ n ] : NULL;
480
481 if( p )
482 pScToken->AddColRowName( p->aRef );
483 else
484 bRet = false;
485 }
486 break;
487 case T_Matrix:
488 {
489 sal_uInt16 n = pElement[ nId ];
490 ScMatrix* p = ( n < nP_Matrix )? ppP_Matrix[ n ] : NULL;
491
492 if( p )
493 pScToken->AddMatrix( p );
494 else
495 bRet = false;
496 }
497 break;
498 case T_ExtName:
499 {
500 sal_uInt16 n = pElement[nId];
501 if (n < maExtNames.size())
502 {
503 const ExtName& r = maExtNames[n];
504 pScToken->AddExternalName(r.mnFileId, r.maName);
505 }
506 else
507 bRet = false;
508 }
509 break;
510 case T_ExtRefC:
511 {
512 sal_uInt16 n = pElement[nId];
513 if (n < maExtCellRefs.size())
514 {
515 const ExtCellRef& r = maExtCellRefs[n];
516 pScToken->AddExternalSingleReference(r.mnFileId, r.maTabName, r.maRef);
517 }
518 else
519 bRet = false;
520 }
521 break;
522 case T_ExtRefA:
523 {
524 sal_uInt16 n = pElement[nId];
525 if (n < maExtAreaRefs.size())
526 {
527 const ExtAreaRef& r = maExtAreaRefs[n];
528 pScToken->AddExternalDoubleReference(r.mnFileId, r.maTabName, r.maRef);
529 }
530 else
531 bRet = false;
532 }
533 break;
534 default:
535 DBG_ERROR("-TokenPool::GetElement(): undefined state!?");
536 bRet = false;
537 }
538 }
539 return bRet;
540 }
541
542
GetElementRek(const sal_uInt16 nId)543 bool TokenPool::GetElementRek( const sal_uInt16 nId )
544 {
545 #ifdef DBG_UTIL
546 nRek++;
547 DBG_ASSERT( nRek <= nP_Id, "*TokenPool::GetElement(): recursion loops" );
548 #endif
549
550 if (nId >= nElementAkt)
551 {
552 DBG_ERRORFILE( "*TokenPool::GetElementRek(): nId >= nElementAkt" );
553 #ifdef DBG_UTIL
554 nRek--;
555 #endif
556 return false;
557 }
558
559 if (pType[ nId ] != T_Id)
560 {
561 DBG_ERRORFILE( "-TokenPool::GetElementRek(): pType[ nId ] != T_Id" );
562 #ifdef DBG_UTIL
563 nRek--;
564 #endif
565 return false;
566 }
567
568
569 bool bRet = true;
570 sal_uInt16 nAnz = pSize[ nId ];
571 sal_uInt16 nFirstId = pElement[ nId ];
572 if (nFirstId >= nP_Id)
573 {
574 DBG_ERRORFILE( "TokenPool::GetElementRek: nFirstId >= nP_Id");
575 nAnz = 0;
576 bRet = false;
577 }
578 sal_uInt16* pAkt = nAnz ? &pP_Id[ nFirstId ] : NULL;
579 if (nAnz > nP_Id - nFirstId)
580 {
581 DBG_ERRORFILE( "TokenPool::GetElementRek: nAnz > nP_Id - nFirstId");
582 nAnz = nP_Id - nFirstId;
583 bRet = false;
584 }
585 for( ; nAnz > 0 ; nAnz--, pAkt++ )
586 {
587 if( *pAkt < nScTokenOff )
588 {// Rekursion oder nicht?
589 if (*pAkt >= nElementAkt)
590 {
591 DBG_ERRORFILE( "TokenPool::GetElementRek: *pAkt >= nElementAkt");
592 bRet = false;
593 }
594 else
595 {
596 if (pType[ *pAkt ] == T_Id)
597 bRet = GetElementRek( *pAkt );
598 else
599 bRet = GetElement( *pAkt );
600 }
601 }
602 else // elementarer SC_Token
603 pScToken->AddOpCode( ( DefTokenId ) ( *pAkt - nScTokenOff ) );
604 }
605
606 #ifdef DBG_UTIL
607 nRek--;
608 #endif
609 return bRet;
610 }
611
612
operator >>(TokenId & rId)613 void TokenPool::operator >>( TokenId& rId )
614 {
615 rId = ( TokenId ) ( nElementAkt + 1 );
616
617 if( nElementAkt >= nElement )
618 if (!GrowElement())
619 return;
620
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
625
626 nElementAkt++; // Startwerte fuer naechste Folge
627 nP_IdLast = nP_IdAkt;
628 }
629
630
Store(const double & rDouble)631 const TokenId TokenPool::Store( const double& rDouble )
632 {
633 if( nElementAkt >= nElement )
634 if (!GrowElement())
635 return (const TokenId) nElementAkt+1;
636
637 if( nP_DblAkt >= nP_Dbl )
638 if (!GrowDouble())
639 return (const TokenId) nElementAkt+1;
640
641 pElement[ nElementAkt ] = nP_DblAkt; // Index in Double-Array
642 pType[ nElementAkt ] = T_D; // Typinfo Double eintragen
643
644 pP_Dbl[ nP_DblAkt ] = rDouble;
645
646 pSize[ nElementAkt ] = 1; // eigentlich Banane
647
648 nElementAkt++;
649 nP_DblAkt++;
650
651 return ( const TokenId ) nElementAkt; // Ausgabe von altem Wert + 1!
652 }
653
654
Store(const sal_uInt16 nIndex)655 const TokenId TokenPool::Store( const sal_uInt16 nIndex )
656 {
657 if( nElementAkt >= nElement )
658 if (!GrowElement())
659 return (const TokenId) nElementAkt+1;
660
661 pElement[ nElementAkt ] = nIndex; // Daten direkt im Index!
662 pType[ nElementAkt ] = T_RN; // Typinfo Range Name eintragen
663
664 nElementAkt++;
665 return ( const TokenId ) nElementAkt; // Ausgabe von altem Wert + 1!
666 }
667
668
Store(const String & rString)669 const TokenId TokenPool::Store( const String& rString )
670 {
671 // weitgehend nach Store( const sal_Char* ) kopiert, zur Vermeidung
672 // eines temporaeren Strings in "
673 if( nElementAkt >= nElement )
674 if (!GrowElement())
675 return (const TokenId) nElementAkt+1;
676
677 if( nP_StrAkt >= nP_Str )
678 if (!GrowString())
679 return (const TokenId) nElementAkt+1;
680
681 pElement[ nElementAkt ] = nP_StrAkt; // Index in String-Array
682 pType[ nElementAkt ] = T_Str; // Typinfo String eintragen
683
684 // String anlegen
685 if( !ppP_Str[ nP_StrAkt ] )
686 //...aber nur, wenn noch nicht vorhanden
687 ppP_Str[ nP_StrAkt ] = new (::std::nothrow) String( rString );
688 else
689 //...ansonsten nur kopieren
690 *ppP_Str[ nP_StrAkt ] = rString;
691
692 if (ppP_Str[ nP_StrAkt ])
693 {
694 DBG_ASSERT( sizeof( xub_StrLen ) <= 2, "*TokenPool::Store(): StrLen doesn't match!" );
695 pSize[ nElementAkt ] = ( sal_uInt16 ) ppP_Str[ nP_StrAkt ]->Len();
696 }
697
698 nElementAkt++;
699 nP_StrAkt++;
700
701 return ( const TokenId ) nElementAkt; // Ausgabe von altem Wert + 1!
702 }
703
704
Store(const ScSingleRefData & rTr)705 const TokenId TokenPool::Store( const ScSingleRefData& rTr )
706 {
707 if( nElementAkt >= nElement )
708 if (!GrowElement())
709 return (const TokenId) nElementAkt+1;
710
711 if( nP_RefTrAkt >= nP_RefTr )
712 if (!GrowTripel())
713 return (const TokenId) nElementAkt+1;
714
715 pElement[ nElementAkt ] = nP_RefTrAkt;
716 pType[ nElementAkt ] = T_RefC; // Typinfo Cell-Reff eintragen
717
718 if( !ppP_RefTr[ nP_RefTrAkt ] )
719 ppP_RefTr[ nP_RefTrAkt ] = new ScSingleRefData( rTr );
720 else
721 *ppP_RefTr[ nP_RefTrAkt ] = rTr;
722
723 nElementAkt++;
724 nP_RefTrAkt++;
725
726 return ( const TokenId ) nElementAkt; // Ausgabe von altem Wert + 1!
727 }
728
729
Store(const ScComplexRefData & rTr)730 const TokenId TokenPool::Store( const ScComplexRefData& rTr )
731 {
732 if( nElementAkt >= nElement )
733 if (!GrowElement())
734 return (const TokenId) nElementAkt+1;
735
736 if( nP_RefTrAkt + 1 >= nP_RefTr )
737 if (!GrowTripel( 2))
738 return (const TokenId) nElementAkt+1;
739
740 pElement[ nElementAkt ] = nP_RefTrAkt;
741 pType[ nElementAkt ] = T_RefA; // Typinfo Area-Reff eintragen
742
743 if( !ppP_RefTr[ nP_RefTrAkt ] )
744 ppP_RefTr[ nP_RefTrAkt ] = new ScSingleRefData( rTr.Ref1 );
745 else
746 *ppP_RefTr[ nP_RefTrAkt ] = rTr.Ref1;
747 nP_RefTrAkt++;
748
749 if( !ppP_RefTr[ nP_RefTrAkt ] )
750 ppP_RefTr[ nP_RefTrAkt ] = new ScSingleRefData( rTr.Ref2 );
751 else
752 *ppP_RefTr[ nP_RefTrAkt ] = rTr.Ref2;
753 nP_RefTrAkt++;
754
755 nElementAkt++;
756
757 return ( const TokenId ) nElementAkt; // Ausgabe von altem Wert + 1!
758 }
759
760
Store(const DefTokenId e,const String & r)761 const TokenId TokenPool::Store( const DefTokenId e, const String& r )
762 {
763 if( nElementAkt >= nElement )
764 if (!GrowElement())
765 return (const TokenId) nElementAkt+1;
766
767 if( nP_ExtAkt >= nP_Ext )
768 if (!GrowExt())
769 return (const TokenId) nElementAkt+1;
770
771 pElement[ nElementAkt ] = nP_ExtAkt;
772 pType[ nElementAkt ] = T_Ext; // Typinfo String eintragen
773
774 if( ppP_Ext[ nP_ExtAkt ] )
775 {
776 ppP_Ext[ nP_ExtAkt ]->eId = e;
777 ppP_Ext[ nP_ExtAkt ]->aText = r;
778 }
779 else
780 ppP_Ext[ nP_ExtAkt ] = new EXTCONT( e, r );
781
782 nElementAkt++;
783 nP_ExtAkt++;
784
785 return ( const TokenId ) nElementAkt; // Ausgabe von altem Wert + 1!
786 }
787
788
StoreNlf(const ScSingleRefData & rTr)789 const TokenId TokenPool::StoreNlf( const ScSingleRefData& rTr )
790 {
791 if( nElementAkt >= nElement )
792 if (!GrowElement())
793 return (const TokenId) nElementAkt+1;
794
795 if( nP_NlfAkt >= nP_Nlf )
796 if (!GrowNlf())
797 return (const TokenId) nElementAkt+1;
798
799 pElement[ nElementAkt ] = nP_NlfAkt;
800 pType[ nElementAkt ] = T_Nlf;
801
802 if( ppP_Nlf[ nP_NlfAkt ] )
803 {
804 ppP_Nlf[ nP_NlfAkt ]->aRef = rTr;
805 }
806 else
807 ppP_Nlf[ nP_NlfAkt ] = new NLFCONT( rTr );
808
809 nElementAkt++;
810 nP_NlfAkt++;
811
812 return ( const TokenId ) nElementAkt;
813 }
814
StoreMatrix()815 const TokenId TokenPool::StoreMatrix()
816 {
817 ScMatrix* pM;
818
819 if( nElementAkt >= nElement )
820 if (!GrowElement())
821 return (const TokenId) nElementAkt+1;
822
823 if( nP_MatrixAkt >= nP_Matrix )
824 if (!GrowMatrix())
825 return (const TokenId) nElementAkt+1;
826
827 pElement[ nElementAkt ] = nP_MatrixAkt;
828 pType[ nElementAkt ] = T_Matrix;
829
830 pM = new ScMatrix( 0, 0 );
831 pM->IncRef( );
832 ppP_Matrix[ nP_MatrixAkt ] = pM;
833
834 nElementAkt++;
835 nP_MatrixAkt++;
836
837 return ( const TokenId ) nElementAkt;
838 }
839
StoreExtName(sal_uInt16 nFileId,const String & rName)840 const TokenId TokenPool::StoreExtName( sal_uInt16 nFileId, const String& rName )
841 {
842 if ( nElementAkt >= nElement )
843 if (!GrowElement())
844 return (const TokenId) nElementAkt+1;
845
846 pElement[nElementAkt] = static_cast<sal_uInt16>(maExtNames.size());
847 pType[nElementAkt] = T_ExtName;
848
849 maExtNames.push_back(ExtName());
850 ExtName& r = maExtNames.back();
851 r.mnFileId = nFileId;
852 r.maName = rName;
853
854 ++nElementAkt;
855
856 return static_cast<const TokenId>(nElementAkt);
857 }
858
StoreExtRef(sal_uInt16 nFileId,const String & rTabName,const ScSingleRefData & rRef)859 const TokenId TokenPool::StoreExtRef( sal_uInt16 nFileId, const String& rTabName, const ScSingleRefData& rRef )
860 {
861 if ( nElementAkt >= nElement )
862 if (!GrowElement())
863 return (const TokenId) nElementAkt+1;
864
865 pElement[nElementAkt] = static_cast<sal_uInt16>(maExtCellRefs.size());
866 pType[nElementAkt] = T_ExtRefC;
867
868 maExtCellRefs.push_back(ExtCellRef());
869 ExtCellRef& r = maExtCellRefs.back();
870 r.mnFileId = nFileId;
871 r.maTabName = rTabName;
872 r.maRef = rRef;
873
874 ++nElementAkt;
875
876 return static_cast<const TokenId>(nElementAkt);
877 }
878
StoreExtRef(sal_uInt16 nFileId,const String & rTabName,const ScComplexRefData & rRef)879 const TokenId TokenPool::StoreExtRef( sal_uInt16 nFileId, const String& rTabName, const ScComplexRefData& rRef )
880 {
881 if ( nElementAkt >= nElement )
882 if (!GrowElement())
883 return (const TokenId) nElementAkt+1;
884
885 pElement[nElementAkt] = static_cast<sal_uInt16>(maExtAreaRefs.size());
886 pType[nElementAkt] = T_ExtRefA;
887
888 maExtAreaRefs.push_back(ExtAreaRef());
889 ExtAreaRef& r = maExtAreaRefs.back();
890 r.mnFileId = nFileId;
891 r.maTabName = rTabName;
892 r.maRef = rRef;
893
894 ++nElementAkt;
895
896 return static_cast<const TokenId>(nElementAkt);
897 }
898
Reset(void)899 void TokenPool::Reset( void )
900 {
901 nP_IdAkt = nP_IdLast = nElementAkt = nP_StrAkt = nP_DblAkt = nP_ErrAkt = nP_RefTrAkt = nP_ExtAkt = nP_NlfAkt = nP_MatrixAkt = 0;
902 maExtNames.clear();
903 maExtCellRefs.clear();
904 maExtAreaRefs.clear();
905 }
906
907
IsSingleOp(const TokenId & rId,const DefTokenId eId) const908 sal_Bool TokenPool::IsSingleOp( const TokenId& rId, const DefTokenId eId ) const
909 {
910 sal_uInt16 nId = (sal_uInt16) rId;
911 if( nId && nId <= nElementAkt )
912 {// existent?
913 nId--;
914 if( T_Id == pType[ nId ] )
915 {// Tokenfolge?
916 if( pSize[ nId ] == 1 )
917 {// GENAU 1 Token
918 sal_uInt16 nPid = pElement[ nId ];
919 if (nPid < nP_Id)
920 {
921 sal_uInt16 nSecId = pP_Id[ nPid ];
922 if( nSecId >= nScTokenOff )
923 {// Default-Token?
924 return ( DefTokenId ) ( nSecId - nScTokenOff ) == eId; // Gesuchter?
925 }
926 }
927 }
928 }
929 }
930
931 return sal_False;
932 }
933
934
GetExternal(const TokenId & rId) const935 const String* TokenPool::GetExternal( const TokenId& rId ) const
936 {
937 const String* p = NULL;
938 sal_uInt16 n = (sal_uInt16) rId;
939 if( n && n <= nElementAkt )
940 {
941 n--;
942 if( pType[ n ] == T_Ext )
943 {
944 sal_uInt16 nExt = pElement[ n ];
945 if ( nExt < nP_Ext && ppP_Ext[ nExt ] )
946 p = &ppP_Ext[ nExt ]->aText;
947 }
948 }
949
950 return p;
951 }
952
GetMatrix(unsigned int n) const953 ScMatrix* TokenPool::GetMatrix( unsigned int n ) const
954 {
955 if( n < nP_MatrixAkt )
956 return ppP_Matrix[ n ];
957 else
958 printf ("GETMATRIX %d >= %d\n", n, nP_MatrixAkt);
959 return NULL;
960 }
961
962