LCOV - code coverage report
Current view: top level - chart2/source/tools - Scaling.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 99 128 77.3 %
Date: 2015-06-13 12:38:46 Functions: 42 52 80.8 %
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             : #include <cppuhelper/supportsservice.hxx>
      24             : 
      25             : namespace
      26             : {
      27             : 
      28             : static const char lcl_aServiceName_Logarithmic[] = "com.sun.star.chart2.LogarithmicScaling";
      29             : static const char lcl_aServiceName_Exponential[] = "com.sun.star.chart2.ExponentialScaling";
      30             : static const char lcl_aServiceName_Linear[] = "com.sun.star.chart2.LinearScaling";
      31             : static const char lcl_aServiceName_Power[] = "com.sun.star.chart2.PowerScaling";
      32             : 
      33             : }
      34             : 
      35             : namespace chart
      36             : {
      37             : using namespace ::com::sun::star;
      38             : using namespace ::com::sun::star::chart2;
      39             : 
      40           3 : LogarithmicScaling::LogarithmicScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
      41             :         m_fBase( 10.0 ),
      42             :         m_fLogOfBase( log( 10.0 ) ),
      43           3 :         m_xContext( xContext )
      44             : {
      45           3 : }
      46             : 
      47           3 : LogarithmicScaling::LogarithmicScaling( double fBase ) :
      48             :         m_fBase( fBase ),
      49           3 :         m_fLogOfBase( log( fBase ) )
      50             : {
      51           3 : }
      52             : 
      53          10 : LogarithmicScaling::~LogarithmicScaling()
      54             : {
      55          10 : }
      56             : 
      57       64909 : double SAL_CALL LogarithmicScaling::doScaling( double value )
      58             :     throw (uno::RuntimeException, std::exception)
      59             : {
      60             :     double fResult;
      61       64909 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
      62           0 :         ::rtl::math::setNan( & fResult );
      63             :     else
      64       64909 :         fResult = log( value ) / m_fLogOfBase;
      65       64909 :     return fResult;
      66             : }
      67             : 
      68        1907 : uno::Reference< XScaling > SAL_CALL LogarithmicScaling::getInverseScaling()
      69             :     throw (uno::RuntimeException, std::exception)
      70             : {
      71        1907 :     return new ExponentialScaling( m_fBase );
      72             : }
      73             : 
      74         786 : OUString SAL_CALL LogarithmicScaling::getServiceName()
      75             :     throw (uno::RuntimeException, std::exception)
      76             : {
      77         786 :     return OUString(lcl_aServiceName_Logarithmic);
      78             : }
      79             : 
      80           1 : uno::Sequence< OUString > LogarithmicScaling::getSupportedServiceNames_Static()
      81             : {
      82           1 :     uno::Sequence< OUString > aSeq(1);
      83           1 :     aSeq.getArray()[0] = lcl_aServiceName_Logarithmic;
      84           1 :     return aSeq;
      85             : }
      86             : 
      87             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
      88           1 : OUString SAL_CALL LogarithmicScaling::getImplementationName()
      89             :     throw( css::uno::RuntimeException, std::exception )
      90             : {
      91           1 :     return getImplementationName_Static();
      92             : }
      93             : 
      94           1 : OUString LogarithmicScaling::getImplementationName_Static()
      95             : {
      96           1 :     return OUString(lcl_aServiceName_Logarithmic);
      97             : }
      98             : 
      99           0 : sal_Bool SAL_CALL LogarithmicScaling::supportsService( const OUString& rServiceName )
     100             :     throw( css::uno::RuntimeException, std::exception )
     101             : {
     102           0 :     return cppu::supportsService(this, rServiceName);
     103             : }
     104             : 
     105           1 : css::uno::Sequence< OUString > SAL_CALL LogarithmicScaling::getSupportedServiceNames()
     106             :     throw( css::uno::RuntimeException, std::exception )
     107             : {
     108           1 :     return getSupportedServiceNames_Static();
     109             : }
     110             : 
     111           1 : ExponentialScaling::ExponentialScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
     112             :         m_fBase( 10.0 ),
     113           1 :         m_xContext( xContext )
     114             : {
     115           1 : }
     116             : 
     117        1907 : ExponentialScaling::ExponentialScaling( double fBase ) :
     118        1907 :         m_fBase( fBase )
     119             : {
     120        1907 : }
     121             : 
     122        3814 : ExponentialScaling::~ExponentialScaling()
     123             : {
     124        3814 : }
     125             : 
     126        8916 : double SAL_CALL ExponentialScaling::doScaling( double value )
     127             :     throw (uno::RuntimeException, std::exception)
     128             : {
     129             :     double fResult;
     130        8916 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
     131           0 :         ::rtl::math::setNan( & fResult );
     132             :     else
     133        8916 :         fResult = pow( m_fBase, value );
     134        8916 :     return fResult;
     135             : }
     136             : 
     137           0 : uno::Reference< XScaling > SAL_CALL ExponentialScaling::getInverseScaling()
     138             :     throw (uno::RuntimeException, std::exception)
     139             : {
     140           0 :     return new LogarithmicScaling( m_fBase );
     141             : }
     142             : 
     143           0 : OUString SAL_CALL ExponentialScaling::getServiceName()
     144             :     throw (uno::RuntimeException, std::exception)
     145             : {
     146           0 :     return OUString(lcl_aServiceName_Exponential);
     147             : }
     148             : 
     149           1 : uno::Sequence< OUString > ExponentialScaling::getSupportedServiceNames_Static()
     150             : {
     151           1 :     uno::Sequence< OUString > aSeq(1);
     152           1 :     aSeq.getArray()[0] = lcl_aServiceName_Exponential;
     153           1 :     return aSeq;
     154             : }
     155             : 
     156             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     157           1 : OUString SAL_CALL ExponentialScaling::getImplementationName()
     158             :     throw( css::uno::RuntimeException, std::exception )
     159             : {
     160           1 :     return getImplementationName_Static();
     161             : }
     162             : 
     163           1 : OUString ExponentialScaling::getImplementationName_Static()
     164             : {
     165           1 :     return OUString(lcl_aServiceName_Exponential);
     166             : }
     167             : 
     168           0 : sal_Bool SAL_CALL ExponentialScaling::supportsService( const OUString& rServiceName )
     169             :     throw( css::uno::RuntimeException, std::exception )
     170             : {
     171           0 :     return cppu::supportsService(this, rServiceName);
     172             : }
     173             : 
     174           1 : css::uno::Sequence< OUString > SAL_CALL ExponentialScaling::getSupportedServiceNames()
     175             :     throw( css::uno::RuntimeException, std::exception )
     176             : {
     177           1 :     return getSupportedServiceNames_Static();
     178             : }
     179             : 
     180         258 : LinearScaling::LinearScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
     181             :         m_fSlope( 1.0 ),
     182             :         m_fOffset( 0.0 ),
     183         258 :         m_xContext( xContext )
     184         258 : {}
     185             : 
     186        8713 : LinearScaling::LinearScaling( double fSlope, double fOffset ) :
     187             :         m_fSlope( fSlope ),
     188        8713 :         m_fOffset( fOffset )
     189        8713 : {}
     190             : 
     191       17858 : LinearScaling::~LinearScaling()
     192       17858 : {}
     193             : 
     194      363796 : double SAL_CALL LinearScaling::doScaling( double value )
     195             :     throw (uno::RuntimeException, std::exception)
     196             : {
     197             :     double fResult;
     198      363796 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
     199          42 :         ::rtl::math::setNan( & fResult );
     200             :     else
     201      363754 :         fResult = m_fOffset + m_fSlope * value;
     202      363796 :     return fResult;
     203             : }
     204             : 
     205             : uno::Reference< XScaling > SAL_CALL
     206        8415 :     LinearScaling::getInverseScaling()
     207             :     throw (uno::RuntimeException, std::exception)
     208             : {
     209             :     // ToDo: ApproxEqual ?
     210        8415 :     if( m_fSlope == 0 )
     211           0 :         throw uno::RuntimeException();
     212             : 
     213        8415 :     return new LinearScaling( 1.0 / m_fSlope, m_fOffset / m_fSlope );
     214             : }
     215             : 
     216        5264 : OUString SAL_CALL LinearScaling::getServiceName()
     217             :     throw (uno::RuntimeException, std::exception)
     218             : {
     219        5264 :     return OUString(lcl_aServiceName_Linear);
     220             : }
     221             : 
     222           1 : uno::Sequence< OUString > LinearScaling::getSupportedServiceNames_Static()
     223             : {
     224           1 :     uno::Sequence< OUString > aSeq(1);
     225           1 :     aSeq.getArray()[0] = lcl_aServiceName_Linear;
     226           1 :     return aSeq;
     227             : }
     228             : 
     229             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     230           1 : OUString SAL_CALL LinearScaling::getImplementationName()
     231             :     throw( css::uno::RuntimeException, std::exception )
     232             : {
     233           1 :     return getImplementationName_Static();
     234             : }
     235             : 
     236           1 : OUString LinearScaling::getImplementationName_Static()
     237             : {
     238           1 :     return OUString(lcl_aServiceName_Linear) ;
     239             : }
     240             : 
     241           0 : sal_Bool SAL_CALL LinearScaling::supportsService( const OUString& rServiceName )
     242             :     throw( css::uno::RuntimeException, std::exception )
     243             : {
     244           0 :     return cppu::supportsService(this, rServiceName);
     245             : }
     246             : 
     247           1 : css::uno::Sequence< OUString > SAL_CALL LinearScaling::getSupportedServiceNames()
     248             :     throw( css::uno::RuntimeException, std::exception )
     249             : {
     250           1 :     return getSupportedServiceNames_Static();
     251             : }
     252             : 
     253           1 : PowerScaling::PowerScaling( const uno::Reference< uno::XComponentContext > & xContext ) :
     254             :         m_fExponent( 10.0 ),
     255           1 :         m_xContext( xContext )
     256           1 : {}
     257             : 
     258           0 : PowerScaling::PowerScaling( double fExponent ) :
     259           0 :         m_fExponent( fExponent )
     260           0 : {}
     261             : 
     262           2 : PowerScaling::~PowerScaling()
     263           2 : {}
     264             : 
     265           0 : double SAL_CALL PowerScaling::doScaling( double value )
     266             :     throw (uno::RuntimeException, std::exception)
     267             : {
     268             :     double fResult;
     269           0 :     if( ::rtl::math::isNan( value ) || ::rtl::math::isInf( value ) )
     270           0 :         ::rtl::math::setNan( & fResult );
     271             :     else
     272           0 :         fResult = pow( value, m_fExponent );
     273           0 :     return fResult;
     274             : }
     275             : 
     276             : uno::Reference< XScaling > SAL_CALL
     277           0 :     PowerScaling::getInverseScaling()
     278             :     throw (uno::RuntimeException, std::exception)
     279             : {
     280             :     // ToDo: ApproxEqual ?
     281           0 :     if( m_fExponent == 0 )
     282           0 :         throw uno::RuntimeException();
     283             : 
     284           0 :     return new PowerScaling( 1.0 / m_fExponent );
     285             : }
     286             : 
     287             :     OUString SAL_CALL
     288           0 : PowerScaling::getServiceName()
     289             :     throw (uno::RuntimeException, std::exception)
     290             : {
     291           0 :     return OUString(lcl_aServiceName_Power);
     292             : }
     293             : 
     294           1 : uno::Sequence< OUString > PowerScaling::getSupportedServiceNames_Static()
     295             : {
     296           1 :     uno::Sequence< OUString > aSeq(1);
     297           1 :     aSeq.getArray()[0] = lcl_aServiceName_Power;
     298           1 :     return aSeq;
     299             : }
     300             : 
     301             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     302           1 : OUString SAL_CALL PowerScaling::getImplementationName()
     303             :     throw( css::uno::RuntimeException, std::exception )
     304             : {
     305           1 :     return getImplementationName_Static();
     306             : }
     307             : 
     308           1 : OUString PowerScaling::getImplementationName_Static()
     309             : {
     310           1 :     return OUString(lcl_aServiceName_Power);
     311             : }
     312             : 
     313           0 : sal_Bool SAL_CALL PowerScaling::supportsService( const OUString& rServiceName )
     314             :     throw( css::uno::RuntimeException, std::exception )
     315             : {
     316           0 :     return cppu::supportsService(this, rServiceName);
     317             : }
     318             : 
     319           1 : css::uno::Sequence< OUString > SAL_CALL PowerScaling::getSupportedServiceNames()
     320             :     throw( css::uno::RuntimeException, std::exception )
     321             : {
     322           1 :     return getSupportedServiceNames_Static();
     323             : }
     324             : 
     325             : } //namespace chart
     326             : 
     327             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     328         258 : com_sun_star_chart2_LinearScaling_get_implementation(css::uno::XComponentContext *context,
     329             :         css::uno::Sequence<css::uno::Any> const &)
     330             : {
     331         258 :     return cppu::acquire(new chart::LinearScaling(context));
     332             : }
     333             : 
     334             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     335           1 : com_sun_star_chart2_ExponentialScaling_get_implementation(css::uno::XComponentContext *context,
     336             :         css::uno::Sequence<css::uno::Any> const &)
     337             : {
     338           1 :     return cppu::acquire(new chart::ExponentialScaling(context));
     339             : }
     340             : 
     341             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     342           3 : com_sun_star_chart2_LogarithmicScaling_get_implementation(css::uno::XComponentContext *context,
     343             :         css::uno::Sequence<css::uno::Any> const &)
     344             : {
     345           3 :     return cppu::acquire(new chart::LogarithmicScaling(context));
     346             : }
     347             : 
     348             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     349           1 : com_sun_star_chart2_PowerScaling_get_implementation(css::uno::XComponentContext *context,
     350             :         css::uno::Sequence<css::uno::Any> const &)
     351             : {
     352           1 :     return cppu::acquire(new chart::PowerScaling(context));
     353             : }
     354             : 
     355             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11