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

Generated by: LCOV version 1.10