1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: jumpmatrix.hxx,v $
10 * $Revision: 1.6.148.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_JUMPMATRIX_HXX
32 #define SC_JUMPMATRIX_HXX
34 #include "formula/token.hxx"
35 #include "formula/errorcodes.hxx"
36 #include <tools/solar.h>
38 #include "scmatrix.hxx"
40 typedef ::std::vector
< formula::FormulaToken
*> ScTokenVec
;
42 struct ScJumpMatrixEntry
44 double fBool
; // 0:= false 1:= true also if no-path
45 // other values may contain error conditions like NAN and INF
46 short nStart
; // start of path (actually start-1, see formula::FormulaTokenIterator)
47 short nNext
; // next after path
48 // jump path exists if nStart != nNext, else no path
49 short nStop
; // optional stop of path (nPC < nStop)
51 void SetJump( double fBoolP
, short nStartP
, short nNextP
, short nStopP
)
58 void GetJump( double& rBool
, short& rStart
, short& rNext
, short& rStop
)
69 ScJumpMatrixEntry
* pJump
; // the jumps
70 ScMatrixRef pMat
; // the results
71 ScTokenVec
* pParams
; // parameter stack
80 // not implemented, prevent usage
81 ScJumpMatrix( const ScJumpMatrix
& );
82 ScJumpMatrix
& operator=( const ScJumpMatrix
& );
85 ScJumpMatrix( SCSIZE nColsP
, SCSIZE nRowsP
)
86 : pJump( new ScJumpMatrixEntry
[ nColsP
* nRowsP
] )
87 , pMat( new ScMatrix( nColsP
, nRowsP
) )
93 , nResMatCols( nColsP
)
94 , nResMatRows( nRowsP
)
97 // Initialize result matrix in case of
98 // a premature end of the interpreter
100 pMat
->FillDouble( CreateDoubleError(
101 NOTAVAILABLE
), 0, 0, nCols
-1,
103 /*! pJump not initialized */
109 for ( ScTokenVec::iterator i
=
110 pParams
->begin(); i
!=
111 pParams
->end(); ++i
)
119 void GetDimensions( SCSIZE
& rCols
, SCSIZE
& rRows
) const
124 void SetJump( SCSIZE nCol
, SCSIZE nRow
, double fBool
,
125 short nStart
, short nNext
,
126 short nStop
= SHRT_MAX
)
128 pJump
[ (ULONG
)nCol
* nRows
+ nRow
].
129 SetJump( fBool
, nStart
, nNext
, nStop
);
131 void GetJump( SCSIZE nCol
, SCSIZE nRow
, double& rBool
,
132 short& rStart
, short& rNext
,
135 if (nCols
== 1 && nRows
== 1)
140 else if (nCols
== 1 && nRow
< nRows
)
142 else if (nRows
== 1 && nCol
< nCols
)
144 else if (nCols
<= nCol
|| nRows
<= nRow
)
146 DBG_ERROR("ScJumpMatrix::GetJump: dimension error");
150 pJump
[ (ULONG
)nCol
* nRows
+ nRow
].
151 GetJump( rBool
, rStart
, rNext
, rStop
);
153 void SetAllJumps( double fBool
,
154 short nStart
, short nNext
,
155 short nStop
= SHRT_MAX
)
157 ULONG n
= (ULONG
)nCols
* nRows
;
158 for ( ULONG j
=0; j
<n
; ++j
)
160 pJump
[ j
].SetJump( fBool
, nStart
,
164 void SetJumpParameters( ScTokenVec
* p
)
166 const ScTokenVec
* GetJumpParameters() const { return pParams
; }
167 ScMatrix
* GetResultMatrix() const { return pMat
; }
168 void GetPos( SCSIZE
& rCol
, SCSIZE
& rRow
) const
173 bool Next( SCSIZE
& rCol
, SCSIZE
& rRow
)
178 nCurCol
= nCurRow
= 0;
182 if ( ++nCurRow
>= nResMatRows
)
188 GetPos( rCol
, rRow
);
189 return nCurCol
< nResMatCols
;
191 void GetResMatDimensions( SCSIZE
& rCols
, SCSIZE
& rRows
)
196 void SetNewResMat( SCSIZE nNewCols
, SCSIZE nNewRows
)
198 if ( nNewCols
> nResMatCols
|| nNewRows
> nResMatRows
)
200 pMat
= pMat
->CloneAndExtend( nNewCols
, nNewRows
);
201 if ( nResMatCols
< nNewCols
)
203 pMat
->FillDouble( CreateDoubleError(
204 NOTAVAILABLE
), nResMatCols
, 0, nNewCols
-1,
207 if ( nResMatRows
< nNewRows
)
209 pMat
->FillDouble( CreateDoubleError(
210 NOTAVAILABLE
), 0, nResMatRows
, nNewCols
-1,
213 if ( nRows
== 1 && nCurCol
!= 0 )
216 nCurRow
= nResMatRows
- 1;
218 nResMatCols
= nNewCols
;
219 nResMatRows
= nNewRows
;
224 #endif // SC_JUMPMATRIX_HXX