LCOV - code coverage report
Current view: top level - sc/source/core/tool - unitconv.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 62 0.0 %
Date: 2012-08-25 Functions: 0 9 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 64 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <com/sun/star/uno/Any.hxx>
      30                 :            : #include <com/sun/star/uno/Sequence.hxx>
      31                 :            : 
      32                 :            : #include "unitconv.hxx"
      33                 :            : #include "global.hxx"
      34                 :            : #include "viewopti.hxx"         //! move ScLinkConfigItem to separate header!
      35                 :            : 
      36                 :            : using namespace utl;
      37                 :            : using namespace com::sun::star::uno;
      38                 :            : 
      39                 :            : using ::rtl::OUString;
      40                 :            : 
      41                 :            : // --------------------------------------------------------------------
      42                 :            : 
      43                 :            : const sal_Unicode cDelim = 0x01;        // Delimiter zwischen From und To
      44                 :            : 
      45                 :            : 
      46                 :            : // --- ScUnitConverterData --------------------------------------------
      47                 :            : 
      48                 :          0 : ScUnitConverterData::ScUnitConverterData(
      49                 :            :     const rtl::OUString& rFromUnit, const rtl::OUString& rToUnit, double fValue ) :
      50                 :            :     maIndexString(BuildIndexString(rFromUnit, rToUnit)),
      51                 :          0 :     mfValue(fValue) {}
      52                 :            : 
      53                 :          0 : ScUnitConverterData::ScUnitConverterData( const ScUnitConverterData& r ) :
      54                 :            :     maIndexString(r.maIndexString),
      55                 :          0 :     mfValue(r.mfValue) {}
      56                 :            : 
      57                 :          0 : ScUnitConverterData::~ScUnitConverterData() {}
      58                 :            : 
      59                 :          0 : double ScUnitConverterData::GetValue() const
      60                 :            : {
      61                 :          0 :     return mfValue;
      62                 :            : }
      63                 :            : 
      64                 :          0 : const rtl::OUString& ScUnitConverterData::GetIndexString() const
      65                 :            : {
      66                 :          0 :     return maIndexString;
      67                 :            : }
      68                 :            : 
      69                 :          0 : rtl::OUString ScUnitConverterData::BuildIndexString(
      70                 :            :     const rtl::OUString& rFromUnit, const rtl::OUString& rToUnit )
      71                 :            : {
      72         [ #  # ]:          0 :     rtl::OUStringBuffer aBuf(rFromUnit);
      73         [ #  # ]:          0 :     aBuf.append(cDelim);
      74         [ #  # ]:          0 :     aBuf.append(rToUnit);
      75         [ #  # ]:          0 :     return aBuf.makeStringAndClear();
      76                 :            : }
      77                 :            : 
      78                 :            : // --- ScUnitConverter ------------------------------------------------
      79                 :            : 
      80                 :            : #define CFGPATH_UNIT        "Office.Calc/UnitConversion"
      81                 :            : #define CFGSTR_UNIT_FROM    "FromUnit"
      82                 :            : #define CFGSTR_UNIT_TO      "ToUnit"
      83                 :            : #define CFGSTR_UNIT_FACTOR  "Factor"
      84                 :            : 
      85         [ #  # ]:          0 : ScUnitConverter::ScUnitConverter()
      86                 :            : {
      87                 :            :     //  read from configuration - "convert.ini" is no longer used
      88                 :            :     //! config item as member to allow change of values
      89                 :            : 
      90 [ #  # ][ #  # ]:          0 :     ScLinkConfigItem aConfigItem( OUString(RTL_CONSTASCII_USTRINGPARAM( CFGPATH_UNIT )) );
      91                 :            : 
      92                 :            :     // empty node name -> use the config item's path itself
      93                 :          0 :     OUString aEmptyString;
      94         [ #  # ]:          0 :     Sequence<OUString> aNodeNames = aConfigItem.GetNodeNames( aEmptyString );
      95                 :            : 
      96                 :          0 :     long nNodeCount = aNodeNames.getLength();
      97         [ #  # ]:          0 :     if ( nNodeCount )
      98                 :            :     {
      99                 :          0 :         const OUString* pNodeArray = aNodeNames.getConstArray();
     100         [ #  # ]:          0 :         Sequence<OUString> aValNames( nNodeCount * 3 );
     101         [ #  # ]:          0 :         OUString* pValNameArray = aValNames.getArray();
     102                 :          0 :         const OUString sSlash('/');
     103                 :            : 
     104                 :          0 :         long nIndex = 0;
     105         [ #  # ]:          0 :         for (long i=0; i<nNodeCount; i++)
     106                 :            :         {
     107                 :          0 :             OUString sPrefix = pNodeArray[i];
     108                 :          0 :             sPrefix += sSlash;
     109                 :            : 
     110                 :          0 :             pValNameArray[nIndex] = sPrefix;
     111         [ #  # ]:          0 :             pValNameArray[nIndex++] += OUString(RTL_CONSTASCII_USTRINGPARAM( CFGSTR_UNIT_FROM ));
     112                 :          0 :             pValNameArray[nIndex] = sPrefix;
     113         [ #  # ]:          0 :             pValNameArray[nIndex++] += OUString(RTL_CONSTASCII_USTRINGPARAM( CFGSTR_UNIT_TO ));
     114                 :          0 :             pValNameArray[nIndex] = sPrefix;
     115         [ #  # ]:          0 :             pValNameArray[nIndex++] += OUString(RTL_CONSTASCII_USTRINGPARAM( CFGSTR_UNIT_FACTOR ));
     116                 :          0 :         }
     117                 :            : 
     118         [ #  # ]:          0 :         Sequence<Any> aProperties = aConfigItem.GetProperties(aValNames);
     119                 :            : 
     120         [ #  # ]:          0 :         if (aProperties.getLength() == aValNames.getLength())
     121                 :            :         {
     122                 :          0 :             const Any* pProperties = aProperties.getConstArray();
     123                 :            : 
     124                 :          0 :             OUString sFromUnit;
     125                 :          0 :             OUString sToUnit;
     126                 :          0 :             double fFactor = 0;
     127                 :            : 
     128                 :          0 :             nIndex = 0;
     129         [ #  # ]:          0 :             for (long i=0; i<nNodeCount; i++)
     130                 :            :             {
     131                 :          0 :                 pProperties[nIndex++] >>= sFromUnit;
     132                 :          0 :                 pProperties[nIndex++] >>= sToUnit;
     133                 :          0 :                 pProperties[nIndex++] >>= fFactor;
     134                 :            : 
     135 [ #  # ][ #  # ]:          0 :                 ScUnitConverterData* pNew = new ScUnitConverterData( sFromUnit, sToUnit, fFactor );
     136                 :          0 :                 rtl::OUString aIndex  = pNew->GetIndexString();
     137         [ #  # ]:          0 :                 maData.insert(aIndex, pNew);
     138                 :          0 :             }
     139 [ #  # ][ #  # ]:          0 :         }
     140 [ #  # ][ #  # ]:          0 :     }
     141                 :          0 : }
     142                 :            : 
     143         [ #  # ]:          0 : ScUnitConverter::~ScUnitConverter() {}
     144                 :            : 
     145                 :          0 : bool ScUnitConverter::GetValue(
     146                 :            :     double& fValue, const rtl::OUString& rFromUnit, const rtl::OUString& rToUnit ) const
     147                 :            : {
     148         [ #  # ]:          0 :     rtl::OUString aIndex = ScUnitConverterData::BuildIndexString(rFromUnit, rToUnit);
     149         [ #  # ]:          0 :     MapType::const_iterator it = maData.find(aIndex);
     150 [ #  # ][ #  # ]:          0 :     if (it == maData.end())
                 [ #  # ]
     151                 :            :     {
     152                 :          0 :         fValue = 1.0;
     153                 :          0 :         return false;
     154                 :            :     }
     155                 :            : 
     156         [ #  # ]:          0 :     fValue = it->second->GetValue();
     157                 :          0 :     return true;
     158                 :            : }
     159                 :            : 
     160                 :            : 
     161                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10