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