1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: token.hxx,v $
* $Revision: 1.15.32.3 $
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#ifndef SC_TOKEN_HXX
#define SC_TOKEN_HXX
#include <memory>
#include <vector>
#include "opcode.hxx"
#include "refdata.hxx"
#include "scmatrix.hxx"
#include "intruref.hxx"
#include <tools/mempool.hxx>
enum StackVarEnum
{
svByte,
svDouble,
svString,
svSingleRef,
svDoubleRef,
svMatrix,
svIndex,
svJump,
svExternal, // Byte + String
svFAP, // FormulaAutoPilot only, ever exported
svJumpMatrix, // 2003-07-02
svRefList, // ocUnion result
svEmptyCell, // Result is an empty cell, e.g. in LOOKUP()
svMatrixCell, // Result is a matrix with bells and
// whistles as needed for _the_ matrix
// formula result.
svHybridCell, // A temporary condition of a formula
// cell during import, having a double
// and/or string result and a formula
// string to be compiled.
svError, // error token
svMissing = 0x70, // 0 or ""
svSep, // separator, ocSep, ocOpen, ocClose
svUnknown // unknown StackType
};
#ifdef PRODUCT
// save memory since compilers tend to int an enum
typedef BYTE StackVar;
#else
// have enum names in debugger
typedef StackVarEnum StackVar;
#endif
class ScJumpMatrix;
class ScToken;
typedef ScSimpleIntrusiveReference< class ScToken > ScTokenRef;
typedef ScSimpleIntrusiveReference< const class ScToken > ScConstTokenRef;
typedef ::std::vector< ComplRefData > ScRefList;
class ScToken
{
private:
const StackVar eType; // type of data
mutable USHORT nRefCnt; // reference count
// not implemented, prevent usage
ScToken();
ScToken& operator=( const ScToken& );
protected:
static String aDummyString;
ScToken( StackVar eTypeP ) :
eType( eTypeP ), nRefCnt(0) {}
ScToken( const ScToken& r ) :
eType( r.eType ), nRefCnt(0) {}
public:
virtual ~ScToken();
inline void Delete() { delete this; }
inline const StackVar GetType() const { return eType; }
BOOL IsFunction() const; // pure functions, no operators
BOOL IsMatrixFunction() const; // if a function _always_ returns a Matrix
BYTE GetParamCount() const;
inline void IncRef() const { nRefCnt++; }
inline void DecRef() const
{
if (!--nRefCnt)
const_cast<ScToken*>(this)->Delete();
}
inline USHORT GetRef() const { return nRefCnt; }
/**
Dummy methods to avoid switches and casts where possible,
the real token classes have to overload the appropriate method[s].
The only methods valid anytime if not overloaded are:
- GetOpCode() since for a token type not needing an explicit OpCode set
the implicit OpCode is ocPush.
- GetByte() since this represents the count of parameters to a function
which of course is 0 on non-functions. ScByteToken and ScExternal do
overload it.
- HasForceArray() since also this is only used for operators and
functions and is 0 for other tokens.
Any other non-overloaded method pops up an assertion.
*/
virtual OpCode GetOpCode() const;
virtual BYTE GetByte() const;
virtual void SetByte( BYTE n );
virtual bool HasForceArray() const;
virtual void SetForceArray( bool b );
virtual double GetDouble() const;
virtual double& GetDoubleAsReference();
virtual const String& GetString() const;
virtual const SingleRefData& GetSingleRef() const;
virtual SingleRefData& GetSingleRef();
virtual const ComplRefData& GetDoubleRef() const;
virtual ComplRefData& GetDoubleRef();
virtual const SingleRefData& GetSingleRef2() const;
virtual SingleRefData& GetSingleRef2();
virtual void CalcAbsIfRel( const ScAddress& );
virtual void CalcRelFromAbs( const ScAddress& );
virtual const ScMatrix* GetMatrix() const;
virtual ScMatrix* GetMatrix();
virtual USHORT GetIndex() const;
virtual void SetIndex( USHORT n );
virtual short* GetJump() const;
virtual const String& GetExternal() const;
virtual ScToken* GetFAPOrigToken() const;
virtual ScJumpMatrix* GetJumpMatrix() const;
virtual const ScRefList* GetRefList() const;
virtual ScRefList* GetRefList();
virtual USHORT GetError() const;
virtual void SetError( USHORT );
ScToken* Clone() const;
virtual BOOL operator==( const ScToken& rToken ) const;
BOOL TextEqual( const ScToken& rToken ) const;
BOOL Is3DRef() const; // reference with 3D flag set
//UNUSED2008-05 // If token in RPN resulted from resolving a name and contains an absolute
//UNUSED2008-05 // reference. Token must be obtained through ScTokenArray::GetNextReferenceRPN()
//UNUSED2008-05 // or similar.
//UNUSED2008-05 BOOL IsRPNReferenceAbsName() const;
/** If rTok1 and rTok2 both are SingleRef or DoubleRef tokens, extend/merge
ranges as needed for ocRange.
@param rPos
The formula's position, used to calculate absolute positions from
relative references.
@param bReuseDoubleRef
If TRUE, a DoubleRef token is reused if passed as rTok1 or rTok2,
else a new DoubleRef token is created and returned.
@return
A reused or new'ed ScDoubleRefToken, or a NULL TokenRef if rTok1 or
rTok2 are not of sv(Single|Double)Ref
*/
static ScTokenRef ExtendRangeReference( ScToken & rTok1, ScToken & rTok2, const ScAddress & rPos, bool bReuseDoubleRef );
static size_t GetStrLenBytes( xub_StrLen nLen )
{ return nLen * sizeof(sal_Unicode); }
static size_t GetStrLenBytes( const String& rStr )
{ return GetStrLenBytes( rStr.Len() ); }
};
/** Tokens that need a different OpCode than ocPush are derived from this. */
class ScOpToken : public ScToken
{
private:
OpCode eOp;
public:
ScOpToken( OpCode e, StackVar v ) :
ScToken( v ), eOp( e ) {}
ScOpToken( const ScOpToken & r ) :
ScToken( r ), eOp( r.eOp ) {}
/** This is dirty and only the compiler should use it! */
inline void NewOpCode( OpCode e ) { eOp = e; }
virtual OpCode GetOpCode() const;
// No operator== to be overloaded, ScToken::operator== already checks the
// OpCode as well via GetOpCode().
};
class ScByteToken : public ScOpToken
{
private:
BYTE nByte;
bool bHasForceArray;
protected:
ScByteToken( OpCode e, BYTE n, StackVar v, bool b ) :
ScOpToken( e, v ), nByte( n ),
bHasForceArray( b ) {}
public:
ScByteToken( OpCode e, BYTE n, bool b ) :
ScOpToken( e, svByte ), nByte( n ),
bHasForceArray( b ) {}
ScByteToken( OpCode e, BYTE n ) :
ScOpToken( e, svByte ), nByte( n ),
bHasForceArray( false ) {}
ScByteToken( OpCode e ) :
ScOpToken( e, svByte ), nByte( 0 ),
bHasForceArray( false ) {}
ScByteToken( const ScByteToken& r ) :
ScOpToken( r ), nByte( r.nByte ),
bHasForceArray( r.bHasForceArray ) {}
virtual BYTE GetByte() const;
virtual void SetByte( BYTE n );
virtual bool HasForceArray() const;
virtual void SetForceArray( bool b );
virtual BOOL operator==( const ScToken& rToken ) const;
DECL_FIXEDMEMPOOL_NEWDEL( ScByteToken );
};
// A special token for the FormulaAutoPilot only. Keeps a reference pointer of
// the token of which it was created for comparison.
class ScFAPToken : public ScByteToken
{
private:
ScTokenRef pOrigToken;
public:
ScFAPToken( OpCode e, BYTE n, ScToken* p ) :
ScByteToken( e, n, svFAP, false ),
pOrigToken( p ) {}
ScFAPToken( const ScFAPToken& r ) :
ScByteToken( r ), pOrigToken( r.pOrigToken ) {}
virtual ScToken* GetFAPOrigToken() const;
virtual BOOL operator==( const ScToken& rToken ) const;
};
class ScDoubleToken : public ScToken
{
private:
double fDouble;
public:
ScDoubleToken( double f ) :
ScToken( svDouble ), fDouble( f ) {}
ScDoubleToken( const ScDoubleToken& r ) :
ScToken( r ), fDouble( r.fDouble ) {}
virtual double GetDouble() const;
virtual double& GetDoubleAsReference();
virtual BOOL operator==( const ScToken& rToken ) const;
DECL_FIXEDMEMPOOL_NEWDEL( ScDoubleToken );
};
class ScStringToken : public ScToken
{
private:
String aString;
public:
ScStringToken( const String& r ) :
ScToken( svString ), aString( r ) {}
ScStringToken( const ScStringToken& r ) :
ScToken( r ), aString( r.aString ) {}
virtual const String& GetString() const;
virtual BOOL operator==( const ScToken& rToken ) const;
DECL_FIXEDMEMPOOL_NEWDEL( ScStringToken );
};
/** Identical to ScStringToken, but with explicit OpCode instead of implicit
ocPush, and an optional BYTE for ocBad tokens. */
class ScStringOpToken : public ScByteToken
{
private:
String aString;
public:
ScStringOpToken( OpCode e, const String& r ) :
ScByteToken( e, 0, svString, false ), aString( r ) {}
ScStringOpToken( const ScStringOpToken& r ) :
ScByteToken( r ), aString( r.aString ) {}
virtual const String& GetString() const;
virtual BOOL operator==( const ScToken& rToken ) const;
};
class ScSingleRefToken : public ScToken
{
private:
SingleRefData aSingleRef;
public:
ScSingleRefToken( const SingleRefData& r ) :
ScToken( svSingleRef ), aSingleRef( r ) {}
ScSingleRefToken( const ScSingleRefToken& r ) :
ScToken( r ), aSingleRef( r.aSingleRef ) {}
virtual const SingleRefData& GetSingleRef() const;
virtual SingleRefData& GetSingleRef();
virtual void CalcAbsIfRel( const ScAddress& );
virtual void CalcRelFromAbs( const ScAddress& );
virtual BOOL operator==( const ScToken& rToken ) const;
DECL_FIXEDMEMPOOL_NEWDEL( ScSingleRefToken );
};
/** Identical to ScSingleRefToken, but with explicit OpCode instead of implicit
ocPush. */
class ScSingleRefOpToken : public ScOpToken
{
private:
SingleRefData aSingleRef;
public:
ScSingleRefOpToken( OpCode e, const SingleRefData& r ) :
ScOpToken( e, svSingleRef ), aSingleRef( r ) {}
ScSingleRefOpToken( const ScSingleRefOpToken& r ) :
ScOpToken( r ), aSingleRef( r.aSingleRef ) {}
virtual const SingleRefData& GetSingleRef() const;
virtual SingleRefData& GetSingleRef();
virtual void CalcAbsIfRel( const ScAddress& );
virtual void CalcRelFromAbs( const ScAddress& );
virtual BOOL operator==( const ScToken& rToken ) const;
};
class ScDoubleRefToken : public ScToken
{
private:
ComplRefData aDoubleRef;
public:
ScDoubleRefToken( const ComplRefData& r ) :
ScToken( svDoubleRef ), aDoubleRef( r ) {}
ScDoubleRefToken( const SingleRefData& r ) :
ScToken( svDoubleRef )
{
aDoubleRef.Ref1 = r;
aDoubleRef.Ref2 = r;
}
ScDoubleRefToken( const ScDoubleRefToken& r ) :
ScToken( r ), aDoubleRef( r.aDoubleRef ) {}
virtual const SingleRefData& GetSingleRef() const;
virtual SingleRefData& GetSingleRef();
virtual const ComplRefData& GetDoubleRef() const;
virtual ComplRefData& GetDoubleRef();
virtual const SingleRefData& GetSingleRef2() const;
virtual SingleRefData& GetSingleRef2();
virtual void CalcAbsIfRel( const ScAddress& );
virtual void CalcRelFromAbs( const ScAddress& );
virtual BOOL operator==( const ScToken& rToken ) const;
DECL_FIXEDMEMPOOL_NEWDEL( ScDoubleRefToken );
};
/** Identical to ScDoubleRefToken, but with explicit OpCode instead of implicit
ocPush. */
class ScDoubleRefOpToken : public ScOpToken
{
private:
ComplRefData aDoubleRef;
public:
ScDoubleRefOpToken( OpCode e, const ComplRefData& r ) :
ScOpToken( e, svDoubleRef ), aDoubleRef( r ) {}
ScDoubleRefOpToken( OpCode e, const SingleRefData& r ) :
ScOpToken( e, svDoubleRef )
{
aDoubleRef.Ref1 = r;
aDoubleRef.Ref2 = r;
}
ScDoubleRefOpToken( const ScDoubleRefOpToken& r ) :
ScOpToken( r ), aDoubleRef( r.aDoubleRef ) {}
virtual const SingleRefData& GetSingleRef() const;
virtual SingleRefData& GetSingleRef();
virtual const ComplRefData& GetDoubleRef() const;
virtual ComplRefData& GetDoubleRef();
virtual const SingleRefData& GetSingleRef2() const;
virtual SingleRefData& GetSingleRef2();
virtual void CalcAbsIfRel( const ScAddress& );
virtual void CalcRelFromAbs( const ScAddress& );
virtual BOOL operator==( const ScToken& rToken ) const;
};
class ScMatrixToken : public ScToken
{
private:
ScMatrixRef pMatrix;
public:
ScMatrixToken( ScMatrix* p ) :
ScToken( svMatrix ), pMatrix( p ) {}
ScMatrixToken( const ScMatrixToken& r ) :
ScToken( r ), pMatrix( r.pMatrix ) {}
virtual const ScMatrix* GetMatrix() const;
virtual ScMatrix* GetMatrix();
virtual BOOL operator==( const ScToken& rToken ) const;
};
class ScIndexToken : public ScOpToken
{
private:
USHORT nIndex;
public:
ScIndexToken( OpCode e, USHORT n ) :
ScOpToken( e, svIndex ), nIndex( n ) {}
ScIndexToken( const ScIndexToken& r ) :
ScOpToken( r ), nIndex( r.nIndex ) {}
virtual USHORT GetIndex() const;
virtual void SetIndex( USHORT n );
virtual BOOL operator==( const ScToken& rToken ) const;
};
class ScJumpToken : public ScOpToken
{
private:
short* pJump;
public:
ScJumpToken( OpCode e, short* p ) :
ScOpToken( e, svJump )
{
pJump = new short[ p[0] + 1 ];
memcpy( pJump, p, (p[0] + 1) * sizeof(short) );
}
ScJumpToken( const ScJumpToken& r ) :
ScOpToken( r )
{
pJump = new short[ r.pJump[0] + 1 ];
memcpy( pJump, r.pJump, (r.pJump[0] + 1) * sizeof(short) );
}
virtual ~ScJumpToken();
virtual short* GetJump() const;
virtual BOOL operator==( const ScToken& rToken ) const;
};
// Only created from within the interpreter, no conversion from ScRawToken,
// never added to ScTokenArray!
class ScJumpMatrixToken : public ScToken
{
private:
ScJumpMatrix* pJumpMatrix;
public:
ScJumpMatrixToken( ScJumpMatrix* p ) :
ScToken( svJumpMatrix ), pJumpMatrix( p ) {}
ScJumpMatrixToken( const ScJumpMatrixToken& r ) :
ScToken( r ), pJumpMatrix( r.pJumpMatrix ) {}
virtual ~ScJumpMatrixToken();
virtual ScJumpMatrix* GetJumpMatrix() const;
virtual BOOL operator==( const ScToken& rToken ) const;
};
// Only created from within the interpreter, no conversion from ScRawToken,
// never added to ScTokenArray!
class ScRefListToken : public ScToken
{
private:
ScRefList aRefList;
public:
ScRefListToken() :
ScToken( svRefList ) {}
ScRefListToken( const ScRefListToken & r ) :
ScToken( r ), aRefList( r.aRefList ) {}
virtual void CalcAbsIfRel( const ScAddress& );
virtual void CalcRelFromAbs( const ScAddress& );
virtual const ScRefList* GetRefList() const;
virtual ScRefList* GetRefList();
virtual BOOL operator==( const ScToken& rToken ) const;
};
class ScExternalToken : public ScOpToken
{
private:
String aExternal;
BYTE nByte;
public:
ScExternalToken( OpCode e, BYTE n, const String& r ) :
ScOpToken( e, svExternal ), aExternal( r ),
nByte( n ) {}
ScExternalToken( OpCode e, const String& r ) :
ScOpToken( e, svExternal ), aExternal( r ),
nByte( 0 ) {}
ScExternalToken( const ScExternalToken& r ) :
ScOpToken( r ), aExternal( r.aExternal ),
nByte( r.nByte ) {}
virtual const String& GetExternal() const;
virtual BYTE GetByte() const;
virtual void SetByte( BYTE n );
virtual BOOL operator==( const ScToken& rToken ) const;
};
class ScMissingToken : public ScOpToken
{
public:
ScMissingToken() :
ScOpToken( ocMissing, svMissing ) {}
ScMissingToken( const ScMissingToken& r ) :
ScOpToken( r ) {}
virtual double GetDouble() const;
virtual const String& GetString() const;
virtual BOOL operator==( const ScToken& rToken ) const;
};
class ScUnknownToken : public ScOpToken
{
public:
ScUnknownToken( OpCode e ) :
ScOpToken( e, svUnknown ) {}
ScUnknownToken( const ScUnknownToken& r ) :
ScOpToken( r ) {}
virtual BOOL operator==( const ScToken& rToken ) const;
};
class ScErrorToken : public ScToken
{
USHORT nError;
public:
ScErrorToken( USHORT nErr ) :
ScToken( svError ), nError( nErr) {}
ScErrorToken( const ScErrorToken& r ) :
ScToken( r ), nError( r.nError) {}
virtual USHORT GetError() const;
virtual void SetError( USHORT nErr );
virtual BOOL operator==( const ScToken& rToken ) const;
};
class ScEmptyCellToken : public ScToken
{
bool bInherited :1;
bool bDisplayedAsString :1;
public:
explicit ScEmptyCellToken( bool bInheritedP, bool bDisplayAsString ) :
ScToken( svEmptyCell ),
bInherited( bInheritedP ),
bDisplayedAsString( bDisplayAsString ) {}
ScEmptyCellToken( const ScEmptyCellToken& r ) :
ScToken( r ),
bInherited( r.bInherited ),
bDisplayedAsString( r.bDisplayedAsString ) {}
bool IsInherited() const { return bInherited; }
bool IsDisplayedAsString() const { return bDisplayedAsString; }
virtual double GetDouble() const;
virtual const String & GetString() const;
virtual BOOL operator==( const ScToken& rToken ) const;
};
/** Transports the result from the interpreter to the formula cell. */
class ScMatrixCellResultToken : public ScToken
{
// No non-const access implemented, silence down unxsols4 complaining about
// the public GetMatrix() hiding the one from ScToken.
virtual ScMatrix* GetMatrix();
protected:
ScConstMatrixRef xMatrix;
ScConstTokenRef xUpperLeft;
public:
ScMatrixCellResultToken( ScMatrix* pMat, ScToken* pUL ) :
ScToken( svMatrixCell ),
xMatrix( pMat), xUpperLeft( pUL) {}
ScMatrixCellResultToken( const ScMatrixCellResultToken& r ) :
ScToken( r ), xMatrix( r.xMatrix ),
xUpperLeft( r.xUpperLeft ) {}
virtual double GetDouble() const;
virtual const String & GetString() const;
virtual const ScMatrix* GetMatrix() const;
virtual BOOL operator==( const ScToken& rToken ) const;
StackVar GetUpperLeftType() const
{
return xUpperLeft ?
xUpperLeft->GetType() :
static_cast<StackVar>(svUnknown);
}
ScConstTokenRef GetUpperLeftToken() const { return xUpperLeft; }
void Assign( const ScMatrixCellResultToken & r )
{
xMatrix = r.xMatrix;
xUpperLeft = r.xUpperLeft;
}
};
/** Stores the matrix result at the formula cell, additionally the range the
matrix formula occupies. */
class ScMatrixFormulaCellToken : public ScMatrixCellResultToken
{
private:
SCROW nRows;
SCCOL nCols;
public:
ScMatrixFormulaCellToken( SCCOL nC, SCROW nR ) :
ScMatrixCellResultToken( NULL, NULL ),
nRows( nR ), nCols( nC ) {}
ScMatrixFormulaCellToken( const ScMatrixFormulaCellToken& r ) :
ScMatrixCellResultToken( r ),
nRows( r.nRows ), nCols( r.nCols )
{
// xUpperLeft is modifiable through
// SetUpperLeftDouble(), so clone it.
if (xUpperLeft)
xUpperLeft = xUpperLeft->Clone();
}
virtual BOOL operator==( const ScToken& rToken ) const;
void SetMatColsRows( SCCOL nC, SCROW nR )
{
nRows = nR;
nCols = nC;
}
void GetMatColsRows( SCCOL & nC, SCROW & nR ) const
{
nR = nRows;
nC = nCols;
}
SCCOL GetMatCols() const { return nCols; }
SCROW GetMatRows() const { return nRows; }
/** Assign matrix result, keep matrix formula
dimension. */
void Assign( const ScMatrixCellResultToken & r )
{
ScMatrixCellResultToken::Assign( r);
}
/** Assign any result, keep matrix formula
dimension. If token is of type
ScMatrixCellResultToken uses the
appropriate Assign() call, other tokens
are assigned to xUpperLeft and xMatrix will
be assigned NULL. */
void Assign( const ScToken & r );
/** Modify xUpperLeft if svDouble, or create
new ScDoubleToken if not set yet. Does
nothing if xUpperLeft is of different type! */
void SetUpperLeftDouble( double f);
/** Reset matrix and upper left, keep matrix
formula dimension. */
void ResetResult()
{
xMatrix = NULL;
xUpperLeft = NULL;
}
};
class ScHybridCellToken : public ScToken
{
private:
double fDouble;
String aString;
String aFormula;
public:
ScHybridCellToken( double f,
const String & rStr,
const String & rFormula ) :
ScToken( svHybridCell ),
fDouble( f ), aString( rStr ),
aFormula( rFormula ) {}
ScHybridCellToken( const ScHybridCellToken& r ) :
ScToken( r ), fDouble( r.fDouble),
aString( r.aString), aFormula( r.aFormula) {}
const String & GetFormula() const { return aFormula; }
virtual double GetDouble() const;
virtual const String & GetString() const;
virtual BOOL operator==( const ScToken& rToken ) const;
};
// Simplify argument passing to RefUpdate methods with ScSingleRefToken or
// ScDoubleRefToken
class SingleDoubleRefModifier
{
ComplRefData aDub;
SingleRefData* pS;
ComplRefData* pD;
// not implemented, prevent usage
SingleDoubleRefModifier( const SingleDoubleRefModifier& );
SingleDoubleRefModifier& operator=( const SingleDoubleRefModifier& );
public:
SingleDoubleRefModifier( ScToken& rT )
{
if ( rT.GetType() == svSingleRef )
{
pS = &rT.GetSingleRef();
aDub.Ref1 = aDub.Ref2 = *pS;
pD = &aDub;
}
else
{
pS = 0;
pD = &rT.GetDoubleRef();
}
}
SingleDoubleRefModifier( SingleRefData& rS )
{
pS = &rS;
aDub.Ref1 = aDub.Ref2 = *pS;
pD = &aDub;
}
~SingleDoubleRefModifier()
{
if ( pS )
*pS = (*pD).Ref1;
}
inline ComplRefData& Ref() { return *pD; }
};
class SingleDoubleRefProvider
{
public:
const SingleRefData& Ref1;
const SingleRefData& Ref2;
SingleDoubleRefProvider( const ScToken& r )
: Ref1( r.GetSingleRef() ),
Ref2( r.GetType() == svDoubleRef ?
r.GetDoubleRef().Ref2 : Ref1 )
{}
SingleDoubleRefProvider( const SingleRefData& r )
: Ref1( r ), Ref2( r )
{}
SingleDoubleRefProvider( const ComplRefData& r )
: Ref1( r.Ref1 ), Ref2( r.Ref2 )
{}
~SingleDoubleRefProvider()
{}
};
#endif
|