View | Details | Raw Unified | Return to issue 21149
Collapse All | Expand All

(-)source/filter/excel/xehelper.cxx (-60 / +57 lines)
Lines 1137-1228 String XclExpUrlHelper::EncodeDde( const Link Here
1137
1137
1138
// Cached Value Lists =========================================================
1138
// Cached Value Lists =========================================================
1139
1139
1140
XclExpCachedValue::~XclExpCachedValue()
1140
XclExpCachedMatrix::XclExpCachedMatrix( const ScMatrix& rMatrix )
1141
    : mrMatrix( rMatrix )
1141
{
1142
{
1143
    const_cast<ScMatrix &>(mrMatrix).IncRef();
1142
}
1144
}
1143
1145
XclExpCachedMatrix::~XclExpCachedMatrix()
1144
// ----------------------------------------------------------------------------
1145
1146
void XclExpCachedDouble::Save( XclExpStream& rStrm ) const
1147
{
1146
{
1148
    rStrm.SetSliceSize( 9 );
1147
    const_cast<ScMatrix &>(mrMatrix).DecRef();
1149
    rStrm << EXC_CACHEDVAL_DOUBLE << mfVal;
1150
}
1148
}
1151
1149
1152
// ----------------------------------------------------------------------------
1150
void XclExpCachedMatrix::GetDimensions( SCSIZE & nCols, SCSIZE & nRows ) const
1153
1154
XclExpCachedString::XclExpCachedString( const String& rStr, XclStrFlags nFlags ) :
1155
    maStr( rStr, nFlags )
1156
{
1151
{
1152
    mrMatrix.GetDimensions( nCols, nRows );
1153
1154
    DBG_ASSERT( nCols && mnRows, "XclExpCachedMatrix::GetDimensions - empty matrix" );
1155
    DBG_ASSERT( nCols <= 256, "XclExpCachedMatrix::GetDimensions - too many columns" );
1157
}
1156
}
1158
1157
1159
void XclExpCachedString::Save( XclExpStream& rStrm ) const
1158
sal_Size XclExpCachedMatrix::GetSize() const
1160
{
1159
{
1161
    rStrm.SetSliceSize( 6 );
1160
    SCSIZE nCols, nRows;
1162
    rStrm << EXC_CACHEDVAL_STRING << maStr;
1163
}
1164
1161
1165
// ----------------------------------------------------------------------------
1162
    GetDimensions( nCols, nRows );
1166
1163
1167
XclExpCachedError::XclExpCachedError( USHORT nScError ) :
1164
    /*  The returned size may be wrong if the matrix contains strings. The only
1168
    mnError( XclTools::GetXclErrorCode( nScError ) )
1165
        effect is that the export stream has to update a wrong record size which is
1169
{
1166
        faster than to iterate through all cached values and calculate their sizes. */
1167
    return 3 + 9 * (nCols * nRows);
1170
}
1168
}
1171
1169
1172
void XclExpCachedError::Save( XclExpStream& rStrm ) const
1170
void XclExpCachedMatrix::Save( XclExpStream& rStrm ) const
1173
{
1171
{
1174
    rStrm.SetSliceSize( 9 );
1172
    SCSIZE nCols, nRows;
1175
    rStrm << EXC_CACHEDVAL_ERROR << mnError;
1176
    rStrm.WriteZeroBytes( 7 );
1177
}
1178
1173
1179
// ----------------------------------------------------------------------------
1174
    GetDimensions( nCols, nRows );
1180
1175
1181
XclExpCachedMatrix::XclExpCachedMatrix( const ScMatrix& rMatrix, XclStrFlags nFlags )
1176
    if( rStrm.GetRoot().GetBiff() <= EXC_BIFF5 )
1182
{
1177
        // in BIFF2-BIFF7: 256 columns represented by 0 columns
1183
    rMatrix.GetDimensions( mnScCols, mnScRows );
1178
        rStrm << static_cast< sal_uInt8 >( nCols ) << static_cast< sal_uInt16 >( nRows );
1184
    DBG_ASSERT( mnScCols && mnScRows, "XclExpCachedMatrix::XclExpCachedMatrix - empty matrix" );
1179
    else
1185
    DBG_ASSERT( mnScCols <= 256, "XclExpCachedMatrix::XclExpCachedMatrix - too many columns" );
1180
        // in BIFF8: columns and rows decreaed by 1
1181
        rStrm << static_cast< sal_uInt8 >( nCols - 1 ) << static_cast< sal_uInt16 >( nRows - 1 );
1186
1182
1187
    for( SCSIZE nScRow = 0; nScRow < mnScRows; ++nScRow )
1183
    for( SCSIZE nRow = 0; nRow < nRows; ++nRow )
1188
    {
1184
    {
1189
        for( SCSIZE nScCol = 0; nScCol < mnScCols; ++nScCol )
1185
        for( SCSIZE nCol = 0; nCol < nCols; ++nCol )
1190
        {
1186
        {
1191
            XclExpCachedValue* pNewVal = 0;
1192
            ScMatValType nMatValType = SC_MATVAL_VALUE;
1187
            ScMatValType nMatValType = SC_MATVAL_VALUE;
1193
            const ScMatrixValue* pMatVal = rMatrix.Get( nScCol, nScRow, nMatValType );
1188
            const ScMatrixValue* pMatVal = mrMatrix.Get( nCol, nRow, nMatValType );
1194
            if( !pMatVal )
1189
1195
                pNewVal = new XclExpCachedString( EMPTY_STRING, nFlags );
1190
            if( !pMatVal || SC_MATVAL_EMPTY == nMatValType )
1196
            else if( ScMatrix::IsStringType( nMatValType ) )
1191
            {
1197
                pNewVal = new XclExpCachedString( pMatVal->GetString(), nFlags );
1192
                rStrm.SetSliceSize( 9 );
1198
            else if( USHORT nScError = pMatVal->GetError() )
1193
                rStrm << EXC_CACHEDVAL_EMPTY;
1199
                pNewVal = new XclExpCachedError( nScError );
1194
                rStrm.WriteZeroBytes( 8 );
1200
            else
1201
                pNewVal = new XclExpCachedDouble( pMatVal->fVal );
1202
            maValueList.Append( pNewVal );
1203
        }
1204
    }
1195
    }
1196
            else if( ScMatrix::IsStringType( nMatValType ) )
1197
            {
1198
                XclExpString aStr( pMatVal->GetString(), EXC_STR_DEFAULT );
1199
                rStrm.SetSliceSize( 6 );
1200
                rStrm << EXC_CACHEDVAL_STRING << aStr;
1205
}
1201
}
1206
1202
            else if( SC_MATVAL_BOOLEAN == nMatValType )
1207
sal_Size XclExpCachedMatrix::GetSize() const
1208
{
1203
{
1209
    /*  The returned size may be wrong if the matrix contains strings. The only
1204
                sal_Int8 nBool = pMatVal->GetBoolean();
1210
        effect is that the export stream has to update a wrong record size which is
1205
                rStrm.SetSliceSize( 9 );
1211
        faster than to iterate through all cached values and calculate their sizes. */
1206
                rStrm << EXC_CACHEDVAL_BOOL << nBool;
1212
    return 3 + 9 * maValueList.Count();
1207
                rStrm.WriteZeroBytes( 7 );
1213
}
1208
}
1214
1209
            else if( USHORT nScError = pMatVal->GetError() )
1215
void XclExpCachedMatrix::Save( XclExpStream& rStrm ) const
1216
{
1210
{
1217
    if( rStrm.GetRoot().GetBiff() <= EXC_BIFF5 )
1211
                sal_Int8 nError ( XclTools::GetXclErrorCode( nScError ) );
1218
        // in BIFF2-BIFF7: 256 columns represented by 0 columns
1212
                rStrm.SetSliceSize( 9 );
1219
        rStrm << static_cast< sal_uInt8 >( mnScCols ) << static_cast< sal_uInt16 >( mnScRows );
1213
                rStrm << EXC_CACHEDVAL_ERROR << nError;
1214
                rStrm.WriteZeroBytes( 7 );
1215
            }
1220
    else
1216
    else
1221
        // in BIFF8: columns and rows decreaed by 1
1217
            {
1222
        rStrm << static_cast< sal_uInt8 >( mnScCols - 1 ) << static_cast< sal_uInt16 >( mnScRows - 1 );
1218
                rStrm.SetSliceSize( 9 );
1223
1219
                rStrm << EXC_CACHEDVAL_DOUBLE << pMatVal->fVal;
1224
    for( const XclExpCachedValue* pValue = maValueList.First(); pValue; pValue = maValueList.Next() )
1220
            }
1225
        pValue->Save( rStrm );
1221
        }
1222
    }
1226
}
1223
}
1227
1224
1228
// ============================================================================
1225
// ============================================================================
(-)source/filter/excel/xihelper.cxx (-3 / +2 lines)
Lines 861-869 XclImpCachedValue::XclImpCachedValue( Xc Link Here
861
        case EXC_CACHEDVAL_ERROR:
861
        case EXC_CACHEDVAL_ERROR:
862
        {
862
        {
863
            double fVal;
863
            double fVal;
864
            rStrm.Ignore( 1 );
865
            rStrm >> mnBoolErr;
864
            rStrm >> mnBoolErr;
866
            rStrm.Ignore( 6 );
865
            rStrm.Ignore( 7 );
867
866
868
            const ScTokenArray* pScTokArr = rStrm.GetRoot().GetOldFmlaConverter().GetBoolErr(
867
            const ScTokenArray* pScTokArr = rStrm.GetRoot().GetOldFmlaConverter().GetBoolErr(
869
                XclTools::ErrorToEnum( fVal, mnType == EXC_CACHEDVAL_ERROR, mnBoolErr ) );
868
                XclTools::ErrorToEnum( fVal, mnType == EXC_CACHEDVAL_ERROR, mnBoolErr ) );
Lines 941-947 ScMatrixRef XclImpCachedMatrix::CreateSc Link Here
941
                        xScMatrix->PutString( pValue->GetString(), nScCol, nScRow );
940
                        xScMatrix->PutString( pValue->GetString(), nScCol, nScRow );
942
                    break;
941
                    break;
943
                    case EXC_CACHEDVAL_BOOL:
942
                    case EXC_CACHEDVAL_BOOL:
944
                        xScMatrix->PutDouble( pValue->GetBool() ? 1.0 : 0.0, nScCol, nScRow );
943
                        xScMatrix->PutBoolean( pValue->GetBool(), nScCol, nScRow );
945
                    break;
944
                    break;
946
                    case EXC_CACHEDVAL_ERROR:
945
                    case EXC_CACHEDVAL_ERROR:
947
                        xScMatrix->PutError( pValue->GetError(), nScCol, nScRow );
946
                        xScMatrix->PutError( pValue->GetError(), nScCol, nScRow );
(-)source/filter/inc/xehelper.hxx (-66 / +5 lines)
Lines 436-511 public: Link Here
436
    static String       EncodeDde( const String& rApplic, const String rTopic );
436
    static String       EncodeDde( const String& rApplic, const String rTopic );
437
};
437
};
438
438
439
// Cached Value Lists =========================================================
440
441
/** The base class for cached values.
442
    @descr  Cached values are used to store a list or a 2D array of double,
443
    string and Boolean values and error codes, for instannce in the records
444
    CRN and EXTERNNAME or in the token tArray. */
445
class XclExpCachedValue
446
{
447
public:
448
    virtual             ~XclExpCachedValue();
449
    virtual void        Save( XclExpStream& rStrm ) const = 0;
450
};
451
452
// ----------------------------------------------------------------------------
453
454
/** A cached value that stores a double. */
455
class XclExpCachedDouble : public XclExpCachedValue
456
{
457
public:
458
    explicit inline     XclExpCachedDouble( double fVal ) : mfVal( fVal ) {}
459
    /** Writes the double value to stream. */
460
    virtual void        Save( XclExpStream& rStrm ) const;
461
462
private:
463
    double              mfVal;          /// The double value.
464
};
465
466
// ----------------------------------------------------------------------------
439
// ----------------------------------------------------------------------------
467
468
/** A cached value that stores a string. */
469
class XclExpCachedString : public XclExpCachedValue
470
{
471
public:
472
    explicit            XclExpCachedString( const String& rStr, XclStrFlags nFlags = EXC_STR_DEFAULT );
473
    /** Writes the string to stream. */
474
    virtual void        Save( XclExpStream& rStrm ) const;
475
476
private:
477
    XclExpString        maStr;
478
};
479
480
// ----------------------------------------------------------------------------
481
482
/** A cached value that stores an error code. */
483
class XclExpCachedError : public XclExpCachedValue
484
{
485
public:
486
    explicit            XclExpCachedError( USHORT nScError );
487
    /** Writes the error code to stream. */
488
    virtual void        Save( XclExpStream& rStrm ) const;
489
490
private:
491
    sal_uInt8           mnError;
492
};
493
494
// ----------------------------------------------------------------------------
495
496
class ScDocument;
440
class ScDocument;
497
class ScMatrix;
441
class ScMatrix;
498
442
499
/** Contains cached values in a 2-dimensional array. */
443
/** Contains cached values in a 2-dimensional array. */
500
class XclExpCachedMatrix
444
class XclExpCachedMatrix
501
{
445
{
446
    void            GetDimensions( SCSIZE & nCols, SCSIZE & nRows ) const;
502
public:
447
public:
503
    /** Constructs and fills a new matrix.
448
    /** Constructs and fills a new matrix.
504
        @param rMatrix  The Calc value matrix.
449
        @param rMatrix  The Calc value matrix. */
505
        @param nFlags  Flags for writing strings. */
450
    explicit        XclExpCachedMatrix( const ScMatrix& rMatrix );
506
    explicit            XclExpCachedMatrix(
451
                   ~XclExpCachedMatrix();
507
                            const ScMatrix& rMatrix,
508
                            XclStrFlags nFlags = EXC_STR_DEFAULT );
509
452
510
    /** Returns the byte count of all contained data. */
453
    /** Returns the byte count of all contained data. */
511
    sal_Size            GetSize() const;
454
    sal_Size            GetSize() const;
Lines 513-523 public: Link Here
513
    void                Save( XclExpStream& rStrm ) const;
456
    void                Save( XclExpStream& rStrm ) const;
514
457
515
private:
458
private:
516
    typedef ScfDelList< XclExpCachedValue > XclExpCachedValueList;
459
    const ScMatrix& mrMatrix;
517
518
    XclExpCachedValueList maValueList;  /// The list containing the cached values.
519
    SCSIZE              mnScCols;       /// Calc column count of the value matrix.
520
    SCSIZE              mnScRows;       /// Calc row count of the value matrix.
521
};
460
};
522
461
523
// ============================================================================
462
// ============================================================================

Return to issue 21149