xref: /AOO41X/main/sc/inc/token.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef SC_TOKEN_HXX
29*cdf0e10cSrcweir #define SC_TOKEN_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <memory>
32*cdf0e10cSrcweir #include <vector>
33*cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "formula/opcode.hxx"
36*cdf0e10cSrcweir #include "refdata.hxx"
37*cdf0e10cSrcweir #include "scmatrix.hxx"
38*cdf0e10cSrcweir #include "formula/intruref.hxx"
39*cdf0e10cSrcweir #include <tools/mempool.hxx>
40*cdf0e10cSrcweir #include "scdllapi.h"
41*cdf0e10cSrcweir #include "formula/IFunctionDescription.hxx"
42*cdf0e10cSrcweir #include "formula/token.hxx"
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir class ScJumpMatrix;
46*cdf0e10cSrcweir class ScToken;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir typedef ::std::vector< ScComplexRefData > ScRefList;
49*cdf0e10cSrcweir typedef formula::SimpleIntrusiveReference< class ScToken > ScTokenRef;
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir /**
52*cdf0e10cSrcweir  * Another ref-counted token type using shared_ptr.  <b>Be extra careful
53*cdf0e10cSrcweir  * not to mix use of this smart pointer type with ScTokenRef</b>, since
54*cdf0e10cSrcweir  * mixing them might cause a premature object deletion because the same
55*cdf0e10cSrcweir  * object may be ref-counted by two different smart pointer wrappers.
56*cdf0e10cSrcweir  *
57*cdf0e10cSrcweir  * You have been warned.
58*cdf0e10cSrcweir  */
59*cdf0e10cSrcweir typedef ::boost::shared_ptr< ScToken > ScSharedTokenRef;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir class SC_DLLPUBLIC ScToken : public formula::FormulaToken
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir private:
64*cdf0e10cSrcweir                                 // not implemented, prevent usage
65*cdf0e10cSrcweir                                 ScToken();
66*cdf0e10cSrcweir             ScToken&            operator=( const ScToken& );
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir protected:
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir     ScToken( formula::StackVar eTypeP,OpCode e = ocPush ) : formula::FormulaToken(eTypeP,e) {}
71*cdf0e10cSrcweir     ScToken( const ScToken& r ): formula::FormulaToken(r) {}
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir public:
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir     virtual                     ~ScToken();
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir     /**
78*cdf0e10cSrcweir         Dummy methods to avoid switches and casts where possible,
79*cdf0e10cSrcweir         the real token classes have to overload the appropriate method[s].
80*cdf0e10cSrcweir         The only methods valid anytime if not overloaded are:
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir         - GetByte() since this represents the count of parameters to a function
83*cdf0e10cSrcweir           which of course is 0 on non-functions. formula::FormulaByteToken and ScExternal do
84*cdf0e10cSrcweir           overload it.
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir         - HasForceArray() since also this is only used for operators and
87*cdf0e10cSrcweir           functions and is 0 for other tokens.
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir         Any other non-overloaded method pops up an assertion.
90*cdf0e10cSrcweir      */
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir     virtual const ScSingleRefData&    GetSingleRef() const;
93*cdf0e10cSrcweir     virtual ScSingleRefData&      GetSingleRef();
94*cdf0e10cSrcweir     virtual const ScComplexRefData& GetDoubleRef() const;
95*cdf0e10cSrcweir     virtual ScComplexRefData&       GetDoubleRef();
96*cdf0e10cSrcweir     virtual const ScSingleRefData&    GetSingleRef2() const;
97*cdf0e10cSrcweir     virtual ScSingleRefData&      GetSingleRef2();
98*cdf0e10cSrcweir     virtual void                CalcAbsIfRel( const ScAddress& );
99*cdf0e10cSrcweir     virtual void                CalcRelFromAbs( const ScAddress& );
100*cdf0e10cSrcweir     virtual const ScMatrix*     GetMatrix() const;
101*cdf0e10cSrcweir     virtual ScMatrix*           GetMatrix();
102*cdf0e10cSrcweir     virtual ScJumpMatrix*       GetJumpMatrix() const;
103*cdf0e10cSrcweir     virtual const ScRefList*    GetRefList() const;
104*cdf0e10cSrcweir     virtual       ScRefList*    GetRefList();
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     virtual sal_Bool                TextEqual( const formula::FormulaToken& rToken ) const;
107*cdf0e10cSrcweir     virtual sal_Bool                Is3DRef() const;    // reference with 3D flag set
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     /** If rTok1 and rTok2 both are SingleRef or DoubleRef tokens, extend/merge
110*cdf0e10cSrcweir         ranges as needed for ocRange.
111*cdf0e10cSrcweir         @param rPos
112*cdf0e10cSrcweir             The formula's position, used to calculate absolute positions from
113*cdf0e10cSrcweir             relative references.
114*cdf0e10cSrcweir         @param bReuseDoubleRef
115*cdf0e10cSrcweir             If sal_True, a DoubleRef token is reused if passed as rTok1 or rTok2,
116*cdf0e10cSrcweir             else a new DoubleRef token is created and returned.
117*cdf0e10cSrcweir         @return
118*cdf0e10cSrcweir             A reused or new'ed ScDoubleRefToken, or a NULL TokenRef if rTok1 or
119*cdf0e10cSrcweir             rTok2 are not of sv(Single|Double)Ref
120*cdf0e10cSrcweir      */
121*cdf0e10cSrcweir     static  formula::FormulaTokenRef          ExtendRangeReference( formula::FormulaToken & rTok1, formula::FormulaToken & rTok2, const ScAddress & rPos, bool bReuseDoubleRef );
122*cdf0e10cSrcweir };
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir class ScSingleRefToken : public ScToken
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir private:
127*cdf0e10cSrcweir             ScSingleRefData       aSingleRef;
128*cdf0e10cSrcweir public:
129*cdf0e10cSrcweir                                 ScSingleRefToken( const ScSingleRefData& r, OpCode e = ocPush ) :
130*cdf0e10cSrcweir                                     ScToken( formula::svSingleRef, e ), aSingleRef( r ) {}
131*cdf0e10cSrcweir                                 ScSingleRefToken( const ScSingleRefToken& r ) :
132*cdf0e10cSrcweir                                     ScToken( r ), aSingleRef( r.aSingleRef ) {}
133*cdf0e10cSrcweir     virtual const ScSingleRefData&    GetSingleRef() const;
134*cdf0e10cSrcweir     virtual ScSingleRefData&      GetSingleRef();
135*cdf0e10cSrcweir     virtual void                CalcAbsIfRel( const ScAddress& );
136*cdf0e10cSrcweir     virtual void                CalcRelFromAbs( const ScAddress& );
137*cdf0e10cSrcweir     virtual sal_Bool                operator==( const formula::FormulaToken& rToken ) const;
138*cdf0e10cSrcweir     virtual FormulaToken*       Clone() const { return new ScSingleRefToken(*this); }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     DECL_FIXEDMEMPOOL_NEWDEL( ScSingleRefToken );
141*cdf0e10cSrcweir };
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir class ScDoubleRefToken : public ScToken
144*cdf0e10cSrcweir {
145*cdf0e10cSrcweir private:
146*cdf0e10cSrcweir             ScComplexRefData        aDoubleRef;
147*cdf0e10cSrcweir public:
148*cdf0e10cSrcweir                                 ScDoubleRefToken( const ScComplexRefData& r, OpCode e = ocPush  ) :
149*cdf0e10cSrcweir                                     ScToken( formula::svDoubleRef, e ), aDoubleRef( r ) {}
150*cdf0e10cSrcweir                                 ScDoubleRefToken( const ScSingleRefData& r, OpCode e = ocPush  ) :
151*cdf0e10cSrcweir                                     ScToken( formula::svDoubleRef, e )
152*cdf0e10cSrcweir                                 {
153*cdf0e10cSrcweir                                     aDoubleRef.Ref1 = r;
154*cdf0e10cSrcweir                                     aDoubleRef.Ref2 = r;
155*cdf0e10cSrcweir                                 }
156*cdf0e10cSrcweir                                 ScDoubleRefToken( const ScDoubleRefToken& r ) :
157*cdf0e10cSrcweir                                     ScToken( r ), aDoubleRef( r.aDoubleRef ) {}
158*cdf0e10cSrcweir     virtual const ScSingleRefData&    GetSingleRef() const;
159*cdf0e10cSrcweir     virtual ScSingleRefData&      GetSingleRef();
160*cdf0e10cSrcweir     virtual const ScComplexRefData& GetDoubleRef() const;
161*cdf0e10cSrcweir     virtual ScComplexRefData&       GetDoubleRef();
162*cdf0e10cSrcweir     virtual const ScSingleRefData&    GetSingleRef2() const;
163*cdf0e10cSrcweir     virtual ScSingleRefData&      GetSingleRef2();
164*cdf0e10cSrcweir     virtual void                CalcAbsIfRel( const ScAddress& );
165*cdf0e10cSrcweir     virtual void                CalcRelFromAbs( const ScAddress& );
166*cdf0e10cSrcweir     virtual sal_Bool                operator==( const formula::FormulaToken& rToken ) const;
167*cdf0e10cSrcweir     virtual FormulaToken*       Clone() const { return new ScDoubleRefToken(*this); }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir     DECL_FIXEDMEMPOOL_NEWDEL( ScDoubleRefToken );
170*cdf0e10cSrcweir };
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir class ScMatrixToken : public ScToken
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir private:
175*cdf0e10cSrcweir             ScMatrixRef         pMatrix;
176*cdf0e10cSrcweir public:
177*cdf0e10cSrcweir                                 ScMatrixToken( ScMatrix* p ) :
178*cdf0e10cSrcweir                                     ScToken( formula::svMatrix ), pMatrix( p ) {}
179*cdf0e10cSrcweir                                 ScMatrixToken( const ScMatrixToken& r ) :
180*cdf0e10cSrcweir                                     ScToken( r ), pMatrix( r.pMatrix ) {}
181*cdf0e10cSrcweir     virtual const ScMatrix*     GetMatrix() const;
182*cdf0e10cSrcweir     virtual ScMatrix*           GetMatrix();
183*cdf0e10cSrcweir     virtual sal_Bool                operator==( const formula::FormulaToken& rToken ) const;
184*cdf0e10cSrcweir     virtual FormulaToken*       Clone() const { return new ScMatrixToken(*this); }
185*cdf0e10cSrcweir };
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir class ScExternalSingleRefToken : public ScToken
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir private:
191*cdf0e10cSrcweir     sal_uInt16                  mnFileId;
192*cdf0e10cSrcweir     String                      maTabName;
193*cdf0e10cSrcweir     ScSingleRefData             maSingleRef;
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir                                 ScExternalSingleRefToken(); // disabled
196*cdf0e10cSrcweir public:
197*cdf0e10cSrcweir                                 ScExternalSingleRefToken( sal_uInt16 nFileId, const String& rTabName, const ScSingleRefData& r );
198*cdf0e10cSrcweir                                 ScExternalSingleRefToken( const ScExternalSingleRefToken& r );
199*cdf0e10cSrcweir     virtual                     ~ScExternalSingleRefToken();
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir     virtual sal_uInt16              GetIndex() const;
202*cdf0e10cSrcweir     virtual const String&           GetString() const;
203*cdf0e10cSrcweir     virtual const ScSingleRefData&  GetSingleRef() const;
204*cdf0e10cSrcweir     virtual ScSingleRefData&        GetSingleRef();
205*cdf0e10cSrcweir     virtual void                    CalcAbsIfRel( const ScAddress& );
206*cdf0e10cSrcweir     virtual void                    CalcRelFromAbs( const ScAddress& );
207*cdf0e10cSrcweir     virtual sal_Bool                operator==( const formula::FormulaToken& rToken ) const;
208*cdf0e10cSrcweir     virtual FormulaToken*           Clone() const { return new ScExternalSingleRefToken(*this); }
209*cdf0e10cSrcweir };
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir class ScExternalDoubleRefToken : public ScToken
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir private:
215*cdf0e10cSrcweir     sal_uInt16                  mnFileId;
216*cdf0e10cSrcweir     String                      maTabName;  // name of the first sheet
217*cdf0e10cSrcweir     ScComplexRefData            maDoubleRef;
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir                                 ScExternalDoubleRefToken(); // disabled
220*cdf0e10cSrcweir public:
221*cdf0e10cSrcweir                                 ScExternalDoubleRefToken( sal_uInt16 nFileId, const String& rTabName, const ScComplexRefData& r );
222*cdf0e10cSrcweir                                 ScExternalDoubleRefToken( const ScExternalDoubleRefToken& r );
223*cdf0e10cSrcweir     explicit                    ScExternalDoubleRefToken( const ScExternalSingleRefToken& r );
224*cdf0e10cSrcweir     virtual                     ~ScExternalDoubleRefToken();
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir     virtual sal_uInt16              GetIndex() const;
227*cdf0e10cSrcweir     virtual const String&           GetString() const;
228*cdf0e10cSrcweir     virtual const ScSingleRefData&  GetSingleRef() const;
229*cdf0e10cSrcweir     virtual ScSingleRefData&        GetSingleRef();
230*cdf0e10cSrcweir     virtual const ScSingleRefData&  GetSingleRef2() const;
231*cdf0e10cSrcweir     virtual ScSingleRefData&        GetSingleRef2();
232*cdf0e10cSrcweir     virtual const ScComplexRefData& GetDoubleRef() const;
233*cdf0e10cSrcweir     virtual ScComplexRefData&       GetDoubleRef();
234*cdf0e10cSrcweir     virtual void                    CalcAbsIfRel( const ScAddress& );
235*cdf0e10cSrcweir     virtual void                    CalcRelFromAbs( const ScAddress& );
236*cdf0e10cSrcweir     virtual sal_Bool                operator==( const formula::FormulaToken& rToken ) const;
237*cdf0e10cSrcweir     virtual FormulaToken*           Clone() const { return new ScExternalDoubleRefToken(*this); }
238*cdf0e10cSrcweir };
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir class ScExternalNameToken : public ScToken
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir private:
244*cdf0e10cSrcweir     sal_uInt16                  mnFileId;
245*cdf0e10cSrcweir     String                      maName;
246*cdf0e10cSrcweir private:
247*cdf0e10cSrcweir                                 ScExternalNameToken(); // disabled
248*cdf0e10cSrcweir public:
249*cdf0e10cSrcweir                                 ScExternalNameToken( sal_uInt16 nFileId, const String& rName );
250*cdf0e10cSrcweir                                 ScExternalNameToken( const ScExternalNameToken& r );
251*cdf0e10cSrcweir     virtual                     ~ScExternalNameToken();
252*cdf0e10cSrcweir     virtual sal_uInt16              GetIndex() const;
253*cdf0e10cSrcweir     virtual const String&       GetString() const;
254*cdf0e10cSrcweir     virtual sal_Bool                operator==( const formula::FormulaToken& rToken ) const;
255*cdf0e10cSrcweir     virtual FormulaToken*       Clone() const { return new ScExternalNameToken(*this); }
256*cdf0e10cSrcweir };
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir // Only created from within the interpreter, no conversion from ScRawToken,
260*cdf0e10cSrcweir // never added to ScTokenArray!
261*cdf0e10cSrcweir class ScJumpMatrixToken : public ScToken
262*cdf0e10cSrcweir {
263*cdf0e10cSrcweir private:
264*cdf0e10cSrcweir             ScJumpMatrix*       pJumpMatrix;
265*cdf0e10cSrcweir public:
266*cdf0e10cSrcweir                                 ScJumpMatrixToken( ScJumpMatrix* p ) :
267*cdf0e10cSrcweir                                     ScToken( formula::svJumpMatrix ), pJumpMatrix( p ) {}
268*cdf0e10cSrcweir                                 ScJumpMatrixToken( const ScJumpMatrixToken& r ) :
269*cdf0e10cSrcweir                                     ScToken( r ), pJumpMatrix( r.pJumpMatrix ) {}
270*cdf0e10cSrcweir     virtual                     ~ScJumpMatrixToken();
271*cdf0e10cSrcweir     virtual ScJumpMatrix*       GetJumpMatrix() const;
272*cdf0e10cSrcweir     virtual sal_Bool                operator==( const formula::FormulaToken& rToken ) const;
273*cdf0e10cSrcweir     virtual FormulaToken*       Clone() const { return new ScJumpMatrixToken(*this); }
274*cdf0e10cSrcweir };
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir // Only created from within the interpreter, no conversion from ScRawToken,
278*cdf0e10cSrcweir // never added to ScTokenArray!
279*cdf0e10cSrcweir class ScRefListToken : public ScToken
280*cdf0e10cSrcweir {
281*cdf0e10cSrcweir private:
282*cdf0e10cSrcweir             ScRefList           aRefList;
283*cdf0e10cSrcweir public:
284*cdf0e10cSrcweir                                 ScRefListToken() :
285*cdf0e10cSrcweir                                     ScToken( formula::svRefList ) {}
286*cdf0e10cSrcweir                                 ScRefListToken( const ScRefListToken & r ) :
287*cdf0e10cSrcweir                                     ScToken( r ), aRefList( r.aRefList ) {}
288*cdf0e10cSrcweir     virtual void                CalcAbsIfRel( const ScAddress& );
289*cdf0e10cSrcweir     virtual void                CalcRelFromAbs( const ScAddress& );
290*cdf0e10cSrcweir     virtual const ScRefList*    GetRefList() const;
291*cdf0e10cSrcweir     virtual       ScRefList*    GetRefList();
292*cdf0e10cSrcweir     virtual sal_Bool                operator==( const formula::FormulaToken& rToken ) const;
293*cdf0e10cSrcweir     virtual FormulaToken*       Clone() const { return new ScRefListToken(*this); }
294*cdf0e10cSrcweir };
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir class SC_DLLPUBLIC ScEmptyCellToken : public ScToken
298*cdf0e10cSrcweir {
299*cdf0e10cSrcweir             bool                bInherited          :1;
300*cdf0e10cSrcweir             bool                bDisplayedAsString  :1;
301*cdf0e10cSrcweir public:
302*cdf0e10cSrcweir     explicit                    ScEmptyCellToken( bool bInheritedP, bool bDisplayAsString ) :
303*cdf0e10cSrcweir                                     ScToken( formula::svEmptyCell ),
304*cdf0e10cSrcweir                                     bInherited( bInheritedP ),
305*cdf0e10cSrcweir                                     bDisplayedAsString( bDisplayAsString ) {}
306*cdf0e10cSrcweir                                 ScEmptyCellToken( const ScEmptyCellToken& r ) :
307*cdf0e10cSrcweir                                     ScToken( r ),
308*cdf0e10cSrcweir                                     bInherited( r.bInherited ),
309*cdf0e10cSrcweir                                     bDisplayedAsString( r.bDisplayedAsString ) {}
310*cdf0e10cSrcweir             bool                IsInherited() const { return bInherited; }
311*cdf0e10cSrcweir             bool                IsDisplayedAsString() const { return bDisplayedAsString; }
312*cdf0e10cSrcweir     virtual double              GetDouble() const;
313*cdf0e10cSrcweir     virtual const String &      GetString() const;
314*cdf0e10cSrcweir     virtual sal_Bool                operator==( const formula::FormulaToken& rToken ) const;
315*cdf0e10cSrcweir     virtual FormulaToken*       Clone() const { return new ScEmptyCellToken(*this); }
316*cdf0e10cSrcweir };
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir /**  Transports the result from the interpreter to the formula cell. */
320*cdf0e10cSrcweir class SC_DLLPUBLIC ScMatrixCellResultToken : public ScToken
321*cdf0e10cSrcweir {
322*cdf0e10cSrcweir     // No non-const access implemented, silence down unxsols4 complaining about
323*cdf0e10cSrcweir     // the public GetMatrix() hiding the one from ScToken.
324*cdf0e10cSrcweir     virtual ScMatrix*           GetMatrix();
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir protected:
327*cdf0e10cSrcweir             ScConstMatrixRef    xMatrix;
328*cdf0e10cSrcweir             formula::FormulaConstTokenRef     xUpperLeft;
329*cdf0e10cSrcweir public:
330*cdf0e10cSrcweir                                 ScMatrixCellResultToken( ScMatrix* pMat, formula::FormulaToken* pUL ) :
331*cdf0e10cSrcweir                                     ScToken( formula::svMatrixCell ),
332*cdf0e10cSrcweir                                     xMatrix( pMat), xUpperLeft( pUL) {}
333*cdf0e10cSrcweir                                 ScMatrixCellResultToken( const ScMatrixCellResultToken& r ) :
334*cdf0e10cSrcweir                                     ScToken( r ), xMatrix( r.xMatrix ),
335*cdf0e10cSrcweir                                     xUpperLeft( r.xUpperLeft ) {}
336*cdf0e10cSrcweir     virtual double              GetDouble() const;
337*cdf0e10cSrcweir     virtual const String &      GetString() const;
338*cdf0e10cSrcweir     virtual const ScMatrix*     GetMatrix() const;
339*cdf0e10cSrcweir     virtual sal_Bool                operator==( const formula::FormulaToken& rToken ) const;
340*cdf0e10cSrcweir     virtual FormulaToken*       Clone() const { return new ScMatrixCellResultToken(*this); }
341*cdf0e10cSrcweir     formula::StackVar           GetUpperLeftType() const
342*cdf0e10cSrcweir                                     {
343*cdf0e10cSrcweir                                         return xUpperLeft ?
344*cdf0e10cSrcweir                                             xUpperLeft->GetType() :
345*cdf0e10cSrcweir                                             static_cast<formula::StackVar>(formula::svUnknown);
346*cdf0e10cSrcweir                                     }
347*cdf0e10cSrcweir     inline formula::FormulaConstTokenRef     GetUpperLeftToken() const   { return xUpperLeft; }
348*cdf0e10cSrcweir             void                Assign( const ScMatrixCellResultToken & r )
349*cdf0e10cSrcweir                                     {
350*cdf0e10cSrcweir                                         xMatrix = r.xMatrix;
351*cdf0e10cSrcweir                                         xUpperLeft = r.xUpperLeft;
352*cdf0e10cSrcweir                                     }
353*cdf0e10cSrcweir };
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir /** Stores the matrix result at the formula cell, additionally the range the
357*cdf0e10cSrcweir     matrix formula occupies. */
358*cdf0e10cSrcweir class SC_DLLPUBLIC ScMatrixFormulaCellToken : public ScMatrixCellResultToken
359*cdf0e10cSrcweir {
360*cdf0e10cSrcweir private:
361*cdf0e10cSrcweir             SCROW               nRows;
362*cdf0e10cSrcweir             SCCOL               nCols;
363*cdf0e10cSrcweir public:
364*cdf0e10cSrcweir                                 ScMatrixFormulaCellToken( SCCOL nC, SCROW nR ) :
365*cdf0e10cSrcweir                                     ScMatrixCellResultToken( NULL, NULL ),
366*cdf0e10cSrcweir                                     nRows( nR ), nCols( nC ) {}
367*cdf0e10cSrcweir                                 ScMatrixFormulaCellToken( const ScMatrixFormulaCellToken& r ) :
368*cdf0e10cSrcweir                                     ScMatrixCellResultToken( r ),
369*cdf0e10cSrcweir                                     nRows( r.nRows ), nCols( r.nCols )
370*cdf0e10cSrcweir                                     {
371*cdf0e10cSrcweir                                         // xUpperLeft is modifiable through
372*cdf0e10cSrcweir                                         // SetUpperLeftDouble(), so clone it.
373*cdf0e10cSrcweir                                         if (xUpperLeft)
374*cdf0e10cSrcweir                                             xUpperLeft = xUpperLeft->Clone();
375*cdf0e10cSrcweir                                     }
376*cdf0e10cSrcweir     virtual sal_Bool                operator==( const formula::FormulaToken& rToken ) const;
377*cdf0e10cSrcweir     virtual FormulaToken*       Clone() const { return new ScMatrixFormulaCellToken(*this); }
378*cdf0e10cSrcweir             void                SetMatColsRows( SCCOL nC, SCROW nR )
379*cdf0e10cSrcweir                                     {
380*cdf0e10cSrcweir                                         nRows = nR;
381*cdf0e10cSrcweir                                         nCols = nC;
382*cdf0e10cSrcweir                                     }
383*cdf0e10cSrcweir             void                GetMatColsRows( SCCOL & nC, SCROW & nR ) const
384*cdf0e10cSrcweir                                     {
385*cdf0e10cSrcweir                                         nR = nRows;
386*cdf0e10cSrcweir                                         nC = nCols;
387*cdf0e10cSrcweir                                     }
388*cdf0e10cSrcweir             SCCOL               GetMatCols() const  { return nCols; }
389*cdf0e10cSrcweir             SCROW               GetMatRows() const  { return nRows; }
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir                                 /** Assign matrix result, keep matrix formula
392*cdf0e10cSrcweir                                     dimension. */
393*cdf0e10cSrcweir             void                Assign( const ScMatrixCellResultToken & r )
394*cdf0e10cSrcweir                                     {
395*cdf0e10cSrcweir                                         ScMatrixCellResultToken::Assign( r);
396*cdf0e10cSrcweir                                     }
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir                                 /** Assign any result, keep matrix formula
399*cdf0e10cSrcweir                                     dimension. If token is of type
400*cdf0e10cSrcweir                                     ScMatrixCellResultToken uses the
401*cdf0e10cSrcweir                                     appropriate Assign() call, other tokens
402*cdf0e10cSrcweir                                     are assigned to xUpperLeft and xMatrix will
403*cdf0e10cSrcweir                                     be assigned NULL. */
404*cdf0e10cSrcweir             void                Assign( const formula::FormulaToken & r );
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir                                 /** Modify xUpperLeft if formula::svDouble, or create
407*cdf0e10cSrcweir                                     new formula::FormulaDoubleToken if not set yet. Does
408*cdf0e10cSrcweir                                     nothing if xUpperLeft is of different type! */
409*cdf0e10cSrcweir             void                SetUpperLeftDouble( double f);
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir                                 /** Reset matrix and upper left, keep matrix
412*cdf0e10cSrcweir                                     formula dimension. */
413*cdf0e10cSrcweir             void                ResetResult()
414*cdf0e10cSrcweir                                     {
415*cdf0e10cSrcweir                                         xMatrix = NULL;
416*cdf0e10cSrcweir                                         xUpperLeft = NULL;
417*cdf0e10cSrcweir                                     }
418*cdf0e10cSrcweir };
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir class SC_DLLPUBLIC ScHybridCellToken : public ScToken
422*cdf0e10cSrcweir {
423*cdf0e10cSrcweir private:
424*cdf0e10cSrcweir             double              fDouble;
425*cdf0e10cSrcweir             String              aString;
426*cdf0e10cSrcweir             String              aFormula;
427*cdf0e10cSrcweir public:
428*cdf0e10cSrcweir                                 ScHybridCellToken( double f,
429*cdf0e10cSrcweir                                         const String & rStr,
430*cdf0e10cSrcweir                                         const String & rFormula ) :
431*cdf0e10cSrcweir                                     ScToken( formula::svHybridCell ),
432*cdf0e10cSrcweir                                     fDouble( f ), aString( rStr ),
433*cdf0e10cSrcweir                                     aFormula( rFormula ) {}
434*cdf0e10cSrcweir                                 ScHybridCellToken( const ScHybridCellToken& r ) :
435*cdf0e10cSrcweir                                     ScToken( r ), fDouble( r.fDouble),
436*cdf0e10cSrcweir                                     aString( r.aString), aFormula( r.aFormula) {}
437*cdf0e10cSrcweir             const String &      GetFormula() const  { return aFormula; }
438*cdf0e10cSrcweir     virtual double              GetDouble() const;
439*cdf0e10cSrcweir     virtual const String &      GetString() const;
440*cdf0e10cSrcweir     virtual sal_Bool                operator==( const formula::FormulaToken& rToken ) const;
441*cdf0e10cSrcweir     virtual FormulaToken*       Clone() const { return new ScHybridCellToken(*this); }
442*cdf0e10cSrcweir };
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir // Simplify argument passing to RefUpdate methods with ScSingleRefToken or
446*cdf0e10cSrcweir // ScDoubleRefToken
447*cdf0e10cSrcweir class SingleDoubleRefModifier
448*cdf0e10cSrcweir {
449*cdf0e10cSrcweir     ScComplexRefData    aDub;
450*cdf0e10cSrcweir     ScSingleRefData*  pS;
451*cdf0e10cSrcweir     ScComplexRefData*   pD;
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir                 // not implemented, prevent usage
454*cdf0e10cSrcweir                 SingleDoubleRefModifier( const SingleDoubleRefModifier& );
455*cdf0e10cSrcweir         SingleDoubleRefModifier& operator=( const SingleDoubleRefModifier& );
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir public:
458*cdf0e10cSrcweir                 SingleDoubleRefModifier( ScToken& rT )
459*cdf0e10cSrcweir                     {
460*cdf0e10cSrcweir                         if ( rT.GetType() == formula::svSingleRef )
461*cdf0e10cSrcweir                         {
462*cdf0e10cSrcweir                             pS = &rT.GetSingleRef();
463*cdf0e10cSrcweir                             aDub.Ref1 = aDub.Ref2 = *pS;
464*cdf0e10cSrcweir                             pD = &aDub;
465*cdf0e10cSrcweir                         }
466*cdf0e10cSrcweir                         else
467*cdf0e10cSrcweir                         {
468*cdf0e10cSrcweir                             pS = 0;
469*cdf0e10cSrcweir                             pD = &rT.GetDoubleRef();
470*cdf0e10cSrcweir                         }
471*cdf0e10cSrcweir                     }
472*cdf0e10cSrcweir                 SingleDoubleRefModifier( ScSingleRefData& rS )
473*cdf0e10cSrcweir                     {
474*cdf0e10cSrcweir                         pS = &rS;
475*cdf0e10cSrcweir                         aDub.Ref1 = aDub.Ref2 = *pS;
476*cdf0e10cSrcweir                         pD = &aDub;
477*cdf0e10cSrcweir                     }
478*cdf0e10cSrcweir                 ~SingleDoubleRefModifier()
479*cdf0e10cSrcweir                     {
480*cdf0e10cSrcweir                         if ( pS )
481*cdf0e10cSrcweir                             *pS = (*pD).Ref1;
482*cdf0e10cSrcweir                     }
483*cdf0e10cSrcweir     inline  ScComplexRefData& Ref() { return *pD; }
484*cdf0e10cSrcweir };
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir class SingleDoubleRefProvider
487*cdf0e10cSrcweir {
488*cdf0e10cSrcweir public:
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir     const ScSingleRefData&    Ref1;
491*cdf0e10cSrcweir     const ScSingleRefData&    Ref2;
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir                 SingleDoubleRefProvider( const ScToken& r )
494*cdf0e10cSrcweir                         : Ref1( r.GetSingleRef() ),
495*cdf0e10cSrcweir                         Ref2( r.GetType() == formula::svDoubleRef ?
496*cdf0e10cSrcweir                         r.GetDoubleRef().Ref2 : Ref1 )
497*cdf0e10cSrcweir                     {}
498*cdf0e10cSrcweir                 SingleDoubleRefProvider( const ScSingleRefData& r )
499*cdf0e10cSrcweir                         : Ref1( r ), Ref2( r )
500*cdf0e10cSrcweir                     {}
501*cdf0e10cSrcweir                 SingleDoubleRefProvider( const ScComplexRefData& r )
502*cdf0e10cSrcweir                         : Ref1( r.Ref1 ), Ref2( r.Ref2 )
503*cdf0e10cSrcweir                     {}
504*cdf0e10cSrcweir                 ~SingleDoubleRefProvider()
505*cdf0e10cSrcweir                     {}
506*cdf0e10cSrcweir };
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir #endif
509