Lines 66-92
union ScMatrixValue
Link Here
|
66 |
|
66 |
|
67 |
@ATTENTION: optimized for speed and double values. |
67 |
@ATTENTION: optimized for speed and double values. |
68 |
|
68 |
|
69 |
Matrix elements are NOT initialized after construction! |
69 |
<p> Matrix elements are NOT initialized after construction! |
70 |
|
70 |
|
71 |
All methods using an SCSIZE nIndex parameter and all Is... methods do NOT |
71 |
<p> All methods using an SCSIZE nIndex parameter and all Is...() methods do |
72 |
check the range for validity! However, the Put... and Get... methods using |
72 |
NOT check the range for validity! However, the Put...() and Get...() |
73 |
nCol/nRow parameters do check the range. <p> |
73 |
methods using nCol/nRow parameters do check the range. |
|
|
74 |
|
75 |
<p> Methods using nCol/nRow parameters do replicate a single row vector if |
76 |
nRow > 0 and nCol < nColCount, respectively a column vector if nCol |
77 |
> 0 and nRow < nRowCount. |
74 |
|
78 |
|
75 |
GetString( SCSIZE nIndex ) does not check if there really is a string, do |
79 |
<p> GetString( SCSIZE nIndex ) does not check if there really is a string, |
76 |
this with IsString() first. GetString( SCSIZE nC, SCSIZE nR ) does check |
80 |
do this with IsString() first. GetString( SCSIZE nC, SCSIZE nR ) does check |
77 |
it and returns and empty string if there is no string. Both GetDouble() |
81 |
it and returns and empty string if there is no string. Both GetDouble() |
78 |
methods don't check for a string, do this with IsNumeric() or IsString() |
82 |
methods don't check for a string, do this with IsNumeric() or IsString() or |
79 |
or IsValue() first. <p> |
83 |
IsValue() first. |
80 |
|
84 |
|
81 |
The GetString( SvNumberFormatter&, ...) methods return the matrix element's |
85 |
<p> The GetString( SvNumberFormatter&, ...) methods return the matrix |
82 |
string if one is present, otherwise the numerical value is formatted as a |
86 |
element's string if one is present, otherwise the numerical value is |
83 |
string, or in case of an error the error string is returned. |
87 |
formatted as a string, or in case of an error the error string is returned. |
84 |
|
88 |
|
85 |
PutDouble() does not reset an eventual string! Use |
89 |
<p> PutDouble() does not reset an eventual string! Use |
86 |
PutDoubleAndResetString() if that is wanted. Also the FillDouble...() |
90 |
PutDoubleAndResetString() if that is wanted. Also the FillDouble...() |
87 |
methods don't reset strings. As a consequence memory leaks may occur if |
91 |
methods don't reset strings. As a consequence memory leaks may occur if |
88 |
used wrong. |
92 |
used wrong. |
89 |
*/ |
93 |
*/ |
|
|
94 |
|
90 |
class ScMatrix |
95 |
class ScMatrix |
91 |
{ |
96 |
{ |
92 |
ScMatrixValue* pMat; |
97 |
ScMatrixValue* pMat; |
Lines 115-121
class ScMatrix
Link Here
|
115 |
|
120 |
|
116 |
public: |
121 |
public: |
117 |
|
122 |
|
118 |
/// The maximum number of elements a matrix may have at runtime |
123 |
/// The maximum number of elements a matrix may have at runtime. |
119 |
inline static size_t GetElementsMax() |
124 |
inline static size_t GetElementsMax() |
120 |
{ |
125 |
{ |
121 |
const size_t nMemMax = (((size_t)(~0))-64) / sizeof(ScMatrixValue); |
126 |
const size_t nMemMax = (((size_t)(~0))-64) / sizeof(ScMatrixValue); |
Lines 157-165
public:
Link Here
|
157 |
created instead and a double error value (errStackOverflow) is set. |
162 |
created instead and a double error value (errStackOverflow) is set. |
158 |
Compare nC and nR with a GetDimensions() call to check. */ |
163 |
Compare nC and nR with a GetDimensions() call to check. */ |
159 |
ScMatrix( SCSIZE nC, SCSIZE nR) : nRefCnt(0) { CreateMatrix( nC, nR); } |
164 |
ScMatrix( SCSIZE nC, SCSIZE nR) : nRefCnt(0) { CreateMatrix( nC, nR); } |
|
|
165 |
|
166 |
/** Clone the matrix. */ |
160 |
ScMatrix* Clone() const; |
167 |
ScMatrix* Clone() const; |
161 |
|
168 |
|
162 |
/// disable refcounting forever, may only be deleted via Delete() afterwards |
169 |
/** Clone the matrix and extend it to the new size. nNewCols and nNewRows |
|
|
170 |
MUST be at least of the size of the original matrix. */ |
171 |
ScMatrix* CloneAndExtend( SCSIZE nNewCols, SCSIZE nNewRows ) const; |
172 |
|
173 |
/// Disable refcounting forever, may only be deleted via Delete() afterwards. |
163 |
inline void SetEternalRef() { nRefCnt = ULONG_MAX; } |
174 |
inline void SetEternalRef() { nRefCnt = ULONG_MAX; } |
164 |
inline bool IsEternalRef() const { return nRefCnt == ULONG_MAX; } |
175 |
inline bool IsEternalRef() const { return nRefCnt == ULONG_MAX; } |
165 |
inline void IncRef() const |
176 |
inline void IncRef() const |
Lines 196-201
public:
Link Here
|
196 |
inline SCSIZE CalcOffset( SCSIZE nC, SCSIZE nR) const |
207 |
inline SCSIZE CalcOffset( SCSIZE nC, SCSIZE nR) const |
197 |
{ return nC * nRowCount + nR; } |
208 |
{ return nC * nRowCount + nR; } |
198 |
|
209 |
|
|
|
210 |
/** For a row vector or column vector, if the position does not point into |
211 |
the vector but is a valid column or row offset it is adapted such that |
212 |
it points to an element to be replicated, same column row 0 for a row |
213 |
vector, same row column 0 for a column vector. Else, for a 2D matrix, |
214 |
returns false. |
215 |
*/ |
216 |
inline bool ValidColRowReplicated( SCSIZE & rC, SCSIZE & rR ) const |
217 |
{ |
218 |
if (nColCount == 1 && nRowCount == 1) |
219 |
{ |
220 |
rC = 0; |
221 |
rR = 0; |
222 |
return true; |
223 |
} |
224 |
else if (nColCount == 1 && rR < nRowCount) |
225 |
{ |
226 |
rC = 0; |
227 |
return true; |
228 |
} |
229 |
else if (nRowCount == 1 && rC < nColCount) |
230 |
{ |
231 |
rR = 0; |
232 |
return true; |
233 |
} |
234 |
return false; |
235 |
} |
236 |
|
237 |
/** Checks if the matrix position is within the matrix. If it is not, for a |
238 |
row vector or column vector the position is adapted such that it points |
239 |
to an element to be replicated, same column row 0 for a row vector, |
240 |
same row column 0 for a column vector. Else, for a 2D matrix and |
241 |
position not within matrix, returns false. |
242 |
*/ |
243 |
inline bool ValidColRowOrReplicated( SCSIZE & rC, SCSIZE & rR ) const |
244 |
{ |
245 |
return ValidColRow( rC, rR) || ValidColRowReplicated( rC, rR); |
246 |
} |
247 |
|
248 |
|
199 |
void PutDouble( double fVal, SCSIZE nC, SCSIZE nR); |
249 |
void PutDouble( double fVal, SCSIZE nC, SCSIZE nR); |
200 |
void PutDouble( double fVal, SCSIZE nIndex) |
250 |
void PutDouble( double fVal, SCSIZE nIndex) |
201 |
{ pMat[nIndex].fVal = fVal; } |
251 |
{ pMat[nIndex].fVal = fVal; } |
Lines 262-293
public:
Link Here
|
262 |
/// @return <TRUE/> if string or empty |
312 |
/// @return <TRUE/> if string or empty |
263 |
BOOL IsString( SCSIZE nIndex ) const |
313 |
BOOL IsString( SCSIZE nIndex ) const |
264 |
{ return mnValType && IsStringType( mnValType[nIndex]); } |
314 |
{ return mnValType && IsStringType( mnValType[nIndex]); } |
|
|
315 |
|
265 |
/// @return <TRUE/> if string or empty |
316 |
/// @return <TRUE/> if string or empty |
266 |
BOOL IsString( SCSIZE nC, SCSIZE nR ) const |
317 |
BOOL IsString( SCSIZE nC, SCSIZE nR ) const |
267 |
{ return mnValType && IsStringType( mnValType[ nC * nRowCount + nR ]); } |
318 |
{ |
|
|
319 |
ValidColRowReplicated( nC, nR ); |
320 |
return mnValType && IsStringType( mnValType[ nC * nRowCount + nR ]); |
321 |
} |
322 |
|
268 |
BOOL IsEmpty( SCSIZE nIndex ) const |
323 |
BOOL IsEmpty( SCSIZE nIndex ) const |
269 |
{ return mnValType && ((mnValType[nIndex] & SC_MATVAL_EMPTY) == SC_MATVAL_EMPTY); } |
324 |
{ return mnValType && ((mnValType[nIndex] & SC_MATVAL_EMPTY) == SC_MATVAL_EMPTY); } |
|
|
325 |
|
270 |
BOOL IsEmptyPath( SCSIZE nC, SCSIZE nR ) const |
326 |
BOOL IsEmptyPath( SCSIZE nC, SCSIZE nR ) const |
271 |
{ return mnValType && ((mnValType[ nC * nRowCount + nR ] & SC_MATVAL_EMPTYPATH) == SC_MATVAL_EMPTYPATH); } |
327 |
{ |
|
|
328 |
ValidColRowReplicated( nC, nR ); |
329 |
return mnValType && ((mnValType[ nC * nRowCount + nR ] & SC_MATVAL_EMPTYPATH) == SC_MATVAL_EMPTYPATH); |
330 |
} |
331 |
|
272 |
BOOL IsEmptyPath( SCSIZE nIndex ) const |
332 |
BOOL IsEmptyPath( SCSIZE nIndex ) const |
273 |
{ return mnValType && ((mnValType[nIndex] & SC_MATVAL_EMPTYPATH) == SC_MATVAL_EMPTYPATH); } |
333 |
{ return mnValType && ((mnValType[nIndex] & SC_MATVAL_EMPTYPATH) == SC_MATVAL_EMPTYPATH); } |
|
|
334 |
|
274 |
BOOL IsEmpty( SCSIZE nC, SCSIZE nR ) const |
335 |
BOOL IsEmpty( SCSIZE nC, SCSIZE nR ) const |
275 |
{ return mnValType && ((mnValType[ nC * nRowCount + nR ] & SC_MATVAL_EMPTY) == SC_MATVAL_EMPTY); } |
336 |
{ |
|
|
337 |
ValidColRowReplicated( nC, nR ); |
338 |
return mnValType && ((mnValType[ nC * nRowCount + nR ] & SC_MATVAL_EMPTY) == SC_MATVAL_EMPTY); |
339 |
} |
340 |
|
276 |
BOOL IsValue( SCSIZE nIndex ) const |
341 |
BOOL IsValue( SCSIZE nIndex ) const |
277 |
{ return !mnValType || IsValueType( mnValType[nIndex]); } |
342 |
{ return !mnValType || IsValueType( mnValType[nIndex]); } |
|
|
343 |
|
278 |
BOOL IsValue( SCSIZE nC, SCSIZE nR ) const |
344 |
BOOL IsValue( SCSIZE nC, SCSIZE nR ) const |
279 |
{ return !mnValType || IsValueType( mnValType[ nC * nRowCount + nR ]); } |
345 |
{ |
|
|
346 |
ValidColRowReplicated( nC, nR ); |
347 |
return !mnValType || IsValueType( mnValType[ nC * nRowCount + nR ]); |
348 |
} |
349 |
|
280 |
BOOL IsValueOrEmpty( SCSIZE nIndex ) const |
350 |
BOOL IsValueOrEmpty( SCSIZE nIndex ) const |
281 |
{ return !mnValType || IsValueType( mnValType[nIndex] ) || |
351 |
{ return !mnValType || IsValueType( mnValType[nIndex] ) || |
282 |
((mnValType[nIndex] & SC_MATVAL_EMPTY) == SC_MATVAL_EMPTY); } |
352 |
((mnValType[nIndex] & SC_MATVAL_EMPTY) == SC_MATVAL_EMPTY); } |
|
|
353 |
|
283 |
BOOL IsValueOrEmpty( SCSIZE nC, SCSIZE nR ) const |
354 |
BOOL IsValueOrEmpty( SCSIZE nC, SCSIZE nR ) const |
284 |
{ return !mnValType || IsValueType( mnValType[ nC * nRowCount + nR ]) || |
355 |
{ |
|
|
356 |
ValidColRowReplicated( nC, nR ); |
357 |
return !mnValType || IsValueType( mnValType[ nC * nRowCount + nR ]) || |
285 |
((mnValType[ nC * nRowCount + nR ] & SC_MATVAL_EMPTY) == |
358 |
((mnValType[ nC * nRowCount + nR ] & SC_MATVAL_EMPTY) == |
286 |
SC_MATVAL_EMPTY); } |
359 |
SC_MATVAL_EMPTY); |
|
|
360 |
} |
361 |
|
287 |
BOOL IsBoolean( SCSIZE nIndex ) const |
362 |
BOOL IsBoolean( SCSIZE nIndex ) const |
288 |
{ return mnValType && IsBooleanType( mnValType[nIndex]); } |
363 |
{ return mnValType && IsBooleanType( mnValType[nIndex]); } |
|
|
364 |
|
289 |
BOOL IsBoolean( SCSIZE nC, SCSIZE nR ) const |
365 |
BOOL IsBoolean( SCSIZE nC, SCSIZE nR ) const |
290 |
{ return mnValType && IsBooleanType( mnValType[ nC * nRowCount + nR ]); } |
366 |
{ |
|
|
367 |
ValidColRowReplicated( nC, nR ); |
368 |
return mnValType && IsBooleanType( mnValType[ nC * nRowCount + nR ]); |
369 |
} |
291 |
|
370 |
|
292 |
/// @return <TRUE/> if entire matrix is numeric, including booleans, with no strings or empties |
371 |
/// @return <TRUE/> if entire matrix is numeric, including booleans, with no strings or empties |
293 |
BOOL IsNumeric() const |
372 |
BOOL IsNumeric() const |
Lines 295-303
public:
Link Here
|
295 |
|
374 |
|
296 |
void MatTrans( ScMatrix& mRes) const; |
375 |
void MatTrans( ScMatrix& mRes) const; |
297 |
void MatCopy ( ScMatrix& mRes) const; |
376 |
void MatCopy ( ScMatrix& mRes) const; |
|
|
377 |
|
298 |
/** Copy upper left of this matrix to mRes matrix. |
378 |
/** Copy upper left of this matrix to mRes matrix. |
299 |
This matrix's dimensions must be greater than the mRes matrix |
379 |
This matrix's dimensions must be greater or equal to the mRes matrix |
300 |
dimensions. */ |
380 |
dimensions. |
|
|
381 |
*/ |
301 |
void MatCopyUpperLeft( ScMatrix& mRes) const; |
382 |
void MatCopyUpperLeft( ScMatrix& mRes) const; |
302 |
|
383 |
|
303 |
// Convert ScInterpreter::CompareMat values (-1,0,1) to boolean values |
384 |
// Convert ScInterpreter::CompareMat values (-1,0,1) to boolean values |
Lines 320-336
typedef ScSimpleIntrusiveReference< clas
Link Here
|
320 |
typedef ScSimpleIntrusiveReference< const class ScMatrix > ScConstMatrixRef; |
401 |
typedef ScSimpleIntrusiveReference< const class ScMatrix > ScConstMatrixRef; |
321 |
|
402 |
|
322 |
|
403 |
|
323 |
// Old values as used up to SO52. |
404 |
#endif // SC_MATRIX_HXX |
324 |
// The overall elements count had to be <= SC_MAX_MAT_DIM * SC_MAX_MAT_DIM. |
|
|
325 |
// Don't use except maybe for file format compatibility. |
326 |
// In any other case use ScMatrix::GetElementsMax() instead. |
327 |
#ifdef WIN |
328 |
#define SC_OLD_MAX_MAT_DIM 64 |
329 |
#else |
330 |
#define SC_OLD_MAX_MAT_DIM 128 |
331 |
#endif |
332 |
#define SC_OLD_MAX_MAT_ELEMENTS ((SC_OLD_MAX_MAT_DIM) * (SC_OLD_MAX_MAT_DIM)) |
333 |
|
334 |
|
335 |
#endif |
336 |
|