LCOV - code coverage report
Current view: top level - chart2/source/tools - CachedDataSequence.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 28 153 18.3 %
Date: 2015-06-13 12:38:46 Functions: 12 34 35.3 %
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 "CachedDataSequence.hxx"
      21             : #include "macros.hxx"
      22             : #include "PropertyHelper.hxx"
      23             : #include "ContainerHelper.hxx"
      24             : #include "CommonFunctors.hxx"
      25             : #include "ModifyListenerHelper.hxx"
      26             : 
      27             : #include <comphelper/sequenceashashmap.hxx>
      28             : #include <cppuhelper/supportsservice.hxx>
      29             : 
      30             : #include <algorithm>
      31             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      32             : #include <rtl/math.hxx>
      33             : 
      34             : using namespace ::com::sun::star;
      35             : using namespace ::chart::ContainerHelper;
      36             : 
      37             : using ::com::sun::star::uno::Sequence;
      38             : using ::com::sun::star::uno::Reference;
      39             : using ::com::sun::star::uno::Any;
      40             : using ::osl::MutexGuard;
      41             : 
      42             : // necessary for MS compiler
      43             : using ::comphelper::OPropertyContainer;
      44             : using ::comphelper::OMutexAndBroadcastHelper;
      45             : using ::comphelper::OPropertyArrayUsageHelper;
      46             : using ::chart::impl::CachedDataSequence_Base;
      47             : 
      48             : namespace
      49             : {
      50             : static const char lcl_aServiceName[] = "com.sun.star.comp.chart.CachedDataSequence";
      51             : 
      52             : enum
      53             : {
      54             : //     PROP_SOURCE_IDENTIFIER,
      55             :     PROP_NUMBERFORMAT_KEY,
      56             :     PROP_PROPOSED_ROLE
      57             : };
      58             : }  // anonymous namespace
      59             : 
      60             : namespace chart
      61             : {
      62             : 
      63           0 : CachedDataSequence::CachedDataSequence()
      64           0 :         : OPropertyContainer( GetBroadcastHelper()),
      65           0 :           CachedDataSequence_Base( GetMutex()),
      66             :           m_eCurrentDataType( NUMERICAL ),
      67           0 :           m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
      68             : {
      69           0 :     registerProperties();
      70           0 : }
      71           1 : CachedDataSequence::CachedDataSequence( const Reference< uno::XComponentContext > & /*xContext*/ )
      72           1 :         : OPropertyContainer( GetBroadcastHelper()),
      73           1 :           CachedDataSequence_Base( GetMutex()),
      74             :           m_eCurrentDataType( MIXED ),
      75           3 :           m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder( ))
      76             : {
      77           1 :     registerProperties();
      78           1 : }
      79             : 
      80           0 : CachedDataSequence::CachedDataSequence( const OUString & rSingleText )
      81           0 :         : OPropertyContainer( GetBroadcastHelper()),
      82           0 :           CachedDataSequence_Base( GetMutex()),
      83             :           m_eCurrentDataType( TEXTUAL ),
      84           0 :           m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
      85             : {
      86           0 :     m_aTextualSequence.realloc(1);
      87           0 :     m_aTextualSequence[0] = rSingleText;
      88           0 :     registerProperties();
      89           0 : }
      90             : 
      91           0 : CachedDataSequence::CachedDataSequence( const CachedDataSequence & rSource )
      92             :         : OMutexAndBroadcastHelper(),
      93           0 :           OPropertyContainer( GetBroadcastHelper()),
      94             :           OPropertyArrayUsageHelper< CachedDataSequence >(),
      95           0 :           CachedDataSequence_Base( GetMutex()),
      96             :           m_nNumberFormatKey( rSource.m_nNumberFormatKey ),
      97             :           m_sRole( rSource.m_sRole ),
      98             :           m_eCurrentDataType( rSource.m_eCurrentDataType ),
      99           0 :           m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     100             : {
     101           0 :     switch( m_eCurrentDataType )
     102             :     {
     103             :         case TEXTUAL:
     104           0 :             m_aTextualSequence = rSource.m_aTextualSequence;
     105           0 :             break;
     106             :         case NUMERICAL:
     107           0 :             m_aNumericalSequence = rSource.m_aNumericalSequence;
     108           0 :             break;
     109             :         case MIXED:
     110           0 :             m_aMixedSequence = rSource.m_aMixedSequence;
     111           0 :             break;
     112             :     }
     113             : 
     114           0 :     registerProperties();
     115           0 : }
     116             : 
     117           2 : CachedDataSequence::~CachedDataSequence()
     118           2 : {}
     119             : 
     120           1 : void CachedDataSequence::registerProperties()
     121             : {
     122             :     registerProperty( "NumberFormatKey",
     123             :                       PROP_NUMBERFORMAT_KEY,
     124             :                       0,   // PropertyAttributes
     125             :                       & m_nNumberFormatKey,
     126           1 :                       cppu::UnoType<decltype(m_nNumberFormatKey)>::get() );
     127             : 
     128             :     registerProperty( "Role",
     129             :                       PROP_PROPOSED_ROLE,
     130             :                       0,   // PropertyAttributes
     131             :                       & m_sRole,
     132           1 :                       cppu::UnoType<decltype(m_sRole)>::get() );
     133           1 : }
     134             : 
     135           0 : Sequence< double > CachedDataSequence::Impl_getNumericalData() const
     136             : {
     137           0 :     if( m_eCurrentDataType == NUMERICAL )
     138           0 :         return m_aNumericalSequence;
     139             : 
     140           0 :     sal_Int32 nSize = ( m_eCurrentDataType == TEXTUAL )
     141           0 :         ? m_aTextualSequence.getLength()
     142           0 :         : m_aMixedSequence.getLength();
     143             : 
     144           0 :     Sequence< double > aResult( nSize );
     145           0 :     double * pResultArray = aResult.getArray();
     146             : 
     147           0 :     if( m_eCurrentDataType == TEXTUAL )
     148             :     {
     149           0 :         const OUString * pTextArray = m_aTextualSequence.getConstArray();
     150             :         ::std::transform( pTextArray, pTextArray + nSize,
     151             :                           pResultArray,
     152           0 :                           CommonFunctors::OUStringToDouble() );
     153             :     }
     154             :     else
     155             :     {
     156             :         OSL_ASSERT( m_eCurrentDataType == MIXED );
     157           0 :         const Any * pMixedArray = m_aMixedSequence.getConstArray();
     158             :         ::std::transform( pMixedArray, pMixedArray + nSize,
     159             :                           pResultArray,
     160           0 :                           CommonFunctors::AnyToDouble() );
     161             :     }
     162           0 :     return aResult;
     163             : }
     164             : 
     165           0 : Sequence< OUString > CachedDataSequence::Impl_getTextualData() const
     166             : {
     167           0 :     if( m_eCurrentDataType == TEXTUAL )
     168           0 :         return m_aTextualSequence;
     169             : 
     170           0 :     sal_Int32 nSize = ( m_eCurrentDataType == NUMERICAL )
     171           0 :         ? m_aNumericalSequence.getLength()
     172           0 :         : m_aMixedSequence.getLength();
     173             : 
     174           0 :     Sequence< OUString > aResult( nSize );
     175           0 :     OUString * pResultArray = aResult.getArray();
     176             : 
     177           0 :     if( m_eCurrentDataType == NUMERICAL )
     178             :     {
     179           0 :         const double * pTextArray = m_aNumericalSequence.getConstArray();
     180             :         ::std::transform( pTextArray, pTextArray + nSize,
     181             :                           pResultArray,
     182           0 :                           CommonFunctors::DoubleToOUString() );
     183             :     }
     184             :     else
     185             :     {
     186             :         OSL_ASSERT( m_eCurrentDataType == MIXED );
     187           0 :         const Any * pMixedArray = m_aMixedSequence.getConstArray();
     188             :         ::std::transform( pMixedArray, pMixedArray + nSize,
     189             :                           pResultArray,
     190           0 :                           CommonFunctors::AnyToString() );
     191             :     }
     192             : 
     193           0 :     return aResult;
     194             : }
     195             : 
     196           0 : Sequence< Any > CachedDataSequence::Impl_getMixedData() const
     197             : {
     198           0 :     if( m_eCurrentDataType == MIXED )
     199           0 :         return m_aMixedSequence;
     200             : 
     201           0 :     sal_Int32 nSize = ( m_eCurrentDataType == NUMERICAL )
     202           0 :         ? m_aNumericalSequence.getLength()
     203           0 :         : m_aTextualSequence.getLength();
     204             : 
     205           0 :     Sequence< Any > aResult( nSize );
     206           0 :     Any * pResultArray = aResult.getArray();
     207             : 
     208           0 :     if( m_eCurrentDataType == NUMERICAL )
     209             :     {
     210           0 :         const double * pTextArray = m_aNumericalSequence.getConstArray();
     211             :         ::std::transform( pTextArray, pTextArray + nSize,
     212             :                           pResultArray,
     213           0 :                           CommonFunctors::makeAny< double >() );
     214             :     }
     215             :     else
     216             :     {
     217             :         OSL_ASSERT( m_eCurrentDataType == TEXTUAL );
     218           0 :         const OUString * pMixedArray = m_aTextualSequence.getConstArray();
     219             :         ::std::transform( pMixedArray, pMixedArray + nSize,
     220             :                           pResultArray,
     221           0 :                           CommonFunctors::makeAny< OUString >() );
     222             :     }
     223             : 
     224           0 :     return aResult;
     225             : }
     226             : 
     227           1 : Sequence< OUString > CachedDataSequence::getSupportedServiceNames_Static()
     228             : {
     229           1 :     Sequence< OUString > aServices( 4 );
     230           1 :     aServices[ 0 ] = lcl_aServiceName;
     231           1 :     aServices[ 1 ] = "com.sun.star.chart2.data.DataSequence";
     232           1 :     aServices[ 2 ] = "com.sun.star.chart2.data.NumericalDataSequence";
     233           1 :     aServices[ 3 ] = "com.sun.star.chart2.data.TextualDataSequence";
     234           1 :     return aServices;
     235             : }
     236             : 
     237          26 : IMPLEMENT_FORWARD_XINTERFACE2( CachedDataSequence, CachedDataSequence_Base, OPropertyContainer )
     238           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( CachedDataSequence, CachedDataSequence_Base, OPropertyContainer )
     239             : 
     240             : // ____ XPropertySet ____
     241           0 : Reference< beans::XPropertySetInfo > SAL_CALL CachedDataSequence::getPropertySetInfo()
     242             :     throw(uno::RuntimeException, std::exception)
     243             : {
     244           0 :     return Reference< beans::XPropertySetInfo >( createPropertySetInfo( getInfoHelper() ) );
     245             : }
     246             : 
     247             : // ____ ::comphelper::OPropertySetHelper ____
     248           0 : ::cppu::IPropertyArrayHelper& CachedDataSequence::getInfoHelper()
     249             : {
     250           0 :     return *getArrayHelper();
     251             : }
     252             : 
     253             : // ____ ::comphelper::OPropertyArrayHelper ____
     254           0 : ::cppu::IPropertyArrayHelper* CachedDataSequence::createArrayHelper() const
     255             : {
     256           0 :     Sequence< beans::Property > aProps;
     257             :     // describes all properties which have been registered in the ctor
     258           0 :     describeProperties( aProps );
     259             : 
     260           0 :     return new ::cppu::OPropertyArrayHelper( aProps );
     261             : }
     262             : 
     263             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     264           1 : OUString SAL_CALL CachedDataSequence::getImplementationName()
     265             :     throw( css::uno::RuntimeException, std::exception )
     266             : {
     267           1 :     return getImplementationName_Static();
     268             : }
     269             : 
     270           1 : OUString CachedDataSequence::getImplementationName_Static()
     271             : {
     272           1 :     return OUString(lcl_aServiceName);
     273             : }
     274             : 
     275           0 : sal_Bool SAL_CALL CachedDataSequence::supportsService( const OUString& rServiceName )
     276             :     throw( css::uno::RuntimeException, std::exception )
     277             : {
     278           0 :     return cppu::supportsService(this, rServiceName);
     279             : }
     280             : 
     281           1 : css::uno::Sequence< OUString > SAL_CALL CachedDataSequence::getSupportedServiceNames()
     282             :     throw( css::uno::RuntimeException, std::exception )
     283             : {
     284           1 :     return getSupportedServiceNames_Static();
     285             : }
     286             : 
     287             : // ________ XNumericalDataSequence ________
     288           0 : Sequence< double > SAL_CALL CachedDataSequence::getNumericalData()
     289             :     throw (uno::RuntimeException, std::exception)
     290             : {
     291           0 :     MutexGuard aGuard( GetMutex() );
     292             : 
     293           0 :     if( m_eCurrentDataType == NUMERICAL )
     294           0 :         return m_aNumericalSequence;
     295             :     else
     296           0 :         return Impl_getNumericalData();
     297             : }
     298             : 
     299             : // ________ XTextualDataSequence ________
     300           0 : Sequence< OUString > SAL_CALL CachedDataSequence::getTextualData()
     301             :     throw (uno::RuntimeException, std::exception)
     302             : {
     303           0 :     MutexGuard aGuard( GetMutex() );
     304             : 
     305           0 :     if( m_eCurrentDataType == TEXTUAL )
     306           0 :         return m_aTextualSequence;
     307             :     else
     308           0 :         return Impl_getTextualData();
     309             : }
     310             : 
     311             : // ________ XDataSequence  ________
     312           0 : Sequence< Any > SAL_CALL CachedDataSequence::getData()
     313             :     throw (uno::RuntimeException, std::exception)
     314             : {
     315           0 :     MutexGuard aGuard( GetMutex() );
     316           0 :     return Impl_getMixedData();
     317             : }
     318             : 
     319           0 : OUString SAL_CALL CachedDataSequence::getSourceRangeRepresentation()
     320             :     throw (uno::RuntimeException, std::exception)
     321             : {
     322           0 :     return m_sRole;
     323             : }
     324             : 
     325           0 : Sequence< OUString > SAL_CALL CachedDataSequence::generateLabel( chart2::data::LabelOrigin  /*eLabelOrigin*/ )
     326             :     throw (uno::RuntimeException, std::exception)
     327             : {
     328             :     // return empty label, as we have no range representaions to determine something useful
     329           0 :     return Sequence< OUString >();
     330             : }
     331             : 
     332           0 : ::sal_Int32 SAL_CALL CachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32 /*nIndex*/ )
     333             :     throw (lang::IndexOutOfBoundsException,
     334             :            uno::RuntimeException, std::exception)
     335             : {
     336           0 :     return 0;
     337             : }
     338             : 
     339           0 : Reference< util::XCloneable > SAL_CALL CachedDataSequence::createClone()
     340             :     throw (uno::RuntimeException, std::exception)
     341             : {
     342           0 :     CachedDataSequence * pNewSeq = new CachedDataSequence( *this );
     343             : 
     344           0 :     return Reference< util::XCloneable >( pNewSeq );
     345             : }
     346             : 
     347           0 : void SAL_CALL CachedDataSequence::addModifyListener( const Reference< util::XModifyListener >& aListener )
     348             :     throw (uno::RuntimeException, std::exception)
     349             : {
     350             :     try
     351             :     {
     352           0 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     353           0 :         xBroadcaster->addModifyListener( aListener );
     354             :     }
     355           0 :     catch( const uno::Exception & ex )
     356             :     {
     357             :         ASSERT_EXCEPTION( ex );
     358             :     }
     359           0 : }
     360             : 
     361           0 : void SAL_CALL CachedDataSequence::removeModifyListener( const Reference< util::XModifyListener >& aListener )
     362             :     throw (uno::RuntimeException, std::exception)
     363             : {
     364             :     try
     365             :     {
     366           0 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     367           0 :         xBroadcaster->removeModifyListener( aListener );
     368             :     }
     369           0 :     catch( const uno::Exception & ex )
     370             :     {
     371             :         ASSERT_EXCEPTION( ex );
     372             :     }
     373           0 : }
     374             : 
     375             : // lang::XInitialization:
     376           0 : void SAL_CALL CachedDataSequence::initialize(const uno::Sequence< uno::Any > & _aArguments) throw (uno::RuntimeException, uno::Exception, std::exception)
     377             : {
     378           0 :     ::comphelper::SequenceAsHashMap aMap(_aArguments);
     379           0 :     m_aNumericalSequence = aMap.getUnpackedValueOrDefault( "DataSequence" ,m_aNumericalSequence);
     380           0 :     if ( m_aNumericalSequence.getLength() )
     381           0 :         m_eCurrentDataType = NUMERICAL;
     382             :     else
     383             :     {
     384           0 :         m_aTextualSequence = aMap.getUnpackedValueOrDefault( "DataSequence" ,m_aTextualSequence);
     385           0 :         if ( m_aTextualSequence.getLength() )
     386           0 :             m_eCurrentDataType = TEXTUAL;
     387             :         else
     388             :         {
     389           0 :             m_aMixedSequence = aMap.getUnpackedValueOrDefault( "DataSequence" ,m_aMixedSequence);
     390           0 :             if ( m_aMixedSequence.getLength() )
     391           0 :                 m_eCurrentDataType = MIXED;
     392             :         }
     393           0 :     }
     394           0 : }
     395             : }  // namespace chart
     396             : 
     397             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     398           1 : com_sun_star_comp_chart_CachedDataSequence_get_implementation(css::uno::XComponentContext *context,
     399             :         css::uno::Sequence<css::uno::Any> const &)
     400             : {
     401           1 :     return cppu::acquire(new ::chart::CachedDataSequence(context));
     402             : }
     403             : 
     404             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11