xref: /AOO41X/main/sc/inc/scmatrix.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_MATRIX_HXX
29*cdf0e10cSrcweir #define SC_MATRIX_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "global.hxx"
32*cdf0e10cSrcweir #include "formula/intruref.hxx"
33*cdf0e10cSrcweir #include "formula/errorcodes.hxx"
34*cdf0e10cSrcweir #include <tools/string.hxx>
35*cdf0e10cSrcweir #include "scdllapi.h"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir class SvStream;
38*cdf0e10cSrcweir class ScInterpreter;
39*cdf0e10cSrcweir class SvNumberFormatter;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir typedef sal_uInt8 ScMatValType;
42*cdf0e10cSrcweir const ScMatValType SC_MATVAL_VALUE     = 0x00;
43*cdf0e10cSrcweir const ScMatValType SC_MATVAL_BOOLEAN   = 0x01;
44*cdf0e10cSrcweir const ScMatValType SC_MATVAL_STRING    = 0x02;
45*cdf0e10cSrcweir const ScMatValType SC_MATVAL_EMPTY     = SC_MATVAL_STRING | 0x04; // STRING plus flag
46*cdf0e10cSrcweir const ScMatValType SC_MATVAL_EMPTYPATH = SC_MATVAL_EMPTY | 0x08;  // EMPTY plus flag
47*cdf0e10cSrcweir const ScMatValType SC_MATVAL_NONVALUE  = SC_MATVAL_EMPTYPATH;     // mask of all non-value bits
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir union ScMatrixValue
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir     double fVal;
52*cdf0e10cSrcweir     String* pS;
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir     /// Only valid if ScMatrix methods indicate so!
55*cdf0e10cSrcweir     const String& GetString() const     { return pS ? *pS : EMPTY_STRING; }
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     /// Only valid if ScMatrix methods indicate that this is no string!
58*cdf0e10cSrcweir     sal_uInt16 GetError() const         { return GetDoubleErrorValue( fVal); }
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir     /// Only valid if ScMatrix methods indicate that this is a boolean
61*cdf0e10cSrcweir     bool GetBoolean() const         { return fVal != 0.; }
62*cdf0e10cSrcweir };
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir /** Matrix representation of double values and strings.
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir     @ATTENTION: optimized for speed and double values.
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir     <p> Matrix elements are NOT initialized after construction!
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir     <p> All methods using an SCSIZE nIndex parameter and all Is...() methods do
71*cdf0e10cSrcweir     NOT check the range for validity! However, the Put...() and Get...()
72*cdf0e10cSrcweir     methods using nCol/nRow parameters do check the range.
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir     <p> Methods using nCol/nRow parameters do replicate a single row vector if
75*cdf0e10cSrcweir     nRow &gt; 0 and nCol &lt; nColCount, respectively a column vector if nCol
76*cdf0e10cSrcweir     &gt; 0 and nRow &lt; nRowCount.
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir     <p> GetString( SCSIZE nIndex ) does not check if there really is a string,
79*cdf0e10cSrcweir     do this with IsString() first. GetString( SCSIZE nC, SCSIZE nR ) does check
80*cdf0e10cSrcweir     it and returns and empty string if there is no string. Both GetDouble()
81*cdf0e10cSrcweir     methods don't check for a string, do this with IsNumeric() or IsString() or
82*cdf0e10cSrcweir     IsValue() first.
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir     <p> The GetString( SvNumberFormatter&, ...) methods return the matrix
85*cdf0e10cSrcweir     element's string if one is present, otherwise the numerical value is
86*cdf0e10cSrcweir     formatted as a string, or in case of an error the error string is returned.
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     <p> PutDouble() does not reset an eventual string! Use
89*cdf0e10cSrcweir     PutDoubleAndResetString() if that is wanted. Also the FillDouble...()
90*cdf0e10cSrcweir     methods don't reset strings. As a consequence memory leaks may occur if
91*cdf0e10cSrcweir     used wrong.
92*cdf0e10cSrcweir  */
93*cdf0e10cSrcweir class SC_DLLPUBLIC ScMatrix
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir     ScMatrixValue*  pMat;
96*cdf0e10cSrcweir     ScMatValType*   mnValType;
97*cdf0e10cSrcweir     sal_uLong           mnNonValue; // how many strings and empties
98*cdf0e10cSrcweir     ScInterpreter*  pErrorInterpreter;
99*cdf0e10cSrcweir     mutable sal_uLong   nRefCnt;    // reference count
100*cdf0e10cSrcweir     SCSIZE          nColCount;
101*cdf0e10cSrcweir     SCSIZE          nRowCount;
102*cdf0e10cSrcweir     bool            mbCloneIfConst;     // Whether the matrix is cloned with a CloneIfConst() call.
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     void ResetIsString();
105*cdf0e10cSrcweir     void DeleteIsString();
106*cdf0e10cSrcweir     void CreateMatrix( SCSIZE nC, SCSIZE nR);
107*cdf0e10cSrcweir     void Clear();
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     // pStr may be NULL, bFlag MUST NOT be 0
110*cdf0e10cSrcweir     void PutStringEntry( const String* pStr, sal_uInt8 bFlag, SCSIZE nIndex );
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     // only delete via Delete()
113*cdf0e10cSrcweir     ~ScMatrix();
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     // not implemented, prevent usage
116*cdf0e10cSrcweir     ScMatrix( const ScMatrix& );
117*cdf0e10cSrcweir     ScMatrix& operator=( const ScMatrix&);
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir     void SetErrorAtInterpreter( sal_uInt16 nError) const;
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir public:
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir     /// The maximum number of elements a matrix may have at runtime.
124*cdf0e10cSrcweir     inline static size_t GetElementsMax()
125*cdf0e10cSrcweir     {
126*cdf0e10cSrcweir         // Roughly 125MB in total, divided by 8+1 per element => 14M elements.
127*cdf0e10cSrcweir         const size_t nMemMax = 0x08000000 / (sizeof(ScMatrixValue) + sizeof(ScMatValType));
128*cdf0e10cSrcweir         // With MAXROWCOUNT==65536 and 128 columns => 8M elements ~72MB.
129*cdf0e10cSrcweir         const size_t nArbitraryLimit = (size_t)MAXROWCOUNT * 128;
130*cdf0e10cSrcweir         // Stuffed with a million rows would limit this to 14 columns.
131*cdf0e10cSrcweir         return nMemMax < nArbitraryLimit ? nMemMax : nArbitraryLimit;
132*cdf0e10cSrcweir     }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir     /// Value or boolean.
135*cdf0e10cSrcweir     inline static bool IsValueType( ScMatValType nType )
136*cdf0e10cSrcweir     {
137*cdf0e10cSrcweir         return nType <= SC_MATVAL_BOOLEAN;
138*cdf0e10cSrcweir     }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     /// Boolean.
141*cdf0e10cSrcweir     inline static bool IsBooleanType( ScMatValType nType )
142*cdf0e10cSrcweir     {
143*cdf0e10cSrcweir         return nType == SC_MATVAL_BOOLEAN;
144*cdf0e10cSrcweir     }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir     /// String, empty or empty path, but not value nor boolean.
147*cdf0e10cSrcweir     inline static bool IsNonValueType( ScMatValType nType )
148*cdf0e10cSrcweir     {
149*cdf0e10cSrcweir         return (nType & SC_MATVAL_NONVALUE) != 0;
150*cdf0e10cSrcweir     }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     /** String, but not empty or empty path or any other type.
153*cdf0e10cSrcweir         Not named IsStringType to prevent confusion because previously
154*cdf0e10cSrcweir         IsNonValueType was named IsStringType. */
155*cdf0e10cSrcweir     inline static bool IsRealStringType( ScMatValType nType )
156*cdf0e10cSrcweir     {
157*cdf0e10cSrcweir         return (nType & SC_MATVAL_NONVALUE) == SC_MATVAL_STRING;
158*cdf0e10cSrcweir     }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     /// Empty, but not empty path or any other type.
161*cdf0e10cSrcweir     inline static bool IsEmptyType( ScMatValType nType )
162*cdf0e10cSrcweir     {
163*cdf0e10cSrcweir         return (nType & SC_MATVAL_NONVALUE) == SC_MATVAL_EMPTY;
164*cdf0e10cSrcweir     }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     /// Empty path, but not empty or any other type.
167*cdf0e10cSrcweir     inline static bool IsEmptyPathType( ScMatValType nType )
168*cdf0e10cSrcweir     {
169*cdf0e10cSrcweir         return (nType & SC_MATVAL_NONVALUE) == SC_MATVAL_EMPTYPATH;
170*cdf0e10cSrcweir     }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     /** If nC*nR results in more than GetElementsMax() entries, a 1x1 matrix is
173*cdf0e10cSrcweir         created instead and a double error value (errStackOverflow) is set.
174*cdf0e10cSrcweir         Compare nC and nR with a GetDimensions() call to check. */
175*cdf0e10cSrcweir     ScMatrix( SCSIZE nC, SCSIZE nR) : nRefCnt(0), mbCloneIfConst(true) { CreateMatrix( nC, nR); }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     /** Clone the matrix. */
178*cdf0e10cSrcweir     ScMatrix* Clone() const;
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     /** Clone the matrix if mbCloneIfConst (immutable) is set, otherwise
181*cdf0e10cSrcweir         return _this_ matrix, to be assigned to a ScMatrixRef. */
182*cdf0e10cSrcweir     ScMatrix* CloneIfConst();
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     /** Set the matrix to (im)mutable for CloneIfConst(), only the interpreter
185*cdf0e10cSrcweir         should do this and know the consequences. */
186*cdf0e10cSrcweir     inline void SetImmutable( bool bVal ) { mbCloneIfConst = bVal; }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir     /**
189*cdf0e10cSrcweir      * Resize the matrix to specified new dimension.  Note that this operation
190*cdf0e10cSrcweir      * clears all stored values.
191*cdf0e10cSrcweir      */
192*cdf0e10cSrcweir     void Resize( SCSIZE nC, SCSIZE nR);
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     /** Clone the matrix and extend it to the new size. nNewCols and nNewRows
195*cdf0e10cSrcweir         MUST be at least of the size of the original matrix. */
196*cdf0e10cSrcweir     ScMatrix* CloneAndExtend( SCSIZE nNewCols, SCSIZE nNewRows ) const;
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir     /// Disable refcounting forever, may only be deleted via Delete() afterwards.
199*cdf0e10cSrcweir     inline  void    SetEternalRef()         { nRefCnt = ULONG_MAX; }
200*cdf0e10cSrcweir     inline  bool    IsEternalRef() const    { return nRefCnt == ULONG_MAX; }
201*cdf0e10cSrcweir     inline  void    IncRef() const
202*cdf0e10cSrcweir     {
203*cdf0e10cSrcweir         if ( !IsEternalRef() )
204*cdf0e10cSrcweir             ++nRefCnt;
205*cdf0e10cSrcweir     }
206*cdf0e10cSrcweir     inline  void    DecRef() const
207*cdf0e10cSrcweir     {
208*cdf0e10cSrcweir         if ( nRefCnt > 0 && !IsEternalRef() )
209*cdf0e10cSrcweir             if ( --nRefCnt == 0 )
210*cdf0e10cSrcweir                 delete this;
211*cdf0e10cSrcweir     }
212*cdf0e10cSrcweir     inline  void    Delete()
213*cdf0e10cSrcweir     {
214*cdf0e10cSrcweir         if ( nRefCnt == 0 || IsEternalRef() )
215*cdf0e10cSrcweir             delete this;
216*cdf0e10cSrcweir         else
217*cdf0e10cSrcweir             --nRefCnt;
218*cdf0e10cSrcweir     }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir     void SetErrorInterpreter( ScInterpreter* p)
221*cdf0e10cSrcweir         { pErrorInterpreter = p; }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir     ScMatrix( SvStream& rStream);
224*cdf0e10cSrcweir     void Store( SvStream& rStream) const;
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir     void GetDimensions( SCSIZE& rC, SCSIZE& rR) const
227*cdf0e10cSrcweir         { rC = nColCount; rR = nRowCount; };
228*cdf0e10cSrcweir     SCSIZE GetElementCount() const
229*cdf0e10cSrcweir         { return nColCount * nRowCount; }
230*cdf0e10cSrcweir     inline bool ValidColRow( SCSIZE nC, SCSIZE nR) const
231*cdf0e10cSrcweir         { return nC < nColCount && nR < nRowCount; }
232*cdf0e10cSrcweir     inline SCSIZE CalcOffset( SCSIZE nC, SCSIZE nR) const
233*cdf0e10cSrcweir         { return nC * nRowCount + nR; }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir     /** For a row vector or column vector, if the position does not point into
236*cdf0e10cSrcweir         the vector but is a valid column or row offset it is adapted such that
237*cdf0e10cSrcweir         it points to an element to be replicated, same column row 0 for a row
238*cdf0e10cSrcweir         vector, same row column 0 for a column vector. Else, for a 2D matrix,
239*cdf0e10cSrcweir         returns false.
240*cdf0e10cSrcweir      */
241*cdf0e10cSrcweir     inline bool ValidColRowReplicated( SCSIZE & rC, SCSIZE & rR ) const
242*cdf0e10cSrcweir     {
243*cdf0e10cSrcweir         if (nColCount == 1 && nRowCount == 1)
244*cdf0e10cSrcweir         {
245*cdf0e10cSrcweir             rC = 0;
246*cdf0e10cSrcweir             rR = 0;
247*cdf0e10cSrcweir             return true;
248*cdf0e10cSrcweir         }
249*cdf0e10cSrcweir         else if (nColCount == 1 && rR < nRowCount)
250*cdf0e10cSrcweir         {
251*cdf0e10cSrcweir             rC = 0;
252*cdf0e10cSrcweir             return true;
253*cdf0e10cSrcweir         }
254*cdf0e10cSrcweir         else if (nRowCount == 1 && rC < nColCount)
255*cdf0e10cSrcweir         {
256*cdf0e10cSrcweir             rR = 0;
257*cdf0e10cSrcweir             return true;
258*cdf0e10cSrcweir         }
259*cdf0e10cSrcweir         return false;
260*cdf0e10cSrcweir     }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir     /** Checks if the matrix position is within the matrix. If it is not, for a
263*cdf0e10cSrcweir         row vector or column vector the position is adapted such that it points
264*cdf0e10cSrcweir         to an element to be replicated, same column row 0 for a row vector,
265*cdf0e10cSrcweir         same row column 0 for a column vector. Else, for a 2D matrix and
266*cdf0e10cSrcweir         position not within matrix, returns false.
267*cdf0e10cSrcweir      */
268*cdf0e10cSrcweir     inline bool ValidColRowOrReplicated( SCSIZE & rC, SCSIZE & rR ) const
269*cdf0e10cSrcweir     {
270*cdf0e10cSrcweir         return ValidColRow( rC, rR) || ValidColRowReplicated( rC, rR);
271*cdf0e10cSrcweir     }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir     void PutDouble( double fVal, SCSIZE nC, SCSIZE nR);
275*cdf0e10cSrcweir     void PutDouble( double fVal, SCSIZE nIndex)
276*cdf0e10cSrcweir         { pMat[nIndex].fVal = fVal; }
277*cdf0e10cSrcweir     void PutString( const String& rStr, SCSIZE nC, SCSIZE nR);
278*cdf0e10cSrcweir     void PutString( const String& rStr, SCSIZE nIndex);
279*cdf0e10cSrcweir     void PutEmpty( SCSIZE nC, SCSIZE nR);
280*cdf0e10cSrcweir     void PutEmpty( SCSIZE nIndex);
281*cdf0e10cSrcweir     /// Jump sal_False without path
282*cdf0e10cSrcweir     void PutEmptyPath( SCSIZE nC, SCSIZE nR);
283*cdf0e10cSrcweir     void PutEmptyPath( SCSIZE nIndex);
284*cdf0e10cSrcweir     void PutError( sal_uInt16 nErrorCode, SCSIZE nC, SCSIZE nR )
285*cdf0e10cSrcweir         { PutDouble( CreateDoubleError( nErrorCode ), nC, nR ); }
286*cdf0e10cSrcweir     void PutError( sal_uInt16 nErrorCode, SCSIZE nIndex )
287*cdf0e10cSrcweir         { PutDouble( CreateDoubleError( nErrorCode ), nIndex ); }
288*cdf0e10cSrcweir     void PutBoolean( bool bVal, SCSIZE nC, SCSIZE nR);
289*cdf0e10cSrcweir     void PutBoolean( bool bVal, SCSIZE nIndex);
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir     void FillDouble( double fVal,
292*cdf0e10cSrcweir             SCSIZE nC1, SCSIZE nR1, SCSIZE nC2, SCSIZE nR2 );
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir     /** May be used before obtaining the double value of an element to avoid
295*cdf0e10cSrcweir         passing its NAN around.
296*cdf0e10cSrcweir         @ATTENTION: MUST NOT be used if the element is a string!
297*cdf0e10cSrcweir                     Use GetErrorIfNotString() instead if not sure.
298*cdf0e10cSrcweir         @returns 0 if no error, else one of err... constants */
299*cdf0e10cSrcweir     sal_uInt16 GetError( SCSIZE nC, SCSIZE nR) const;
300*cdf0e10cSrcweir     sal_uInt16 GetError( SCSIZE nIndex) const
301*cdf0e10cSrcweir         { return pMat[nIndex].GetError(); }
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir     /** Use in ScInterpreter to obtain the error code, if any.
304*cdf0e10cSrcweir         @returns 0 if no error or string element, else one of err... constants */
305*cdf0e10cSrcweir     sal_uInt16 GetErrorIfNotString( SCSIZE nC, SCSIZE nR) const
306*cdf0e10cSrcweir         { return IsValue( nC, nR) ? GetError( nC, nR) : 0; }
307*cdf0e10cSrcweir     sal_uInt16 GetErrorIfNotString( SCSIZE nIndex) const
308*cdf0e10cSrcweir         { return IsValue( nIndex) ? GetError( nIndex) : 0; }
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir     /// @return 0.0 if empty or empty path, else value or DoubleError.
311*cdf0e10cSrcweir     double GetDouble( SCSIZE nC, SCSIZE nR) const;
312*cdf0e10cSrcweir     /// @return 0.0 if empty or empty path, else value or DoubleError.
313*cdf0e10cSrcweir     double GetDouble( SCSIZE nIndex) const
314*cdf0e10cSrcweir     {
315*cdf0e10cSrcweir         if ( pErrorInterpreter )
316*cdf0e10cSrcweir         {
317*cdf0e10cSrcweir             sal_uInt16 nError = GetDoubleErrorValue( pMat[nIndex].fVal);
318*cdf0e10cSrcweir             if ( nError )
319*cdf0e10cSrcweir                 SetErrorAtInterpreter( nError);
320*cdf0e10cSrcweir         }
321*cdf0e10cSrcweir         return pMat[nIndex].fVal;
322*cdf0e10cSrcweir     }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir     /// @return empty string if empty or empty path, else string content.
325*cdf0e10cSrcweir     const String& GetString( SCSIZE nC, SCSIZE nR) const;
326*cdf0e10cSrcweir     /// @return empty string if empty or empty path, else string content.
327*cdf0e10cSrcweir     const String& GetString( SCSIZE nIndex) const
328*cdf0e10cSrcweir         { return pMat[nIndex].GetString(); }
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir     /** @returns the matrix element's string if one is present, otherwise the
331*cdf0e10cSrcweir         numerical value formatted as string, or in case of an error the error
332*cdf0e10cSrcweir         string is returned; an empty string for empty, a "FALSE" string for
333*cdf0e10cSrcweir         empty path. */
334*cdf0e10cSrcweir     String GetString( SvNumberFormatter& rFormatter, SCSIZE nC, SCSIZE nR) const;
335*cdf0e10cSrcweir     String GetString( SvNumberFormatter& rFormatter, SCSIZE nIndex) const;
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir     /// @ATTENTION: If bString the ScMatrixValue->pS may still be NULL to indicate
338*cdf0e10cSrcweir     /// an empty string!
339*cdf0e10cSrcweir     const ScMatrixValue* Get( SCSIZE nC, SCSIZE nR, ScMatValType& nType) const;
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir     /// @return <TRUE/> if string or empty or empty path, in fact non-value.
342*cdf0e10cSrcweir     sal_Bool IsString( SCSIZE nIndex ) const
343*cdf0e10cSrcweir         { return mnValType && IsNonValueType( mnValType[nIndex]); }
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir     /// @return <TRUE/> if string or empty or empty path, in fact non-value.
346*cdf0e10cSrcweir     sal_Bool IsString( SCSIZE nC, SCSIZE nR ) const
347*cdf0e10cSrcweir     {
348*cdf0e10cSrcweir         ValidColRowReplicated( nC, nR );
349*cdf0e10cSrcweir         return mnValType && IsNonValueType( mnValType[ nC * nRowCount + nR ]);
350*cdf0e10cSrcweir     }
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir     /// @return <TRUE/> if empty or empty path.
353*cdf0e10cSrcweir     sal_Bool IsEmpty( SCSIZE nIndex ) const
354*cdf0e10cSrcweir         { return mnValType && ((mnValType[nIndex] & SC_MATVAL_EMPTY) == SC_MATVAL_EMPTY); }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir     /// @return <TRUE/> if empty or empty path.
357*cdf0e10cSrcweir     sal_Bool IsEmpty( SCSIZE nC, SCSIZE nR ) const
358*cdf0e10cSrcweir     {
359*cdf0e10cSrcweir         ValidColRowReplicated( nC, nR );
360*cdf0e10cSrcweir         return mnValType && ((mnValType[ nC * nRowCount + nR ] & SC_MATVAL_EMPTY) == SC_MATVAL_EMPTY);
361*cdf0e10cSrcweir     }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir     /// @return <TRUE/> if empty path.
364*cdf0e10cSrcweir     sal_Bool IsEmptyPath( SCSIZE nC, SCSIZE nR ) const
365*cdf0e10cSrcweir     {
366*cdf0e10cSrcweir         ValidColRowReplicated( nC, nR );
367*cdf0e10cSrcweir         return mnValType && ((mnValType[ nC * nRowCount + nR ] & SC_MATVAL_EMPTYPATH) == SC_MATVAL_EMPTYPATH);
368*cdf0e10cSrcweir     }
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir     /// @return <TRUE/> if empty path.
371*cdf0e10cSrcweir     sal_Bool IsEmptyPath( SCSIZE nIndex ) const
372*cdf0e10cSrcweir         { return mnValType && ((mnValType[nIndex] & SC_MATVAL_EMPTYPATH) == SC_MATVAL_EMPTYPATH); }
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir     /// @return <TRUE/> if value or boolean.
375*cdf0e10cSrcweir     sal_Bool IsValue( SCSIZE nIndex ) const
376*cdf0e10cSrcweir         { return !mnValType || IsValueType( mnValType[nIndex]); }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir     /// @return <TRUE/> if value or boolean.
379*cdf0e10cSrcweir     sal_Bool IsValue( SCSIZE nC, SCSIZE nR ) const
380*cdf0e10cSrcweir     {
381*cdf0e10cSrcweir         ValidColRowReplicated( nC, nR );
382*cdf0e10cSrcweir         return !mnValType || IsValueType( mnValType[ nC * nRowCount + nR ]);
383*cdf0e10cSrcweir     }
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir     /// @return <TRUE/> if value or boolean or empty or empty path.
386*cdf0e10cSrcweir     sal_Bool IsValueOrEmpty( SCSIZE nIndex ) const
387*cdf0e10cSrcweir         { return !mnValType || IsValueType( mnValType[nIndex] ) ||
388*cdf0e10cSrcweir             ((mnValType[nIndex] & SC_MATVAL_EMPTY) == SC_MATVAL_EMPTY); }
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir     /// @return <TRUE/> if value or boolean or empty or empty path.
391*cdf0e10cSrcweir     sal_Bool IsValueOrEmpty( SCSIZE nC, SCSIZE nR ) const
392*cdf0e10cSrcweir     {
393*cdf0e10cSrcweir         ValidColRowReplicated( nC, nR );
394*cdf0e10cSrcweir         return !mnValType || IsValueType( mnValType[ nC * nRowCount + nR ]) ||
395*cdf0e10cSrcweir             ((mnValType[ nC * nRowCount + nR ] & SC_MATVAL_EMPTY) ==
396*cdf0e10cSrcweir              SC_MATVAL_EMPTY);
397*cdf0e10cSrcweir     }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir     /// @return <TRUE/> if boolean.
400*cdf0e10cSrcweir     sal_Bool IsBoolean( SCSIZE nIndex ) const
401*cdf0e10cSrcweir         { return mnValType && IsBooleanType( mnValType[nIndex]); }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir     /// @return <TRUE/> if boolean.
404*cdf0e10cSrcweir     sal_Bool IsBoolean( SCSIZE nC, SCSIZE nR ) const
405*cdf0e10cSrcweir     {
406*cdf0e10cSrcweir         ValidColRowReplicated( nC, nR );
407*cdf0e10cSrcweir         return mnValType && IsBooleanType( mnValType[ nC * nRowCount + nR ]);
408*cdf0e10cSrcweir     }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir     /// @return <TRUE/> if entire matrix is numeric, including booleans, with no strings or empties
411*cdf0e10cSrcweir     sal_Bool IsNumeric() const
412*cdf0e10cSrcweir         { return 0 == mnNonValue; }
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir     void MatTrans( ScMatrix& mRes) const;
415*cdf0e10cSrcweir     void MatCopy ( ScMatrix& mRes) const;
416*cdf0e10cSrcweir 
417*cdf0e10cSrcweir //UNUSED2009-05 /** Copy upper left of this matrix to mRes matrix.
418*cdf0e10cSrcweir //UNUSED2009-05     This matrix's dimensions must be greater or equal to the mRes matrix
419*cdf0e10cSrcweir //UNUSED2009-05     dimensions.
420*cdf0e10cSrcweir //UNUSED2009-05  */
421*cdf0e10cSrcweir //UNUSED2009-05 void MatCopyUpperLeft( ScMatrix& mRes) const;
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir     // Convert ScInterpreter::CompareMat values (-1,0,1) to boolean values
424*cdf0e10cSrcweir     void CompareEqual();
425*cdf0e10cSrcweir     void CompareNotEqual();
426*cdf0e10cSrcweir     void CompareLess();
427*cdf0e10cSrcweir     void CompareGreater();
428*cdf0e10cSrcweir     void CompareLessEqual();
429*cdf0e10cSrcweir     void CompareGreaterEqual();
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir     double And();       // logical AND of all matrix values, or NAN
432*cdf0e10cSrcweir     double Or();        // logical OR of all matrix values, or NAN
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir     // All other matrix functions  MatMult, MInv, ...  are in ScInterpreter
435*cdf0e10cSrcweir     // to be numerically safe.
436*cdf0e10cSrcweir };
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir typedef formula::SimpleIntrusiveReference< class ScMatrix > ScMatrixRef;
440*cdf0e10cSrcweir typedef formula::SimpleIntrusiveReference< const class ScMatrix > ScConstMatrixRef;
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir #endif  // SC_MATRIX_HXX
444