LCOV - code coverage report
Current view: top level - chart2/source/tools - UncachedDataSequence.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 76 128 59.4 %
Date: 2015-06-13 12:38:46 Functions: 22 38 57.9 %
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 "UncachedDataSequence.hxx"
      21             : #include "macros.hxx"
      22             : #include "PropertyHelper.hxx"
      23             : #include "CommonFunctors.hxx"
      24             : #include "ModifyListenerHelper.hxx"
      25             : 
      26             : #include <cppuhelper/supportsservice.hxx>
      27             : #include <algorithm>
      28             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      29             : #include <rtl/math.hxx>
      30             : 
      31             : using namespace ::com::sun::star;
      32             : 
      33             : using ::com::sun::star::uno::Sequence;
      34             : using ::com::sun::star::uno::Reference;
      35             : using ::com::sun::star::uno::Any;
      36             : using ::osl::MutexGuard;
      37             : 
      38             : // necessary for MS compiler
      39             : using ::comphelper::OPropertyContainer;
      40             : using ::chart::impl::UncachedDataSequence_Base;
      41             : 
      42             : namespace
      43             : {
      44             : static const char lcl_aServiceName[] = "com.sun.star.comp.chart.UncachedDataSequence";
      45             : 
      46             : enum
      47             : {
      48             :     PROP_NUMBERFORMAT_KEY,
      49             :     PROP_PROPOSED_ROLE,
      50             :     PROP_XML_RANGE
      51             : };
      52             : }  // anonymous namespace
      53             : 
      54             : namespace chart
      55             : {
      56             : 
      57         931 : UncachedDataSequence::UncachedDataSequence(
      58             :     const Reference< chart2::XInternalDataProvider > & xIntDataProv,
      59             :     const OUString & rRangeRepresentation )
      60         931 :         : OPropertyContainer( GetBroadcastHelper()),
      61         931 :           UncachedDataSequence_Base( GetMutex()),
      62             :           m_nNumberFormatKey(0),
      63             :           m_xDataProvider( xIntDataProv ),
      64             :           m_aSourceRepresentation( rRangeRepresentation ),
      65        2793 :           m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
      66             : {
      67         931 :     registerProperties();
      68         931 : }
      69             : 
      70       12842 : UncachedDataSequence::UncachedDataSequence(
      71             :     const Reference< chart2::XInternalDataProvider > & xIntDataProv,
      72             :     const OUString & rRangeRepresentation,
      73             :     const OUString & rRole )
      74       12842 :         : OPropertyContainer( GetBroadcastHelper()),
      75       12842 :           UncachedDataSequence_Base( GetMutex()),
      76             :           m_nNumberFormatKey(0),
      77             :           m_xDataProvider( xIntDataProv ),
      78             :           m_aSourceRepresentation( rRangeRepresentation ),
      79       38526 :           m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
      80             : {
      81       12842 :     registerProperties();
      82       12842 :     setFastPropertyValue_NoBroadcast( PROP_PROPOSED_ROLE, uno::makeAny( rRole ));
      83       12842 : }
      84             : 
      85          46 : UncachedDataSequence::UncachedDataSequence( const UncachedDataSequence & rSource )
      86             :         : ::comphelper::OMutexAndBroadcastHelper(),
      87          46 :           OPropertyContainer( GetBroadcastHelper()),
      88             :           ::comphelper::OPropertyArrayUsageHelper< UncachedDataSequence >(),
      89          46 :           UncachedDataSequence_Base( GetMutex()),
      90             :           m_nNumberFormatKey( rSource.m_nNumberFormatKey ),
      91             :           m_sRole( rSource.m_sRole ),
      92             :           m_xDataProvider( rSource.m_xDataProvider ),
      93             :           m_aSourceRepresentation( rSource.m_aSourceRepresentation ),
      94         138 :           m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
      95             : {
      96          46 :     registerProperties();
      97          46 : }
      98             : 
      99       27414 : UncachedDataSequence::~UncachedDataSequence()
     100       27414 : {}
     101             : 
     102       13819 : void UncachedDataSequence::registerProperties()
     103             : {
     104             :     registerProperty( "NumberFormatKey",
     105             :                       PROP_NUMBERFORMAT_KEY,
     106             :                       0,   // PropertyAttributes
     107             :                       & m_nNumberFormatKey,
     108       13819 :                       cppu::UnoType<decltype(m_nNumberFormatKey)>::get() );
     109             : 
     110             :     registerProperty( "Role",
     111             :                       PROP_PROPOSED_ROLE,
     112             :                       0,   // PropertyAttributes
     113             :                       & m_sRole,
     114       13819 :                       cppu::UnoType<decltype(m_sRole)>::get() );
     115             : 
     116             :     registerProperty( "CachedXMLRange",
     117             :                       PROP_XML_RANGE,
     118             :                       0,   // PropertyAttributes
     119             :                       & m_aXMLRange,
     120       13819 :                       cppu::UnoType<decltype(m_aXMLRange)>::get() );
     121       13819 : }
     122             : 
     123           0 : Sequence< OUString > UncachedDataSequence::getSupportedServiceNames_Static()
     124             : {
     125           0 :     Sequence< OUString > aServices( 4 );
     126           0 :     aServices[ 0 ] = lcl_aServiceName;
     127           0 :     aServices[ 1 ] = "com.sun.star.chart2.data.DataSequence";
     128           0 :     aServices[ 2 ] = "com.sun.star.chart2.data.NumericalDataSequence";
     129           0 :     aServices[ 3 ] = "com.sun.star.chart2.data.TextualDataSequence";
     130           0 :     return aServices;
     131             : }
     132             : 
     133     1740191 : IMPLEMENT_FORWARD_XINTERFACE2( UncachedDataSequence, UncachedDataSequence_Base, OPropertyContainer )
     134           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( UncachedDataSequence, UncachedDataSequence_Base, OPropertyContainer )
     135             : 
     136             : // ____ XPropertySet ____
     137        1107 : Reference< beans::XPropertySetInfo > SAL_CALL UncachedDataSequence::getPropertySetInfo()
     138             :     throw(uno::RuntimeException, std::exception)
     139             : {
     140        1107 :     return Reference< beans::XPropertySetInfo >( createPropertySetInfo( getInfoHelper() ) );
     141             : }
     142             : 
     143             : // ____ ::comphelper::OPropertySetHelper ____
     144      342307 : ::cppu::IPropertyArrayHelper& UncachedDataSequence::getInfoHelper()
     145             : {
     146      342307 :     return *getArrayHelper();
     147             : }
     148             : 
     149             : // ____ ::comphelper::OPropertyArrayHelper ____
     150         135 : ::cppu::IPropertyArrayHelper* UncachedDataSequence::createArrayHelper() const
     151             : {
     152         135 :     Sequence< beans::Property > aProps;
     153             :     // describes all properties which have been registered in the ctor
     154         135 :     describeProperties( aProps );
     155             : 
     156         135 :     return new ::cppu::OPropertyArrayHelper( aProps );
     157             : }
     158             : 
     159             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     160           0 : OUString SAL_CALL UncachedDataSequence::getImplementationName()
     161             :     throw( css::uno::RuntimeException, std::exception )
     162             : {
     163           0 :     return getImplementationName_Static();
     164             : }
     165             : 
     166           0 : OUString UncachedDataSequence::getImplementationName_Static()
     167             : {
     168           0 :     return OUString(lcl_aServiceName);
     169             : }
     170             : 
     171           0 : sal_Bool SAL_CALL UncachedDataSequence::supportsService( const OUString& rServiceName )
     172             :     throw( css::uno::RuntimeException, std::exception )
     173             : {
     174           0 :     return cppu::supportsService(this, rServiceName);
     175             : }
     176             : 
     177           0 : css::uno::Sequence< OUString > SAL_CALL UncachedDataSequence::getSupportedServiceNames()
     178             :     throw( css::uno::RuntimeException, std::exception )
     179             : {
     180           0 :     return getSupportedServiceNames_Static();
     181             : }
     182             : 
     183             : // ________ XNumericalDataSequence ________
     184        3324 : Sequence< double > SAL_CALL UncachedDataSequence::getNumericalData()
     185             :     throw (uno::RuntimeException, std::exception)
     186             : {
     187        3324 :     Sequence< double > aResult;
     188        6648 :     MutexGuard aGuard( GetMutex() );
     189        3324 :     if( m_xDataProvider.is())
     190             :     {
     191        3324 :         Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
     192        3324 :         aResult.realloc( aValues.getLength());
     193        3324 :         ::std::transform( aValues.getConstArray(), aValues.getConstArray() + aValues.getLength(),
     194        6648 :                           aResult.getArray(), CommonFunctors::AnyToDouble());
     195             :     }
     196        6648 :     return aResult;
     197             : }
     198             : 
     199             : // ________ XTextualDataSequence ________
     200        5588 : Sequence< OUString > SAL_CALL UncachedDataSequence::getTextualData()
     201             :     throw (uno::RuntimeException, std::exception)
     202             : {
     203        5588 :     Sequence< OUString > aResult;
     204       11176 :     MutexGuard aGuard( GetMutex() );
     205        5588 :     if( m_xDataProvider.is())
     206             :     {
     207        5588 :         Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
     208        5588 :         aResult.realloc( aValues.getLength());
     209        5588 :         ::std::transform( aValues.getConstArray(), aValues.getConstArray() + aValues.getLength(),
     210       11176 :                           aResult.getArray(), CommonFunctors::AnyToString());
     211             :     }
     212       11176 :     return aResult;
     213             : }
     214             : 
     215             : // ________ XDataSequence  ________
     216      120152 : Sequence< Any > SAL_CALL UncachedDataSequence::getData()
     217             :     throw (uno::RuntimeException, std::exception)
     218             : {
     219      120152 :     MutexGuard aGuard( GetMutex() );
     220      120152 :     if( m_xDataProvider.is())
     221      120152 :         return m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation );
     222           0 :     return Sequence< Any >();
     223             : }
     224             : 
     225       11955 : OUString SAL_CALL UncachedDataSequence::getSourceRangeRepresentation()
     226             :     throw (uno::RuntimeException, std::exception)
     227             : {
     228       11955 :     return getName();
     229             : }
     230             : 
     231          61 : Sequence< OUString > SAL_CALL UncachedDataSequence::generateLabel( chart2::data::LabelOrigin )
     232             :     throw (uno::RuntimeException, std::exception)
     233             : {
     234             :     // auto-generated label is an empty string
     235          61 :     return Sequence< OUString >(1);
     236             : }
     237             : 
     238        3162 : ::sal_Int32 SAL_CALL UncachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32 )
     239             :     throw (lang::IndexOutOfBoundsException,
     240             :            uno::RuntimeException, std::exception)
     241             : {
     242        3162 :     return m_nNumberFormatKey;
     243             : }
     244             : 
     245             : // ____ XIndexReplace ____
     246           0 : void SAL_CALL UncachedDataSequence::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element )
     247             :     throw (lang::IllegalArgumentException,
     248             :            lang::IndexOutOfBoundsException,
     249             :            lang::WrappedTargetException,
     250             :            uno::RuntimeException, std::exception)
     251             : {
     252           0 :     MutexGuard aGuard( GetMutex() );
     253           0 :     Sequence< Any > aData( getData());
     254           0 :     if( Index < aData.getLength() &&
     255           0 :         m_xDataProvider.is() )
     256             :     {
     257           0 :         aData[Index] = Element;
     258           0 :         m_xDataProvider->setDataByRangeRepresentation( m_aSourceRepresentation, aData );
     259           0 :         fireModifyEvent();
     260           0 :     }
     261           0 : }
     262             : 
     263             : // ____ XIndexAccess (base of XIndexReplace) ____
     264           0 : ::sal_Int32 SAL_CALL UncachedDataSequence::getCount()
     265             :     throw (uno::RuntimeException, std::exception)
     266             : {
     267             :     OSL_FAIL( "Implement!" );
     268           0 :     return 0;
     269             : }
     270             : 
     271           0 : uno::Any SAL_CALL UncachedDataSequence::getByIndex( ::sal_Int32 )
     272             :     throw (lang::IndexOutOfBoundsException,
     273             :            lang::WrappedTargetException,
     274             :            uno::RuntimeException, std::exception)
     275             : {
     276             :     OSL_FAIL( "Implement!" );
     277           0 :     return uno::Any();
     278             : }
     279             : 
     280             : // ____ XElementAccess (base of XIndexAccess) ____
     281           0 : uno::Type SAL_CALL UncachedDataSequence::getElementType()
     282             :     throw (uno::RuntimeException, std::exception)
     283             : {
     284           0 :     return cppu::UnoType<uno::Any>::get();
     285             : }
     286             : 
     287           0 : sal_Bool SAL_CALL UncachedDataSequence::hasElements()
     288             :     throw (uno::RuntimeException, std::exception)
     289             : {
     290           0 :     if( ! m_xDataProvider.is())
     291           0 :         return sal_False;
     292           0 :     return m_xDataProvider->hasDataByRangeRepresentation( m_aSourceRepresentation );
     293             : }
     294             : 
     295             : // ____ XNamed ____
     296       11955 : OUString SAL_CALL UncachedDataSequence::getName()
     297             :     throw (uno::RuntimeException, std::exception)
     298             : {
     299       11955 :     return m_aSourceRepresentation;
     300             : }
     301             : 
     302           0 : void SAL_CALL UncachedDataSequence::setName( const OUString& aName )
     303             :     throw (uno::RuntimeException, std::exception)
     304             : {
     305           0 :     m_aSourceRepresentation = aName;
     306           0 :     fireModifyEvent();
     307           0 : }
     308             : 
     309          46 : Reference< util::XCloneable > SAL_CALL UncachedDataSequence::createClone()
     310             :     throw (uno::RuntimeException, std::exception)
     311             : {
     312          46 :     UncachedDataSequence * pNewSeq = new UncachedDataSequence( *this );
     313          46 :     return Reference< util::XCloneable >( pNewSeq );
     314             : }
     315             : 
     316             : // ____ XModifiable ____
     317           0 : sal_Bool SAL_CALL UncachedDataSequence::isModified()
     318             :     throw (uno::RuntimeException, std::exception)
     319             : {
     320           0 :     return sal_False;
     321             : }
     322             : 
     323           0 : void SAL_CALL UncachedDataSequence::setModified( sal_Bool bModified )
     324             :     throw (beans::PropertyVetoException,
     325             :            uno::RuntimeException, std::exception)
     326             : {
     327           0 :     if( bModified )
     328           0 :         fireModifyEvent();
     329           0 : }
     330             : 
     331             : // ____ XModifyBroadcaster (base of XModifiable) ____
     332       13819 : void SAL_CALL UncachedDataSequence::addModifyListener( const Reference< util::XModifyListener >& aListener )
     333             :     throw (uno::RuntimeException, std::exception)
     334             : {
     335             :     try
     336             :     {
     337       13819 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     338       13819 :         xBroadcaster->addModifyListener( aListener );
     339             :     }
     340           0 :     catch( const uno::Exception & ex )
     341             :     {
     342             :         ASSERT_EXCEPTION( ex );
     343             :     }
     344       13819 : }
     345             : 
     346       13707 : void SAL_CALL UncachedDataSequence::removeModifyListener( const Reference< util::XModifyListener >& aListener )
     347             :     throw (uno::RuntimeException, std::exception)
     348             : {
     349             :     try
     350             :     {
     351       13707 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     352       13707 :         xBroadcaster->removeModifyListener( aListener );
     353             :     }
     354           0 :     catch( const uno::Exception & ex )
     355             :     {
     356             :         ASSERT_EXCEPTION( ex );
     357             :     }
     358       13707 : }
     359             : 
     360           0 : void UncachedDataSequence::fireModifyEvent()
     361             : {
     362             :     // @todo: currently never called, as data changes are not yet reported by
     363             :     // the data provider
     364           0 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     365           0 : }
     366             : 
     367             : }  // namespace chart
     368             : 
     369             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11