LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/tools - Scaling.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 89 31.5 %
Date: 2012-12-27 Functions: 14 50 28.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             :  * 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             : #include "Scaling.hxx"
      21             : #include <rtl/math.hxx>
      22             : #include "com/sun/star/uno/RuntimeException.hpp"
      23             : 
      24             : namespace
      25             : {
      26             : 
      27           1 : static const ::rtl::OUString lcl_aServiceName_Logarithmic(
      28             :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LogarithmicScaling" ));
      29           1 : static const ::rtl::OUString lcl_aServiceName_Exponential(
      30             :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.ExponentialScaling" ));
      31           1 : static const ::rtl::OUString lcl_aServiceName_Linear(
      32             :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LinearScaling" ));
      33           1 : static const ::rtl::OUString lcl_aServiceName_Power(
      34             :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.PowerScaling" ));
      35             : 
      36             : }
      37             : 
      38             : //.............................................................................
      39             : namespace chart
      40             : {
      41             : //.............................................................................
      42             : using namespace ::com::sun::star;
      43             : using namespace ::com::sun::star::chart2;
      44             : 
      45           0 : LogarithmicScaling::LogarithmicScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
      46             :         m_fBase( 10.0 ),
      47             :         m_fLogOfBase( log( 10.0 ) ),
      48           0 :         m_xContext( xContext )
      49             : {
      50           0 : }
      51             : 
      52           0 : LogarithmicScaling::LogarithmicScaling( double fBase ) :
      53             :         m_fBase( fBase ),
      54           0 :         m_fLogOfBase( log( fBase ) )
      55             : {
      56           0 : }
      57             : 
      58           0 : LogarithmicScaling::~LogarithmicScaling()
      59             : {
      60           0 : }
      61             : 
      62             :     double SAL_CALL
      63           0 : LogarithmicScaling::doScaling( double value )
      64             :     throw (uno::RuntimeException)
      65             : {
      66             :     double fResult;
      67           0 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
      68           0 :         ::rtl::math::setNan( & fResult );
      69             :     else
      70           0 :         fResult = log( value ) / m_fLogOfBase;
      71           0 :     return fResult;
      72             : }
      73             : 
      74             :     uno::Reference< XScaling > SAL_CALL
      75           0 : LogarithmicScaling::getInverseScaling()
      76             :     throw (uno::RuntimeException)
      77             : {
      78           0 :     return new ExponentialScaling( m_fBase );
      79             : }
      80             : 
      81             :     ::rtl::OUString SAL_CALL
      82           0 : LogarithmicScaling::getServiceName()
      83             :     throw (uno::RuntimeException)
      84             : {
      85           0 :     return lcl_aServiceName_Logarithmic;
      86             : }
      87             : 
      88           0 : uno::Sequence< ::rtl::OUString > LogarithmicScaling::getSupportedServiceNames_Static()
      89             : {
      90           0 :     return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Logarithmic, 1 );
      91             : }
      92             : 
      93             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
      94           3 : APPHELPER_XSERVICEINFO_IMPL( LogarithmicScaling, lcl_aServiceName_Logarithmic )
      95             : 
      96             : // ----------------------------------------
      97             : 
      98           0 : ExponentialScaling::ExponentialScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
      99             :         m_fBase( 10.0 ),
     100           0 :         m_xContext( xContext )
     101             : {
     102           0 : }
     103             : 
     104           0 : ExponentialScaling::ExponentialScaling( double fBase ) :
     105           0 :         m_fBase( fBase )
     106             : {
     107           0 : }
     108             : 
     109           0 : ExponentialScaling::~ExponentialScaling()
     110             : {
     111           0 : }
     112             : 
     113             :     double SAL_CALL
     114           0 : ExponentialScaling::doScaling( double value )
     115             :     throw (uno::RuntimeException)
     116             : {
     117             :     double fResult;
     118           0 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
     119           0 :         ::rtl::math::setNan( & fResult );
     120             :     else
     121           0 :         fResult = pow( m_fBase, value );
     122           0 :     return fResult;
     123             : }
     124             : 
     125             :     uno::Reference< XScaling > SAL_CALL
     126           0 : ExponentialScaling::getInverseScaling()
     127             :     throw (uno::RuntimeException)
     128             : {
     129           0 :     return new LogarithmicScaling( m_fBase );
     130             : }
     131             : 
     132             :     ::rtl::OUString SAL_CALL
     133           0 : ExponentialScaling::getServiceName()
     134             :     throw (uno::RuntimeException)
     135             : {
     136           0 :     return lcl_aServiceName_Exponential;
     137             : }
     138             : 
     139           0 : uno::Sequence< ::rtl::OUString > ExponentialScaling::getSupportedServiceNames_Static()
     140             : {
     141           0 :     return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Exponential, 1 );
     142             : }
     143             : 
     144             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     145           3 : APPHELPER_XSERVICEINFO_IMPL( ExponentialScaling, lcl_aServiceName_Exponential )
     146             : 
     147             : // ----------------------------------------
     148             : 
     149          40 : LinearScaling::LinearScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
     150             :         m_fSlope( 1.0 ),
     151             :         m_fOffset( 0.0 ),
     152          40 :         m_xContext( xContext )
     153          40 : {}
     154             : 
     155         574 : LinearScaling::LinearScaling( double fSlope, double fOffset ) :
     156             :         m_fSlope( fSlope ),
     157         574 :         m_fOffset( fOffset )
     158         574 : {}
     159             : 
     160        1228 : LinearScaling::~LinearScaling()
     161        1228 : {}
     162             : 
     163       18081 : double SAL_CALL LinearScaling::doScaling( double value )
     164             :     throw (uno::RuntimeException)
     165             : {
     166             :     double fResult;
     167       18081 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
     168           0 :         ::rtl::math::setNan( & fResult );
     169             :     else
     170       18081 :         fResult = m_fOffset + m_fSlope * value;
     171       18081 :     return fResult;
     172             : }
     173             : 
     174             : uno::Reference< XScaling > SAL_CALL
     175         492 :     LinearScaling::getInverseScaling()
     176             :     throw (uno::RuntimeException)
     177             : {
     178             :     // ToDo: ApproxEqual ?
     179         492 :     if( m_fSlope == 0 )
     180           0 :         throw uno::RuntimeException();
     181             : 
     182         492 :     return new LinearScaling( 1.0 / m_fSlope, m_fOffset / m_fSlope );
     183             : }
     184             : 
     185             :     ::rtl::OUString SAL_CALL
     186         164 : LinearScaling::getServiceName()
     187             :     throw (uno::RuntimeException)
     188             : {
     189         164 :     return lcl_aServiceName_Linear;
     190             : }
     191             : 
     192           1 : uno::Sequence< ::rtl::OUString > LinearScaling::getSupportedServiceNames_Static()
     193             : {
     194           1 :     return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Linear, 1 );
     195             : }
     196             : 
     197             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     198           3 : APPHELPER_XSERVICEINFO_IMPL( LinearScaling, lcl_aServiceName_Linear )
     199             : 
     200             : // ----------------------------------------
     201             : 
     202           0 : PowerScaling::PowerScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
     203             :         m_fExponent( 10.0 ),
     204           0 :         m_xContext( xContext )
     205           0 : {}
     206             : 
     207           0 : PowerScaling::PowerScaling( double fExponent ) :
     208           0 :         m_fExponent( fExponent )
     209           0 : {}
     210             : 
     211           0 : PowerScaling::~PowerScaling()
     212           0 : {}
     213             : 
     214           0 : double SAL_CALL PowerScaling::doScaling( double value )
     215             :     throw (uno::RuntimeException)
     216             : {
     217             :     double fResult;
     218           0 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
     219           0 :         ::rtl::math::setNan( & fResult );
     220             :     else
     221           0 :         fResult = pow( value, m_fExponent );
     222           0 :     return fResult;
     223             : }
     224             : 
     225             : uno::Reference< XScaling > SAL_CALL
     226           0 :     PowerScaling::getInverseScaling()
     227             :     throw (uno::RuntimeException)
     228             : {
     229             :     // ToDo: ApproxEqual ?
     230           0 :     if( m_fExponent == 0 )
     231           0 :         throw uno::RuntimeException();
     232             : 
     233           0 :     return new PowerScaling( 1.0 / m_fExponent );
     234             : }
     235             : 
     236             :     ::rtl::OUString SAL_CALL
     237           0 : PowerScaling::getServiceName()
     238             :     throw (uno::RuntimeException)
     239             : {
     240           0 :     return lcl_aServiceName_Power;
     241             : }
     242             : 
     243           0 : uno::Sequence< ::rtl::OUString > PowerScaling::getSupportedServiceNames_Static()
     244             : {
     245           0 :     return uno::Sequence< ::rtl::OUString >( & lcl_aServiceName_Power, 1 );
     246             : }
     247             : 
     248             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     249           3 : APPHELPER_XSERVICEINFO_IMPL( PowerScaling, lcl_aServiceName_Power )
     250             : 
     251             : //.............................................................................
     252           3 : } //namespace chart
     253             : //.............................................................................
     254             : 
     255             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10