LCOV - code coverage report
Current view: top level - sc/source/core/data - subtotalparam.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 66 106 62.3 %
Date: 2015-06-13 12:38:46 Functions: 6 8 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include "subtotalparam.hxx"
      11             : 
      12             : #include <osl/diagnose.h>
      13             : 
      14         279 : ScSubTotalParam::ScSubTotalParam()
      15             : {
      16        1116 :     for ( sal_uInt16 i=0; i<MAXSUBTOTAL; i++ )
      17             :     {
      18         837 :         nSubTotals[i] = 0;
      19         837 :         pSubTotals[i] = NULL;
      20         837 :         pFunctions[i] = NULL;
      21             :     }
      22             : 
      23         279 :     Clear();
      24         279 : }
      25             : 
      26         480 : ScSubTotalParam::ScSubTotalParam( const ScSubTotalParam& r ) :
      27             :         nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),nUserIndex(r.nUserIndex),
      28             :         bRemoveOnly(r.bRemoveOnly),bReplace(r.bReplace),bPagebreak(r.bPagebreak),bCaseSens(r.bCaseSens),
      29             :         bDoSort(r.bDoSort),bAscending(r.bAscending),bUserDef(r.bUserDef),
      30         480 :         bIncludePattern(r.bIncludePattern)
      31             : {
      32        1920 :     for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
      33             :     {
      34        1440 :         bGroupActive[i] = r.bGroupActive[i];
      35        1440 :         nField[i]       = r.nField[i];
      36             : 
      37        1440 :         if ( (r.nSubTotals[i] > 0) && r.pSubTotals[i] && r.pFunctions[i] )
      38             :         {
      39           4 :             nSubTotals[i] = r.nSubTotals[i];
      40           4 :             pSubTotals[i] = new SCCOL   [r.nSubTotals[i]];
      41           4 :             pFunctions[i] = new ScSubTotalFunc  [r.nSubTotals[i]];
      42             : 
      43           8 :             for (SCCOL j=0; j<r.nSubTotals[i]; j++)
      44             :             {
      45           4 :                 pSubTotals[i][j] = r.pSubTotals[i][j];
      46           4 :                 pFunctions[i][j] = r.pFunctions[i][j];
      47           4 :             }
      48             :         }
      49             :         else
      50             :         {
      51        1436 :             nSubTotals[i] = 0;
      52        1436 :             pSubTotals[i] = NULL;
      53        1436 :             pFunctions[i] = NULL;
      54             :         }
      55             :     }
      56         480 : }
      57             : 
      58         279 : void ScSubTotalParam::Clear()
      59             : {
      60         279 :     nCol1=nCol2= 0;
      61         279 :     nRow1=nRow2 = 0;
      62         279 :     nUserIndex = 0;
      63         279 :     bPagebreak=bCaseSens=bUserDef=bIncludePattern=bRemoveOnly = false;
      64         279 :     bAscending=bReplace=bDoSort = true;
      65             : 
      66        1116 :     for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
      67             :     {
      68         837 :         bGroupActive[i] = false;
      69         837 :         nField[i]       = 0;
      70             : 
      71         837 :         if ( (nSubTotals[i] > 0) && pSubTotals[i] && pFunctions[i] )
      72             :         {
      73           0 :             for ( SCCOL j=0; j<nSubTotals[i]; j++ ) {
      74           0 :                 pSubTotals[i][j] = 0;
      75           0 :                 pFunctions[i][j] = SUBTOTAL_FUNC_NONE;
      76             :             }
      77             :         }
      78             :     }
      79         279 : }
      80             : 
      81         187 : ScSubTotalParam& ScSubTotalParam::operator=( const ScSubTotalParam& r )
      82             : {
      83         187 :     nCol1           = r.nCol1;
      84         187 :     nRow1           = r.nRow1;
      85         187 :     nCol2           = r.nCol2;
      86         187 :     nRow2           = r.nRow2;
      87         187 :     bRemoveOnly     = r.bRemoveOnly;
      88         187 :     bReplace        = r.bReplace;
      89         187 :     bPagebreak      = r.bPagebreak;
      90         187 :     bCaseSens       = r.bCaseSens;
      91         187 :     bDoSort         = r.bDoSort;
      92         187 :     bAscending      = r.bAscending;
      93         187 :     bUserDef        = r.bUserDef;
      94         187 :     nUserIndex      = r.nUserIndex;
      95         187 :     bIncludePattern = r.bIncludePattern;
      96             : 
      97         748 :     for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
      98             :     {
      99         561 :         bGroupActive[i] = r.bGroupActive[i];
     100         561 :         nField[i]       = r.nField[i];
     101         561 :         nSubTotals[i]   = r.nSubTotals[i];
     102             : 
     103         561 :         if ( pSubTotals[i] ) delete [] pSubTotals[i];
     104         561 :         if ( pFunctions[i] ) delete [] pFunctions[i];
     105             : 
     106         561 :         if ( r.nSubTotals[i] > 0 )
     107             :         {
     108         163 :             pSubTotals[i] = new SCCOL   [r.nSubTotals[i]];
     109         163 :             pFunctions[i] = new ScSubTotalFunc  [r.nSubTotals[i]];
     110             : 
     111         328 :             for (SCCOL j=0; j<r.nSubTotals[i]; j++)
     112             :             {
     113         165 :                 pSubTotals[i][j] = r.pSubTotals[i][j];
     114         165 :                 pFunctions[i][j] = r.pFunctions[i][j];
     115             :             }
     116             :         }
     117             :         else
     118             :         {
     119         398 :             nSubTotals[i] = 0;
     120         398 :             pSubTotals[i] = NULL;
     121         398 :             pFunctions[i] = NULL;
     122             :         }
     123             :     }
     124             : 
     125         187 :     return *this;
     126             : }
     127             : 
     128           0 : bool ScSubTotalParam::operator==( const ScSubTotalParam& rOther ) const
     129             : {
     130           0 :     bool bEqual =   (nCol1          == rOther.nCol1)
     131           0 :                  && (nRow1          == rOther.nRow1)
     132           0 :                  && (nCol2          == rOther.nCol2)
     133           0 :                  && (nRow2          == rOther.nRow2)
     134           0 :                  && (nUserIndex     == rOther.nUserIndex)
     135           0 :                  && (bRemoveOnly    == rOther.bRemoveOnly)
     136           0 :                  && (bReplace       == rOther.bReplace)
     137           0 :                  && (bPagebreak     == rOther.bPagebreak)
     138           0 :                  && (bDoSort        == rOther.bDoSort)
     139           0 :                  && (bCaseSens      == rOther.bCaseSens)
     140           0 :                  && (bAscending     == rOther.bAscending)
     141           0 :                  && (bUserDef       == rOther.bUserDef)
     142           0 :                  && (bIncludePattern== rOther.bIncludePattern);
     143             : 
     144           0 :     if ( bEqual )
     145             :     {
     146           0 :         bEqual = true;
     147           0 :         for ( sal_uInt16 i=0; i<MAXSUBTOTAL && bEqual; i++ )
     148             :         {
     149           0 :             bEqual =   (bGroupActive[i] == rOther.bGroupActive[i])
     150           0 :                     && (nField[i]       == rOther.nField[i])
     151           0 :                     && (nSubTotals[i]   == rOther.nSubTotals[i]);
     152             : 
     153           0 :             if ( bEqual && (nSubTotals[i] > 0) )
     154             :             {
     155           0 :                 for (SCCOL j=0; (j<nSubTotals[i]) && bEqual; j++)
     156             :                 {
     157             :                     bEqual =   bEqual
     158           0 :                             && (pSubTotals[i][j] == rOther.pSubTotals[i][j])
     159           0 :                             && (pFunctions[i][j] == rOther.pFunctions[i][j]);
     160             :                 }
     161             :             }
     162             :         }
     163             :     }
     164             : 
     165           0 :     return bEqual;
     166             : }
     167             : 
     168           0 : void ScSubTotalParam::SetSubTotals( sal_uInt16 nGroup,
     169             :                                     const SCCOL* ptrSubTotals,
     170             :                                     const ScSubTotalFunc* ptrFunctions,
     171             :                                     sal_uInt16 nCount )
     172             : {
     173             :     OSL_ENSURE( (nGroup <= MAXSUBTOTAL),
     174             :                 "ScSubTotalParam::SetSubTotals(): nGroup > MAXSUBTOTAL!" );
     175             :     OSL_ENSURE( ptrSubTotals,
     176             :                 "ScSubTotalParam::SetSubTotals(): ptrSubTotals == NULL!" );
     177             :     OSL_ENSURE( ptrFunctions,
     178             :                 "ScSubTotalParam::SetSubTotals(): ptrFunctions == NULL!" );
     179             :     OSL_ENSURE( (nCount > 0),
     180             :                 "ScSubTotalParam::SetSubTotals(): nCount <= 0!" );
     181             : 
     182           0 :     if ( ptrSubTotals && ptrFunctions && (nCount > 0) && (nGroup <= MAXSUBTOTAL) )
     183             :     {
     184             :         // 0 is interpreted as 1, otherwise decrementing the array index
     185           0 :         if (nGroup != 0)
     186           0 :             nGroup--;
     187             : 
     188           0 :         delete [] pSubTotals[nGroup];
     189           0 :         delete [] pFunctions[nGroup];
     190             : 
     191           0 :         pSubTotals[nGroup] = new SCCOL      [nCount];
     192           0 :         pFunctions[nGroup] = new ScSubTotalFunc [nCount];
     193           0 :         nSubTotals[nGroup] = static_cast<SCCOL>(nCount);
     194             : 
     195           0 :         for ( sal_uInt16 i=0; i<nCount; i++ )
     196             :         {
     197           0 :             pSubTotals[nGroup][i] = ptrSubTotals[i];
     198           0 :             pFunctions[nGroup][i] = ptrFunctions[i];
     199             :         }
     200             :     }
     201         156 : }
     202             : 
     203             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11