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

Generated by: LCOV version 1.10