LCOV - code coverage report
Current view: top level - chart2/source/tools - InternalData.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 127 256 49.6 %
Date: 2012-08-25 Functions: 21 33 63.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 89 412 21.6 %

           Branch data     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                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include "InternalData.hxx"
      22                 :            : #include "ResId.hxx"
      23                 :            : #include "Strings.hrc"
      24                 :            : #include "macros.hxx"
      25                 :            : 
      26                 :            : #include <rtl/math.hxx>
      27                 :            : #include <algorithm>
      28                 :            : 
      29                 :            : using ::com::sun::star::uno::Sequence;
      30                 :            : using ::rtl::OUString;
      31                 :            : 
      32                 :            : using namespace ::com::sun::star;
      33                 :            : using namespace ::std;
      34                 :            : 
      35                 :            : namespace chart
      36                 :            : {
      37                 :            : 
      38                 :            : // ----------------------------------------
      39                 :            : namespace
      40                 :            : {
      41                 :        108 : struct lcl_NumberedStringGenerator
      42                 :            : {
      43                 :        108 :     lcl_NumberedStringGenerator( const OUString & rStub, const OUString & rWildcard ) :
      44                 :            :             m_aStub( rStub ),
      45                 :            :             m_nCounter( 0 ),
      46                 :        108 :             m_nStubStartIndex( rStub.indexOf( rWildcard )),
      47                 :        216 :             m_nWildcardLength( rWildcard.getLength())
      48                 :            :     {
      49                 :        108 :     }
      50                 :        378 :     vector< uno::Any > operator()()
      51                 :            :     {
      52                 :        378 :         vector< uno::Any > aRet(1);
      53         [ +  - ]:        378 :         aRet[0] = uno::makeAny( m_aStub.replaceAt( m_nStubStartIndex, m_nWildcardLength, OUString::valueOf( ++m_nCounter )) );
      54                 :        378 :         return aRet;
      55                 :            :     }
      56                 :            : private:
      57                 :            :     OUString m_aStub;
      58                 :            :     sal_Int32 m_nCounter;
      59                 :            :     const sal_Int32 m_nStubStartIndex;
      60                 :            :     const sal_Int32 m_nWildcardLength;
      61                 :            : };
      62                 :            : 
      63                 :            : template< typename T >
      64                 :       6760 :     Sequence< T > lcl_ValarrayToSequence( const ::std::valarray< T > & rValarray )
      65                 :            : {
      66                 :            :     // is there a more elegant way of conversion?
      67                 :       6760 :     Sequence< T > aResult( rValarray.size());
      68 [ +  - ][ +  + ]:      33752 :     for( size_t i = 0; i < rValarray.size(); ++i )
      69 [ +  - ][ +  - ]:      26992 :         aResult[i] = rValarray[i];
      70                 :       6760 :     return aResult;
      71                 :            : }
      72                 :            : 
      73                 :            : } // anonymous namespace
      74                 :            : // ----------------------------------------
      75                 :            : 
      76                 :         75 : InternalData::InternalData()
      77                 :            :     : m_nColumnCount( 0 )
      78                 :            :     , m_nRowCount( 0 )
      79                 :            :     , m_aRowLabels( 0 )
      80 [ +  - ][ +  - ]:         75 :     , m_aColumnLabels( 0 )
      81                 :         75 : {}
      82                 :            : 
      83                 :            : static const double fDefaultData[] = {
      84                 :            :     9.10, 3.20, 4.54,
      85                 :            :     2.40, 8.80, 9.65,
      86                 :            :     3.10, 1.50, 3.70,
      87                 :            :     4.30, 9.02, 6.20
      88                 :            : };
      89                 :            : 
      90                 :         54 : void InternalData::createDefaultData()
      91                 :            : {
      92                 :         54 :     const sal_Int32 nRowCount = 4;
      93                 :         54 :     const sal_Int32 nColumnCount = 3;
      94                 :            : 
      95                 :         54 :     m_nRowCount = nRowCount;
      96                 :         54 :     m_nColumnCount = nColumnCount;
      97                 :         54 :     const sal_Int32 nSize = nColumnCount * nRowCount;
      98                 :            :     // @todo: localize this!
      99 [ +  - ][ +  - ]:         54 :     const OUString aRowName(SCH_RESSTR(STR_ROW_LABEL));
     100 [ +  - ][ +  - ]:         54 :     const OUString aColName(SCH_RESSTR(STR_COLUMN_LABEL));
     101                 :            : 
     102         [ +  - ]:         54 :     m_aData.resize( nSize );
     103         [ +  + ]:        702 :     for( sal_Int32 i=0; i<nSize; ++i )
     104         [ +  - ]:        648 :         m_aData[i] = fDefaultData[i];
     105                 :            : 
     106                 :         54 :     m_aRowLabels.clear();
     107         [ +  - ]:         54 :     m_aRowLabels.reserve( m_nRowCount );
     108                 :            :     generate_n( back_inserter( m_aRowLabels ), m_nRowCount,
     109 [ +  - ][ +  - ]:         54 :         lcl_NumberedStringGenerator( aRowName, C2U("%ROWNUMBER") ));
                 [ +  - ]
     110                 :            : 
     111                 :         54 :     m_aColumnLabels.clear();
     112         [ +  - ]:         54 :     m_aColumnLabels.reserve( m_nColumnCount );
     113                 :            :     generate_n( back_inserter( m_aColumnLabels ), m_nColumnCount,
     114 [ +  - ][ +  - ]:         54 :         lcl_NumberedStringGenerator( aColName, C2U("%COLUMNNUMBER") ));
                 [ +  - ]
     115                 :         54 : }
     116                 :            : 
     117                 :          0 : bool InternalData::isDefaultData()
     118                 :            : {
     119                 :            : 
     120 [ #  # ][ #  # ]:          0 :     if( m_nRowCount == 4 && m_nColumnCount == 3 )
     121                 :            :     {
     122         [ #  # ]:          0 :         for( sal_Int32 i=0; i<(4*3); ++i )
     123         [ #  # ]:          0 :             if( m_aData[i] != fDefaultData[i] )
     124                 :          0 :                 return false;
     125                 :            : 
     126                 :          0 :         return true;
     127                 :            :     }
     128                 :          0 :     return false;
     129                 :            : }
     130                 :            : 
     131                 :          0 : void InternalData::clearDefaultData()
     132                 :            : {
     133         [ #  # ]:          0 :     if( isDefaultData() )
     134                 :            :     {
     135                 :          0 :         m_nRowCount = m_nColumnCount = 1;
     136                 :          0 :         m_aData.resize( 1 );
     137                 :          0 :         m_aRowLabels.clear();
     138                 :          0 :         m_aColumnLabels.clear();
     139                 :            :     }
     140                 :          0 : }
     141                 :            : 
     142                 :         16 : void InternalData::setData( const Sequence< Sequence< double > >& rDataInRows )
     143                 :            : {
     144                 :         16 :     m_nRowCount = rDataInRows.getLength();
     145         [ +  - ]:         16 :     m_nColumnCount = (m_nRowCount ? rDataInRows[0].getLength() : 0);
     146                 :            : 
     147         [ +  + ]:         16 :     if( m_aRowLabels.size() != static_cast< sal_uInt32 >( m_nRowCount ))
     148         [ +  - ]:          6 :         m_aRowLabels.resize( m_nRowCount );
     149         [ +  + ]:         16 :     if( m_aColumnLabels.size() != static_cast< sal_uInt32 >( m_nColumnCount ))
     150         [ +  - ]:          6 :         m_aColumnLabels.resize( m_nColumnCount );
     151                 :            : 
     152         [ +  - ]:         16 :     m_aData.resize( m_nRowCount * m_nColumnCount );
     153                 :            :     double fNan;
     154                 :         16 :     ::rtl::math::setNan( & fNan );
     155                 :            :     // set all values to Nan
     156         [ +  - ]:         16 :     m_aData = fNan;
     157                 :            : 
     158         [ +  + ]:         80 :     for( sal_Int32 nRow=0; nRow<m_nRowCount; ++nRow )
     159                 :            :     {
     160                 :         64 :         int nDataIdx = nRow*m_nColumnCount;
     161         [ +  - ]:         64 :         const sal_Int32 nMax = ::std::min( rDataInRows[nRow].getLength(), m_nColumnCount );
     162         [ +  + ]:        256 :         for( sal_Int32 nCol=0; nCol < nMax; ++nCol )
     163                 :            :         {
     164         [ +  - ]:        192 :             m_aData[nDataIdx] = rDataInRows[nRow][nCol];
     165                 :        192 :             nDataIdx += 1;
     166                 :            :         }
     167                 :            :     }
     168                 :         16 : }
     169                 :            : 
     170                 :         12 : Sequence< Sequence< double > > InternalData::getData() const
     171                 :            : {
     172                 :         12 :     Sequence< Sequence< double > > aResult( m_nRowCount );
     173                 :            : 
     174         [ +  + ]:         60 :     for( sal_Int32 i=0; i<m_nRowCount; ++i )
     175         [ +  - ]:         48 :         aResult[i] = lcl_ValarrayToSequence< tDataType::value_type >(
     176 [ +  - ][ +  - ]:         96 :             m_aData[ ::std::slice( i*m_nColumnCount, m_nColumnCount, 1 ) ] );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     177                 :            : 
     178                 :         12 :     return aResult;
     179                 :            : }
     180                 :            : 
     181                 :       6712 : Sequence< double > InternalData::getColumnValues( sal_Int32 nColumnIndex ) const
     182                 :            : {
     183 [ +  - ][ +  - ]:       6712 :     if( nColumnIndex >= 0 && nColumnIndex < m_nColumnCount )
     184                 :            :         return lcl_ValarrayToSequence< tDataType::value_type >(
     185 [ +  - ][ +  - ]:       6712 :             m_aData[ ::std::slice( nColumnIndex, m_nRowCount, m_nColumnCount ) ] );
                 [ +  - ]
     186                 :       6712 :     return Sequence< double >();
     187                 :            : }
     188                 :          0 : Sequence< double > InternalData::getRowValues( sal_Int32 nRowIndex ) const
     189                 :            : {
     190 [ #  # ][ #  # ]:          0 :     if( nRowIndex >= 0 && nRowIndex < m_nRowCount )
     191                 :            :         return lcl_ValarrayToSequence< tDataType::value_type >(
     192 [ #  # ][ #  # ]:          0 :             m_aData[ ::std::slice( nRowIndex*m_nColumnCount, m_nColumnCount, 1 ) ] );
                 [ #  # ]
     193                 :          0 :     return Sequence< double >();
     194                 :            : }
     195                 :            : 
     196                 :        195 : void InternalData::setColumnValues( sal_Int32 nColumnIndex, const vector< double > & rNewData )
     197                 :            : {
     198         [ +  - ]:        195 :     if( nColumnIndex < 0 )
     199                 :        195 :         return;
     200         [ +  - ]:        195 :     enlargeData( nColumnIndex + 1, rNewData.size() );
     201                 :            : 
     202 [ +  - ][ +  - ]:        195 :     tDataType aSlice = m_aData[ ::std::slice( nColumnIndex, m_nRowCount, m_nColumnCount ) ];
                 [ +  - ]
     203         [ +  + ]:        780 :     for( vector< double >::size_type i = 0; i < rNewData.size(); ++i )
     204 [ +  - ][ +  - ]:        585 :         aSlice[i] = rNewData[i];
     205 [ +  - ][ +  - ]:        195 :     m_aData[ ::std::slice( nColumnIndex, m_nRowCount, m_nColumnCount ) ] = aSlice;
                 [ +  - ]
     206                 :            : }
     207                 :            : 
     208                 :          0 : void InternalData::setRowValues( sal_Int32 nRowIndex, const vector< double > & rNewData )
     209                 :            : {
     210         [ #  # ]:          0 :     if( nRowIndex < 0 )
     211                 :          0 :         return;
     212         [ #  # ]:          0 :     enlargeData( rNewData.size(), nRowIndex+1 );
     213                 :            : 
     214 [ #  # ][ #  # ]:          0 :     tDataType aSlice = m_aData[ ::std::slice( nRowIndex*m_nColumnCount, m_nColumnCount, 1 ) ];
                 [ #  # ]
     215         [ #  # ]:          0 :     for( vector< double >::size_type i = 0; i < rNewData.size(); ++i )
     216 [ #  # ][ #  # ]:          0 :         aSlice[i] = rNewData[i];
     217 [ #  # ][ #  # ]:          0 :     m_aData[ ::std::slice( nRowIndex*m_nColumnCount, m_nColumnCount, 1 ) ]= aSlice;
                 [ #  # ]
     218                 :            : }
     219                 :            : 
     220                 :        195 : void InternalData::setComplexColumnLabel( sal_Int32 nColumnIndex, const vector< uno::Any >& rComplexLabel )
     221                 :            : {
     222         [ -  + ]:        195 :     if( nColumnIndex < 0 )
     223                 :        195 :         return;
     224         [ -  + ]:        195 :     if( nColumnIndex >= static_cast< sal_Int32 >( m_aColumnLabels.size() ) )
     225                 :            :     {
     226                 :          0 :         m_aColumnLabels.resize(nColumnIndex+1);
     227                 :          0 :         enlargeData( nColumnIndex+1, 0 );
     228                 :            :     }
     229                 :        195 :     m_aColumnLabels[nColumnIndex]=rComplexLabel;
     230                 :            : }
     231                 :            : 
     232                 :          0 : void InternalData::setComplexRowLabel( sal_Int32 nRowIndex, const vector< uno::Any >& rComplexLabel )
     233                 :            : {
     234         [ #  # ]:          0 :     if( nRowIndex < 0 )
     235                 :          0 :         return;
     236         [ #  # ]:          0 :     if( nRowIndex >= static_cast< sal_Int32 >( m_aRowLabels.size() ) )
     237                 :            :     {
     238                 :          0 :         m_aRowLabels.resize(nRowIndex+1);
     239                 :          0 :         enlargeData( 0, nRowIndex+1 );
     240                 :            :     }
     241                 :          0 :     m_aRowLabels[nRowIndex] = rComplexLabel;
     242                 :            : }
     243                 :            : 
     244                 :       9277 : vector< uno::Any > InternalData::getComplexColumnLabel( sal_Int32 nColumnIndex ) const
     245                 :            : {
     246         [ +  - ]:       9277 :     if( nColumnIndex < static_cast< sal_Int32 >( m_aColumnLabels.size() ) )
     247                 :       9277 :         return m_aColumnLabels[nColumnIndex];
     248                 :            :     else
     249                 :       9277 :         return vector< uno::Any >();
     250                 :            : }
     251                 :          0 : vector< uno::Any > InternalData::getComplexRowLabel( sal_Int32 nRowIndex ) const
     252                 :            : {
     253         [ #  # ]:          0 :     if( nRowIndex < static_cast< sal_Int32 >( m_aRowLabels.size() ) )
     254                 :          0 :         return m_aRowLabels[nRowIndex];
     255                 :            :     else
     256                 :          0 :         return vector< uno::Any >();
     257                 :            : }
     258                 :            : 
     259                 :          0 : void InternalData::swapRowWithNext( sal_Int32 nRowIndex )
     260                 :            : {
     261         [ #  # ]:          0 :     if( nRowIndex < m_nRowCount - 1 )
     262                 :            :     {
     263                 :          0 :         const sal_Int32 nMax = m_nColumnCount;
     264         [ #  # ]:          0 :         for( sal_Int32 nColIdx=0; nColIdx<nMax; ++nColIdx )
     265                 :            :         {
     266                 :          0 :             size_t nIndex1 = nColIdx + nRowIndex*m_nColumnCount;
     267                 :          0 :             size_t nIndex2 = nIndex1 + m_nColumnCount;
     268         [ #  # ]:          0 :             double fTemp = m_aData[nIndex1];
     269 [ #  # ][ #  # ]:          0 :             m_aData[nIndex1] = m_aData[nIndex2];
     270         [ #  # ]:          0 :             m_aData[nIndex2] = fTemp;
     271                 :            :         }
     272                 :            : 
     273         [ #  # ]:          0 :         vector< uno::Any > aTemp( m_aRowLabels[nRowIndex] );
     274         [ #  # ]:          0 :         m_aRowLabels[nRowIndex] = m_aRowLabels[nRowIndex + 1];
     275         [ #  # ]:          0 :         m_aRowLabels[nRowIndex + 1] = aTemp;
     276                 :            :     }
     277                 :          0 : }
     278                 :            : 
     279                 :          0 : void InternalData::swapColumnWithNext( sal_Int32 nColumnIndex )
     280                 :            : {
     281         [ #  # ]:          0 :     if( nColumnIndex < m_nColumnCount - 1 )
     282                 :            :     {
     283                 :          0 :         const sal_Int32 nMax = m_nRowCount;
     284         [ #  # ]:          0 :         for( sal_Int32 nRowIdx=0; nRowIdx<nMax; ++nRowIdx )
     285                 :            :         {
     286                 :          0 :             size_t nIndex1 = nColumnIndex + nRowIdx*m_nColumnCount;
     287                 :          0 :             size_t nIndex2 = nIndex1 + 1;
     288         [ #  # ]:          0 :             double fTemp = m_aData[nIndex1];
     289 [ #  # ][ #  # ]:          0 :             m_aData[nIndex1] = m_aData[nIndex2];
     290         [ #  # ]:          0 :             m_aData[nIndex2] = fTemp;
     291                 :            :         }
     292                 :            : 
     293         [ #  # ]:          0 :         vector< uno::Any > aTemp( m_aColumnLabels[nColumnIndex] );
     294         [ #  # ]:          0 :         m_aColumnLabels[nColumnIndex] = m_aColumnLabels[nColumnIndex + 1];
     295         [ #  # ]:          0 :         m_aColumnLabels[nColumnIndex + 1] = aTemp;
     296                 :            :     }
     297                 :          0 : }
     298                 :            : 
     299                 :        226 : bool InternalData::enlargeData( sal_Int32 nColumnCount, sal_Int32 nRowCount )
     300                 :            : {
     301                 :        226 :     sal_Int32 nNewColumnCount( ::std::max<sal_Int32>( m_nColumnCount, nColumnCount ) );
     302                 :        226 :     sal_Int32 nNewRowCount( ::std::max<sal_Int32>( m_nRowCount, nRowCount ) );
     303                 :        226 :     sal_Int32 nNewSize( nNewColumnCount*nNewRowCount );
     304                 :            : 
     305                 :        226 :     bool bGrow = (nNewSize > m_nColumnCount*m_nRowCount);
     306                 :            : 
     307         [ -  + ]:        226 :     if( bGrow )
     308                 :            :     {
     309                 :            :         double fNan;
     310                 :          0 :         ::rtl::math::setNan( &fNan );
     311         [ #  # ]:          0 :         tDataType aNewData( fNan, nNewSize );
     312                 :            :         // copy old data
     313         [ #  # ]:          0 :         for( int nCol=0; nCol<m_nColumnCount; ++nCol )
     314                 :            :             static_cast< tDataType >(
     315                 :            :                 aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] ) =
     316 [ #  # ][ #  # ]:          0 :                 m_aData[ ::std::slice( nCol, m_nRowCount, m_nColumnCount ) ];
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     317                 :            : 
     318         [ #  # ]:          0 :         m_aData.resize( nNewSize );
     319         [ #  # ]:          0 :         m_aData = aNewData;
     320                 :            :     }
     321                 :        226 :     m_nColumnCount = nNewColumnCount;
     322                 :        226 :     m_nRowCount = nNewRowCount;
     323                 :        226 :     return bGrow;
     324                 :            : }
     325                 :            : 
     326                 :        195 : void InternalData::insertColumn( sal_Int32 nAfterIndex )
     327                 :            : {
     328                 :            :     // note: -1 is allowed, as we insert after the given index
     329                 :            :     OSL_ASSERT( nAfterIndex < m_nColumnCount && nAfterIndex >= -1 );
     330 [ +  - ][ +  - ]:        195 :     if( nAfterIndex >= m_nColumnCount || nAfterIndex < -1 )
     331                 :        195 :         return;
     332                 :        195 :     sal_Int32 nNewColumnCount = m_nColumnCount + 1;
     333                 :        195 :     sal_Int32 nNewSize( nNewColumnCount * m_nRowCount );
     334                 :            : 
     335                 :            :     double fNan;
     336                 :        195 :     ::rtl::math::setNan( &fNan );
     337         [ +  - ]:        195 :     tDataType aNewData( fNan, nNewSize );
     338                 :            : 
     339                 :            :     // copy old data
     340                 :        195 :     int nCol=0;
     341         [ +  + ]:       1365 :     for( ; nCol<=nAfterIndex; ++nCol )
     342                 :            :         aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] =
     343                 :            :             static_cast< tDataType >(
     344 [ +  - ][ +  - ]:       1170 :                 m_aData[ ::std::slice( nCol, m_nRowCount, m_nColumnCount ) ] );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     345         [ -  + ]:        195 :     for( ++nCol; nCol<nNewColumnCount; ++nCol )
     346                 :            :         aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] =
     347                 :            :             static_cast< tDataType >(
     348 [ #  # ][ #  # ]:          0 :                 m_aData[ ::std::slice( nCol - 1, m_nRowCount, m_nColumnCount ) ] );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     349                 :            : 
     350                 :        195 :     m_nColumnCount = nNewColumnCount;
     351         [ +  - ]:        195 :     m_aData.resize( nNewSize );
     352         [ +  - ]:        195 :     m_aData = aNewData;
     353                 :            : 
     354                 :            :     // labels
     355         [ +  - ]:        195 :     if( nAfterIndex < static_cast< sal_Int32 >( m_aColumnLabels.size()))
     356 [ +  - ][ +  - ]:        195 :         m_aColumnLabels.insert( m_aColumnLabels.begin() + (nAfterIndex + 1), vector< uno::Any >(1) );
                 [ +  - ]
     357                 :            : 
     358                 :            : #if OSL_DEBUG_LEVEL > 1
     359                 :            :     traceData();
     360                 :            : #endif
     361                 :            : }
     362                 :            : 
     363                 :        195 : sal_Int32 InternalData::appendColumn()
     364                 :            : {
     365                 :        195 :     insertColumn( getColumnCount() - 1 );
     366                 :        195 :     return getColumnCount() - 1;
     367                 :            : }
     368                 :            : 
     369                 :          0 : sal_Int32 InternalData::appendRow()
     370                 :            : {
     371                 :          0 :     insertRow( getRowCount() - 1 );
     372                 :          0 :     return getRowCount() - 1;
     373                 :            : }
     374                 :            : 
     375                 :          0 : void InternalData::insertRow( sal_Int32 nAfterIndex )
     376                 :            : {
     377                 :            :     // note: -1 is allowed, as we insert after the given index
     378                 :            :     OSL_ASSERT( nAfterIndex < m_nRowCount && nAfterIndex >= -1 );
     379 [ #  # ][ #  # ]:          0 :     if( nAfterIndex >= m_nRowCount || nAfterIndex < -1 )
     380                 :          0 :         return;
     381                 :          0 :     sal_Int32 nNewRowCount = m_nRowCount + 1;
     382                 :          0 :     sal_Int32 nNewSize( m_nColumnCount * nNewRowCount );
     383                 :            : 
     384                 :            :     double fNan;
     385                 :          0 :     ::rtl::math::setNan( &fNan );
     386         [ #  # ]:          0 :     tDataType aNewData( fNan, nNewSize );
     387                 :            : 
     388                 :            :     // copy old data
     389                 :          0 :     sal_Int32 nIndex = nAfterIndex + 1;
     390                 :            :     aNewData[ ::std::slice( 0, nIndex * m_nColumnCount, 1 ) ] =
     391                 :            :         static_cast< tDataType >(
     392 [ #  # ][ #  # ]:          0 :             m_aData[ ::std::slice( 0, nIndex * m_nColumnCount, 1 ) ] );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     393                 :            : 
     394         [ #  # ]:          0 :     if( nIndex < m_nRowCount )
     395                 :            :     {
     396                 :          0 :         sal_Int32 nRemainingCount = m_nColumnCount * (m_nRowCount - nIndex);
     397                 :            :         aNewData[ ::std::slice( (nIndex + 1) * m_nColumnCount, nRemainingCount, 1 ) ] =
     398                 :            :             static_cast< tDataType >(
     399 [ #  # ][ #  # ]:          0 :                 m_aData[ ::std::slice( nIndex * m_nColumnCount, nRemainingCount, 1 ) ] );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     400                 :            :     }
     401                 :            : 
     402                 :          0 :     m_nRowCount = nNewRowCount;
     403         [ #  # ]:          0 :     m_aData.resize( nNewSize );
     404         [ #  # ]:          0 :     m_aData = aNewData;
     405                 :            : 
     406                 :            :     // labels
     407         [ #  # ]:          0 :     if( nAfterIndex < static_cast< sal_Int32 >( m_aRowLabels.size()))
     408 [ #  # ][ #  # ]:          0 :         m_aRowLabels.insert( m_aRowLabels.begin() + nIndex, vector< uno::Any > (1));
                 [ #  # ]
     409                 :            : 
     410                 :            : #if OSL_DEBUG_LEVEL > 1
     411                 :            :     traceData();
     412                 :            : #endif
     413                 :            : }
     414                 :            : 
     415                 :          0 : void InternalData::deleteColumn( sal_Int32 nAtIndex )
     416                 :            : {
     417                 :            :     OSL_ASSERT( nAtIndex < m_nColumnCount && nAtIndex >= 0 );
     418 [ #  # ][ #  # ]:          0 :     if( nAtIndex >= m_nColumnCount || m_nColumnCount < 1 || nAtIndex < 0 )
                 [ #  # ]
     419                 :          0 :         return;
     420                 :          0 :     sal_Int32 nNewColumnCount = m_nColumnCount - 1;
     421                 :          0 :     sal_Int32 nNewSize( nNewColumnCount * m_nRowCount );
     422                 :            : 
     423                 :            :     double fNan;
     424                 :          0 :     ::rtl::math::setNan( &fNan );
     425         [ #  # ]:          0 :     tDataType aNewData( fNan, nNewSize );
     426                 :            : 
     427                 :            :     // copy old data
     428                 :          0 :     int nCol=0;
     429         [ #  # ]:          0 :     for( ; nCol<nAtIndex; ++nCol )
     430                 :            :         aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] =
     431                 :            :             static_cast< tDataType >(
     432 [ #  # ][ #  # ]:          0 :                 m_aData[ ::std::slice( nCol, m_nRowCount, m_nColumnCount ) ] );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     433         [ #  # ]:          0 :     for( ; nCol<nNewColumnCount; ++nCol )
     434                 :            :         aNewData[ ::std::slice( nCol, m_nRowCount, nNewColumnCount ) ] =
     435                 :            :             static_cast< tDataType >(
     436 [ #  # ][ #  # ]:          0 :                 m_aData[ ::std::slice( nCol + 1, m_nRowCount, m_nColumnCount ) ] );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     437                 :            : 
     438                 :          0 :     m_nColumnCount = nNewColumnCount;
     439         [ #  # ]:          0 :     m_aData.resize( nNewSize );
     440         [ #  # ]:          0 :     m_aData = aNewData;
     441                 :            : 
     442                 :            :     // labels
     443         [ #  # ]:          0 :     if( nAtIndex < static_cast< sal_Int32 >( m_aColumnLabels.size()))
     444 [ #  # ][ #  # ]:          0 :         m_aColumnLabels.erase( m_aColumnLabels.begin() + nAtIndex );
     445                 :            : 
     446                 :            : #if OSL_DEBUG_LEVEL > 1
     447                 :            :     traceData();
     448                 :            : #endif
     449                 :            : }
     450                 :            : 
     451                 :          0 : void InternalData::deleteRow( sal_Int32 nAtIndex )
     452                 :            : {
     453                 :            :     OSL_ASSERT( nAtIndex < m_nRowCount && nAtIndex >= 0 );
     454 [ #  # ][ #  # ]:          0 :     if( nAtIndex >= m_nRowCount || m_nRowCount < 1 || nAtIndex < 0 )
                 [ #  # ]
     455                 :          0 :         return;
     456                 :          0 :     sal_Int32 nNewRowCount = m_nRowCount - 1;
     457                 :          0 :     sal_Int32 nNewSize( m_nColumnCount * nNewRowCount );
     458                 :            : 
     459                 :            :     double fNan;
     460                 :          0 :     ::rtl::math::setNan( &fNan );
     461         [ #  # ]:          0 :     tDataType aNewData( fNan, nNewSize );
     462                 :            : 
     463                 :            :     // copy old data
     464                 :          0 :     sal_Int32 nIndex = nAtIndex;
     465         [ #  # ]:          0 :     if( nIndex )
     466                 :            :         aNewData[ ::std::slice( 0, nIndex * m_nColumnCount, 1 ) ] =
     467                 :            :             static_cast< tDataType >(
     468 [ #  # ][ #  # ]:          0 :                 m_aData[ ::std::slice( 0, nIndex * m_nColumnCount, 1 ) ] );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     469                 :            : 
     470         [ #  # ]:          0 :     if( nIndex < nNewRowCount )
     471                 :            :     {
     472                 :          0 :         sal_Int32 nRemainingCount = m_nColumnCount * (nNewRowCount - nIndex);
     473                 :            :         aNewData[ ::std::slice( nIndex * m_nColumnCount, nRemainingCount, 1 ) ] =
     474                 :            :             static_cast< tDataType >(
     475 [ #  # ][ #  # ]:          0 :                 m_aData[ ::std::slice( (nIndex + 1) * m_nColumnCount, nRemainingCount, 1 ) ] );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     476                 :            :     }
     477                 :            : 
     478                 :          0 :     m_nRowCount = nNewRowCount;
     479         [ #  # ]:          0 :     m_aData.resize( nNewSize );
     480         [ #  # ]:          0 :     m_aData = aNewData;
     481                 :            : 
     482                 :            :     // labels
     483         [ #  # ]:          0 :     if( nAtIndex < static_cast< sal_Int32 >( m_aRowLabels.size()))
     484 [ #  # ][ #  # ]:          0 :         m_aRowLabels.erase( m_aRowLabels.begin() + nAtIndex );
     485                 :            : 
     486                 :            : #if OSL_DEBUG_LEVEL > 1
     487                 :            :     traceData();
     488                 :            : #endif
     489                 :            : }
     490                 :            : 
     491                 :       2548 : sal_Int32 InternalData::getRowCount() const
     492                 :            : {
     493                 :       2548 :     return m_nRowCount;
     494                 :            : }
     495                 :            : 
     496                 :        488 : sal_Int32 InternalData::getColumnCount() const
     497                 :            : {
     498                 :        488 :     return m_nColumnCount;
     499                 :            : }
     500                 :            : 
     501                 :         23 : void InternalData::setComplexRowLabels( const vector< vector< uno::Any > >& rNewRowLabels )
     502                 :            : {
     503                 :         23 :     m_aRowLabels = rNewRowLabels;
     504                 :         23 :     sal_Int32 nNewRowCount = static_cast< sal_Int32 >( m_aRowLabels.size() );
     505         [ -  + ]:         23 :     if( nNewRowCount < m_nRowCount )
     506                 :          0 :         m_aRowLabels.resize( m_nRowCount );
     507                 :            :     else
     508                 :         23 :         enlargeData( 0, nNewRowCount );
     509                 :         23 : }
     510                 :            : 
     511                 :      11418 : vector< vector< uno::Any > > InternalData::getComplexRowLabels() const
     512                 :            : {
     513                 :      11418 :     return m_aRowLabels;
     514                 :            : }
     515                 :            : 
     516                 :          8 : void InternalData::setComplexColumnLabels( const vector< vector< uno::Any > >& rNewColumnLabels )
     517                 :            : {
     518                 :          8 :     m_aColumnLabels = rNewColumnLabels;
     519                 :          8 :     sal_Int32 nNewColumnCount = static_cast< sal_Int32 >( m_aColumnLabels.size() );
     520         [ -  + ]:          8 :     if( nNewColumnCount < m_nColumnCount )
     521                 :          0 :         m_aColumnLabels.resize( m_nColumnCount );
     522                 :            :     else
     523                 :          8 :         enlargeData( nNewColumnCount, 0 );
     524                 :          8 : }
     525                 :            : 
     526                 :         10 : vector< vector< uno::Any > > InternalData::getComplexColumnLabels() const
     527                 :            : {
     528                 :         10 :     return m_aColumnLabels;
     529                 :            : }
     530                 :            : 
     531                 :            : #if OSL_DEBUG_LEVEL > 1
     532                 :            : void InternalData::traceData() const
     533                 :            : {
     534                 :            :     OSL_TRACE( "InternalData: Data in rows" );
     535                 :            : 
     536                 :            :     for( sal_Int32 i=0; i<m_nRowCount; ++i )
     537                 :            :     {
     538                 :            :         tDataType aSlice( m_aData[ ::std::slice( i*m_nColumnCount, m_nColumnCount, 1 ) ] );
     539                 :            :         for( sal_Int32 j=0; j<m_nColumnCount; ++j )
     540                 :            :             OSL_TRACE( "%lf ", aSlice[j] );
     541                 :            :         OSL_TRACE( "\n" );
     542                 :            :     }
     543                 :            :     OSL_TRACE( "\n" );
     544                 :            : }
     545                 :            : #endif
     546                 :            : 
     547                 :            : } //  namespace chart
     548                 :            : 
     549                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10