LCOV - code coverage report
Current view: top level - chart2/source/tools - UncachedDataSequence.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 78 123 63.4 %
Date: 2014-11-03 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          36 : 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        2318 : UncachedDataSequence::UncachedDataSequence(
      57             :     const Reference< chart2::XInternalDataProvider > & xIntDataProv,
      58             :     const OUString & rRangeRepresentation )
      59        2318 :         : OPropertyContainer( GetBroadcastHelper()),
      60        2318 :           UncachedDataSequence_Base( GetMutex()),
      61             :           m_nNumberFormatKey(0),
      62             :           m_xDataProvider( xIntDataProv ),
      63             :           m_aSourceRepresentation( rRangeRepresentation ),
      64        6954 :           m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
      65             : {
      66        2318 :     registerProperties();
      67        2318 : }
      68             : 
      69        5969 : UncachedDataSequence::UncachedDataSequence(
      70             :     const Reference< chart2::XInternalDataProvider > & xIntDataProv,
      71             :     const OUString & rRangeRepresentation,
      72             :     const OUString & rRole )
      73        5969 :         : OPropertyContainer( GetBroadcastHelper()),
      74        5969 :           UncachedDataSequence_Base( GetMutex()),
      75             :           m_nNumberFormatKey(0),
      76             :           m_xDataProvider( xIntDataProv ),
      77             :           m_aSourceRepresentation( rRangeRepresentation ),
      78       17907 :           m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
      79             : {
      80        5969 :     registerProperties();
      81        5969 :     setFastPropertyValue_NoBroadcast( PROP_PROPOSED_ROLE, uno::makeAny( rRole ));
      82        5969 : }
      83             : 
      84          44 : UncachedDataSequence::UncachedDataSequence( const UncachedDataSequence & rSource )
      85             :         : ::comphelper::OMutexAndBroadcastHelper(),
      86          44 :           OPropertyContainer( GetBroadcastHelper()),
      87             :           ::comphelper::OPropertyArrayUsageHelper< UncachedDataSequence >(),
      88          44 :           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         132 :           m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
      94             : {
      95          44 :     registerProperties();
      96          44 : }
      97             : 
      98       16320 : UncachedDataSequence::~UncachedDataSequence()
      99       16320 : {}
     100             : 
     101        8331 : void UncachedDataSequence::registerProperties()
     102             : {
     103             :     registerProperty( "NumberFormatKey",
     104             :                       PROP_NUMBERFORMAT_KEY,
     105             :                       0,   // PropertyAttributes
     106             :                       & m_nNumberFormatKey,
     107        8331 :                       ::getCppuType( & m_nNumberFormatKey ) );
     108             : 
     109             :     registerProperty( "Role",
     110             :                       PROP_PROPOSED_ROLE,
     111             :                       0,   // PropertyAttributes
     112             :                       & m_sRole,
     113        8331 :                       ::getCppuType( & m_sRole ) );
     114             : 
     115             :     registerProperty( "CachedXMLRange",
     116             :                       PROP_XML_RANGE,
     117             :                       0,   // PropertyAttributes
     118             :                       & m_aXMLRange,
     119        8331 :                       ::getCppuType( & m_aXMLRange ) );
     120        8331 : }
     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     2846324 : IMPLEMENT_FORWARD_XINTERFACE2( UncachedDataSequence, UncachedDataSequence_Base, OPropertyContainer )
     133           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( UncachedDataSequence, UncachedDataSequence_Base, OPropertyContainer )
     134             : 
     135             : // ____ XPropertySet ____
     136        3186 : Reference< beans::XPropertySetInfo > SAL_CALL UncachedDataSequence::getPropertySetInfo()
     137             :     throw(uno::RuntimeException, std::exception)
     138             : {
     139        3186 :     return Reference< beans::XPropertySetInfo >( createPropertySetInfo( getInfoHelper() ) );
     140             : }
     141             : 
     142             : // ____ ::comphelper::OPropertySetHelper ____
     143      618132 : ::cppu::IPropertyArrayHelper& UncachedDataSequence::getInfoHelper()
     144             : {
     145      618132 :     return *getArrayHelper();
     146             : }
     147             : 
     148             : // ____ ::comphelper::OPropertyArrayHelper ____
     149         338 : ::cppu::IPropertyArrayHelper* UncachedDataSequence::createArrayHelper() const
     150             : {
     151         338 :     Sequence< beans::Property > aProps;
     152             :     // describes all properties which have been registered in the ctor
     153         338 :     describeProperties( aProps );
     154             : 
     155         338 :     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        2564 : Sequence< double > SAL_CALL UncachedDataSequence::getNumericalData()
     163             :     throw (uno::RuntimeException, std::exception)
     164             : {
     165        2564 :     Sequence< double > aResult;
     166        5128 :     MutexGuard aGuard( GetMutex() );
     167        2564 :     if( m_xDataProvider.is())
     168             :     {
     169        2564 :         Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
     170        2564 :         aResult.realloc( aValues.getLength());
     171        2564 :         ::std::transform( aValues.getConstArray(), aValues.getConstArray() + aValues.getLength(),
     172        5128 :                           aResult.getArray(), CommonFunctors::AnyToDouble());
     173             :     }
     174        5128 :     return aResult;
     175             : }
     176             : 
     177             : // ________ XTextualDataSequence ________
     178        7130 : Sequence< OUString > SAL_CALL UncachedDataSequence::getTextualData()
     179             :     throw (uno::RuntimeException, std::exception)
     180             : {
     181        7130 :     Sequence< OUString > aResult;
     182       14260 :     MutexGuard aGuard( GetMutex() );
     183        7130 :     if( m_xDataProvider.is())
     184             :     {
     185        7130 :         Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ));
     186        7130 :         aResult.realloc( aValues.getLength());
     187        7130 :         ::std::transform( aValues.getConstArray(), aValues.getConstArray() + aValues.getLength(),
     188       14260 :                           aResult.getArray(), CommonFunctors::AnyToString());
     189             :     }
     190       14260 :     return aResult;
     191             : }
     192             : 
     193             : // ________ XDataSequence  ________
     194      211917 : Sequence< Any > SAL_CALL UncachedDataSequence::getData()
     195             :     throw (uno::RuntimeException, std::exception)
     196             : {
     197      211917 :     MutexGuard aGuard( GetMutex() );
     198      211917 :     if( m_xDataProvider.is())
     199      211917 :         return m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation );
     200           0 :     return Sequence< Any >();
     201             : }
     202             : 
     203       11177 : OUString SAL_CALL UncachedDataSequence::getSourceRangeRepresentation()
     204             :     throw (uno::RuntimeException, std::exception)
     205             : {
     206       11177 :     return getName();
     207             : }
     208             : 
     209          94 : 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          94 :     return Sequence< OUString >(1);
     214             : }
     215             : 
     216        5013 : ::sal_Int32 SAL_CALL UncachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32 )
     217             :     throw (lang::IndexOutOfBoundsException,
     218             :            uno::RuntimeException, std::exception)
     219             : {
     220        5013 :     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       11177 : OUString SAL_CALL UncachedDataSequence::getName()
     275             :     throw (uno::RuntimeException, std::exception)
     276             : {
     277       11177 :     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          44 : Reference< util::XCloneable > SAL_CALL UncachedDataSequence::createClone()
     288             :     throw (uno::RuntimeException, std::exception)
     289             : {
     290          44 :     UncachedDataSequence * pNewSeq = new UncachedDataSequence( *this );
     291          44 :     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        8331 : void SAL_CALL UncachedDataSequence::addModifyListener( const Reference< util::XModifyListener >& aListener )
     311             :     throw (uno::RuntimeException, std::exception)
     312             : {
     313             :     try
     314             :     {
     315        8331 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     316        8331 :         xBroadcaster->addModifyListener( aListener );
     317             :     }
     318           0 :     catch( const uno::Exception & ex )
     319             :     {
     320             :         ASSERT_EXCEPTION( ex );
     321             :     }
     322        8331 : }
     323             : 
     324        8160 : void SAL_CALL UncachedDataSequence::removeModifyListener( const Reference< util::XModifyListener >& aListener )
     325             :     throw (uno::RuntimeException, std::exception)
     326             : {
     327             :     try
     328             :     {
     329        8160 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     330        8160 :         xBroadcaster->removeModifyListener( aListener );
     331             :     }
     332           0 :     catch( const uno::Exception & ex )
     333             :     {
     334             :         ASSERT_EXCEPTION( ex );
     335             :     }
     336        8160 : }
     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         108 : }  // namespace chart
     346             : 
     347             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10