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

Generated by: LCOV version 1.10