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