From faeb8adf4b12a62919fbf961f65181964cce5325 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sat, 27 Apr 2024 20:49:13 +0500 Subject: Simplify a bit Change-Id: Ic6d0dd0f66a258fffd0be7f458316801516aaefc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166778 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- chart2/qa/extras/chart2export3.cxx | 4 +- chart2/qa/unit/common_functor_test.cxx | 4 +- .../source/controller/main/DrawCommandDispatch.cxx | 6 +- chart2/source/inc/CommonFunctors.hxx | 65 +++++++------- chart2/source/model/filter/XMLFilter.cxx | 2 +- .../source/model/main/ChartModel_Persistence.cxx | 20 +---- chart2/source/tools/CachedDataSequence.cxx | 76 +++-------------- chart2/source/tools/ColorPerPointHelper.cxx | 4 +- chart2/source/tools/InternalDataProvider.cxx | 99 ++++++---------------- .../tools/MeanValueRegressionCurveCalculator.cxx | 18 ++-- chart2/source/tools/UncachedDataSequence.cxx | 14 +-- chart2/source/view/main/ChartView.cxx | 22 ++--- 12 files changed, 99 insertions(+), 235 deletions(-) diff --git a/chart2/qa/extras/chart2export3.cxx b/chart2/qa/extras/chart2export3.cxx index df96a70e8e1f..df70cd603d89 100644 --- a/chart2/qa/extras/chart2export3.cxx +++ b/chart2/qa/extras/chart2export3.cxx @@ -838,9 +838,9 @@ void checkCharacterProps(Reference const & xTitleProp) std::vector aValues = { "This", " is", "3", " a ", "custom", " erte1\n", "2dfgd ch", "ar", "t ", "title" }; for (sal_Int32 i = 0; i < xFormattedSubTitle.getLength(); i++) { - const OUString aText = xFormattedSubTitle.getConstArray()[i]->getString(); + const OUString aText = xFormattedSubTitle[i]->getString(); CPPUNIT_ASSERT_EQUAL(aValues[i], aText); - Reference< beans::XPropertySet > xRunPropSet(xFormattedSubTitle.getConstArray()[i], uno::UNO_QUERY); + Reference< beans::XPropertySet > xRunPropSet(xFormattedSubTitle[i], uno::UNO_QUERY); // common props uno::Any aAny = xRunPropSet->getPropertyValue("CharFontName"); CPPUNIT_ASSERT_EQUAL(uno::Any(OUString("Aptos Narrow")), aAny); diff --git a/chart2/qa/unit/common_functor_test.cxx b/chart2/qa/unit/common_functor_test.cxx index b2e404e13508..a744945e6663 100644 --- a/chart2/qa/unit/common_functor_test.cxx +++ b/chart2/qa/unit/common_functor_test.cxx @@ -48,7 +48,7 @@ void CommonFunctorsTest::testAnyToString() std::vector aOutput; std::transform(aInput.begin(), aInput.end(), - std::back_inserter(aOutput), chart::CommonFunctors::AnyToString()); + std::back_inserter(aOutput), chart::CommonFunctors::ToString()); CPPUNIT_ASSERT_EQUAL(OUString("2"), aOutput[0]); CPPUNIT_ASSERT_EQUAL(OUString("10"), aOutput[1]); @@ -65,7 +65,7 @@ void CommonFunctorsTest::testDoubleToString() std::vector aOutput; std::transform(aInput.begin(), aInput.end(), - std::back_inserter(aOutput), chart::CommonFunctors::DoubleToOUString()); + std::back_inserter(aOutput), chart::CommonFunctors::ToString()); CPPUNIT_ASSERT_EQUAL(OUString("2"), aOutput[0]); CPPUNIT_ASSERT_EQUAL(OUString("10"), aOutput[1]); diff --git a/chart2/source/controller/main/DrawCommandDispatch.cxx b/chart2/source/controller/main/DrawCommandDispatch.cxx index 01771f1e7763..516c2d2ec5f3 100644 --- a/chart2/source/controller/main/DrawCommandDispatch.cxx +++ b/chart2/source/controller/main/DrawCommandDispatch.cxx @@ -346,13 +346,11 @@ void DrawCommandDispatch::execute( const OUString& rCommand, const Sequence< bea pDrawViewWrapper->SetCreateMode(); } - const beans::PropertyValue* pIter = rArgs.getConstArray(); - const beans::PropertyValue* pEnd = pIter + rArgs.getLength(); - const beans::PropertyValue* pKeyModifier = std::find_if(pIter, pEnd, + const beans::PropertyValue* pKeyModifier = std::find_if(rArgs.begin(), rArgs.end(), [](const beans::PropertyValue& lhs) {return lhs.Name == "KeyModifier";} ); sal_Int16 nKeyModifier = 0; - if ( !(pKeyModifier != pEnd && ( pKeyModifier->Value >>= nKeyModifier ) && nKeyModifier == KEY_MOD1) ) + if ( !(pKeyModifier != rArgs.end() && ( pKeyModifier->Value >>= nKeyModifier ) && nKeyModifier == KEY_MOD1) ) return; if ( eDrawMode != CHARTDRAW_INSERT ) diff --git a/chart2/source/inc/CommonFunctors.hxx b/chart2/source/inc/CommonFunctors.hxx index 7bb776490cda..2d01e7ad27ae 100644 --- a/chart2/source/inc/CommonFunctors.hxx +++ b/chart2/source/inc/CommonFunctors.hxx @@ -21,9 +21,11 @@ #include #include #include +#include #include #include "charttoolsdllapi.hxx" +#include #include namespace chart::CommonFunctors @@ -34,20 +36,21 @@ namespace chart::CommonFunctors

uno::makeAny is an inline function. Thus is cannot be taken directly (via mem_fun_ptr)

*/ -template< typename T > - struct makeAny +struct makeAny { + template< typename T > css::uno::Any operator() ( const T & aVal ) { return css::uno::Any( aVal ); } }; -/** unary function to convert css::uno::Any into a double number. +/** unary function to convert an OUString or css::uno::Any into a double number. +

For conversion of OUString, rtl::math::StringToDouble is used.

In case no number can be generated from the Any, NaN is returned.

-*/ -struct OOO_DLLPUBLIC_CHARTTOOLS AnyToDouble + */ +struct OOO_DLLPUBLIC_CHARTTOOLS ToDouble { double operator() ( const css::uno::Any & rAny ) { @@ -55,12 +58,24 @@ struct OOO_DLLPUBLIC_CHARTTOOLS AnyToDouble rAny >>= fResult; return fResult; } + + double operator() ( std::u16string_view rStr ) + { + rtl_math_ConversionStatus eConversionStatus; + double fResult = ::rtl::math::stringToDouble( rStr, '.', ',', & eConversionStatus ); + + if( eConversionStatus != rtl_math_ConversionStatus_Ok ) + return std::numeric_limits::quiet_NaN(); + + return fResult; + } }; -/** unary function to convert css::uno::Any into an - OUString. -*/ -struct OOO_DLLPUBLIC_CHARTTOOLS AnyToString +/** unary function to convert a double number or css::uno::Any into an OUString. + +

For conversion of doubles, rtl::math::DoubleToOUString is used.

+ */ +struct OOO_DLLPUBLIC_CHARTTOOLS ToString { OUString operator() ( const css::uno::Any & rAny ) { @@ -83,32 +98,7 @@ struct OOO_DLLPUBLIC_CHARTTOOLS AnyToString return OUString(); } -}; -/** unary function to convert an OUString into a double number. - -

For conversion rtl::math::StringToDouble is used.

- */ -struct OOO_DLLPUBLIC_CHARTTOOLS OUStringToDouble -{ - double operator() ( std::u16string_view rStr ) - { - rtl_math_ConversionStatus eConversionStatus; - double fResult = ::rtl::math::stringToDouble( rStr, '.', ',', & eConversionStatus ); - - if( eConversionStatus != rtl_math_ConversionStatus_Ok ) - return std::numeric_limits::quiet_NaN(); - - return fResult; - } -}; - -/** unary function to convert a double number into an OUString. - -

For conversion rtl::math::DoubleToOUString is used.

- */ -struct OOO_DLLPUBLIC_CHARTTOOLS DoubleToOUString -{ OUString operator() ( double fNumber ) { return ::rtl::math::doubleToUString( @@ -121,6 +111,13 @@ struct OOO_DLLPUBLIC_CHARTTOOLS DoubleToOUString } }; +template auto convertToSequence(const Container& container, Func f) +{ + css::uno::Sequence result(container.size()); + std::transform(container.begin(), container.end(), result.getArray(), f); + return result; +} + } // namespace chart::CommonFunctors /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/filter/XMLFilter.cxx b/chart2/source/model/filter/XMLFilter.cxx index f1001f3333ea..b5a485dc4c86 100644 --- a/chart2/source/model/filter/XMLFilter.cxx +++ b/chart2/source/model/filter/XMLFilter.cxx @@ -674,7 +674,7 @@ ErrCode XMLFilter::impl_ExportStream( { uno::Reference< beans::XPropertySet > xInfoSet; if( rFilterProperties.hasElements() ) - rFilterProperties.getConstArray()[0] >>= xInfoSet; + rFilterProperties[0] >>= xInfoSet; OSL_ENSURE( xInfoSet.is(), "missing infoset for export" ); if( xInfoSet.is() ) xInfoSet->setPropertyValue( "StreamName", uno::Any( rStreamName ) ); diff --git a/chart2/source/model/main/ChartModel_Persistence.cxx b/chart2/source/model/main/ChartModel_Persistence.cxx index 4fb17e9f1001..8d9e6076078a 100644 --- a/chart2/source/model/main/ChartModel_Persistence.cxx +++ b/chart2/source/model/main/ChartModel_Persistence.cxx @@ -74,19 +74,6 @@ using ::osl::MutexGuard; namespace { -struct lcl_PropNameEquals -{ - explicit lcl_PropNameEquals( OUString aStrToCompareWith ) : - m_aStr(std::move( aStrToCompareWith )) - {} - bool operator() ( const beans::PropertyValue & rProp ) - { - return rProp.Name == m_aStr; - } -private: - OUString m_aStr; -}; - template< typename T > T lcl_getProperty( const Sequence< beans::PropertyValue > & rMediaDescriptor, @@ -95,10 +82,9 @@ T lcl_getProperty( T aResult; if( rMediaDescriptor.hasElements()) { - const beans::PropertyValue * pIt = rMediaDescriptor.getConstArray(); - const beans::PropertyValue * pEndIt = pIt + + rMediaDescriptor.getLength(); - pIt = std::find_if( pIt, pEndIt, lcl_PropNameEquals( rPropName )); - if( pIt != pEndIt ) + auto pIt = std::find_if(rMediaDescriptor.begin(), rMediaDescriptor.end(), + [&rPropName](auto& prop) { return prop.Name == rPropName; }); + if (pIt != rMediaDescriptor.end()) (*pIt).Value >>= aResult; } return aResult; diff --git a/chart2/source/tools/CachedDataSequence.cxx b/chart2/source/tools/CachedDataSequence.cxx index 7ddc9a010408..152b48cf9bd8 100644 --- a/chart2/source/tools/CachedDataSequence.cxx +++ b/chart2/source/tools/CachedDataSequence.cxx @@ -117,29 +117,11 @@ Sequence< double > CachedDataSequence::Impl_getNumericalData() const if( m_eCurrentDataType == NUMERICAL ) return m_aNumericalSequence; - sal_Int32 nSize = ( m_eCurrentDataType == TEXTUAL ) - ? m_aTextualSequence.getLength() - : m_aMixedSequence.getLength(); - - Sequence< double > aResult( nSize ); - double * pResultArray = aResult.getArray(); - if( m_eCurrentDataType == TEXTUAL ) - { - const OUString * pTextArray = m_aTextualSequence.getConstArray(); - std::transform( pTextArray, pTextArray + nSize, - pResultArray, - CommonFunctors::OUStringToDouble() ); - } - else - { - OSL_ASSERT( m_eCurrentDataType == MIXED ); - const Any * pMixedArray = m_aMixedSequence.getConstArray(); - std::transform( pMixedArray, pMixedArray + nSize, - pResultArray, - CommonFunctors::AnyToDouble() ); - } - return aResult; + return CommonFunctors::convertToSequence(m_aTextualSequence, CommonFunctors::ToDouble()); + + OSL_ASSERT(m_eCurrentDataType == MIXED); + return CommonFunctors::convertToSequence(m_aMixedSequence, CommonFunctors::ToDouble()); } Sequence< OUString > CachedDataSequence::Impl_getTextualData() const @@ -147,30 +129,11 @@ Sequence< OUString > CachedDataSequence::Impl_getTextualData() const if( m_eCurrentDataType == TEXTUAL ) return m_aTextualSequence; - sal_Int32 nSize = ( m_eCurrentDataType == NUMERICAL ) - ? m_aNumericalSequence.getLength() - : m_aMixedSequence.getLength(); - - Sequence< OUString > aResult( nSize ); - OUString * pResultArray = aResult.getArray(); - if( m_eCurrentDataType == NUMERICAL ) - { - const double * pTextArray = m_aNumericalSequence.getConstArray(); - std::transform( pTextArray, pTextArray + nSize, - pResultArray, - CommonFunctors::DoubleToOUString() ); - } - else - { - OSL_ASSERT( m_eCurrentDataType == MIXED ); - const Any * pMixedArray = m_aMixedSequence.getConstArray(); - std::transform( pMixedArray, pMixedArray + nSize, - pResultArray, - CommonFunctors::AnyToString() ); - } + return CommonFunctors::convertToSequence(m_aNumericalSequence, CommonFunctors::ToString()); - return aResult; + OSL_ASSERT(m_eCurrentDataType == MIXED); + return CommonFunctors::convertToSequence(m_aMixedSequence, CommonFunctors::ToString()); } Sequence< Any > CachedDataSequence::Impl_getMixedData() const @@ -178,30 +141,11 @@ Sequence< Any > CachedDataSequence::Impl_getMixedData() const if( m_eCurrentDataType == MIXED ) return m_aMixedSequence; - sal_Int32 nSize = ( m_eCurrentDataType == NUMERICAL ) - ? m_aNumericalSequence.getLength() - : m_aTextualSequence.getLength(); - - Sequence< Any > aResult( nSize ); - Any * pResultArray = aResult.getArray(); - if( m_eCurrentDataType == NUMERICAL ) - { - const double * pTextArray = m_aNumericalSequence.getConstArray(); - std::transform( pTextArray, pTextArray + nSize, - pResultArray, - CommonFunctors::makeAny< double >() ); - } - else - { - OSL_ASSERT( m_eCurrentDataType == TEXTUAL ); - const OUString * pMixedArray = m_aTextualSequence.getConstArray(); - std::transform( pMixedArray, pMixedArray + nSize, - pResultArray, - CommonFunctors::makeAny< OUString >() ); - } + return CommonFunctors::convertToSequence(m_aNumericalSequence, CommonFunctors::makeAny()); - return aResult; + OSL_ASSERT(m_eCurrentDataType == TEXTUAL); + return CommonFunctors::convertToSequence(m_aTextualSequence, CommonFunctors::makeAny()); } IMPLEMENT_FORWARD_XINTERFACE2( CachedDataSequence, CachedDataSequence_Base, comphelper::OPropertyContainer2 ) diff --git a/chart2/source/tools/ColorPerPointHelper.cxx b/chart2/source/tools/ColorPerPointHelper.cxx index abc940c51357..bced72bb473a 100644 --- a/chart2/source/tools/ColorPerPointHelper.cxx +++ b/chart2/source/tools/ColorPerPointHelper.cxx @@ -65,9 +65,7 @@ bool ColorPerPointHelper::hasPointOwnProperties( uno::Sequence< sal_Int32 > aIndexList; if( xDataSeries->getFastPropertyValue( PROP_DATASERIES_ATTRIBUTED_DATA_POINTS ) >>= aIndexList ) // "AttributedDataPoints" { - const sal_Int32 * pBegIt = aIndexList.getConstArray(); - const sal_Int32 * pEndIt = pBegIt + aIndexList.getLength(); - return ( std::find( pBegIt, pEndIt, nPointIndex ) != pEndIt ); + return (std::find(aIndexList.begin(), aIndexList.end(), nPointIndex) != aIndexList.end()); } } diff --git a/chart2/source/tools/InternalDataProvider.cxx b/chart2/source/tools/InternalDataProvider.cxx index 7e76708d596b..5b95b0a719be 100644 --- a/chart2/source/tools/InternalDataProvider.cxx +++ b/chart2/source/tools/InternalDataProvider.cxx @@ -69,23 +69,11 @@ constexpr OUString lcl_aCompleteRange = u"all"_ustr; typedef std::multimap< OUString, uno::WeakReference< chart2::data::XDataSequence > > lcl_tSequenceMap; -std::vector< OUString > lcl_AnyToStringSequence( const std::vector< uno::Any >& aAnySeq ) -{ - std::vector< OUString > aResult; - aResult.resize( aAnySeq.size() ); - int i = 0; - for (const uno::Any& aAny : aAnySeq) - aResult[i++] = CommonFunctors::AnyToString()(aAny); - return aResult; -} - std::vector< uno::Any > lcl_StringToAnyVector( const css::uno::Sequence< OUString >& aStringSeq ) { std::vector< uno::Any > aResult; - aResult.resize( aStringSeq.getLength() ); - int i = 0; - for (const OUString& aStr : aStringSeq) - aResult[i++] = CommonFunctors::makeAny()(aStr); + aResult.reserve(aStringSeq.getLength()); + std::transform(aStringSeq.begin(), aStringSeq.end(), std::back_inserter(aResult), CommonFunctors::makeAny()); return aResult; } @@ -206,7 +194,7 @@ public: { OUString aString; if( m_nLevel < static_cast< sal_Int32 >(rVector.size()) ) - aString = CommonFunctors::AnyToString()(rVector[m_nLevel]); + aString = CommonFunctors::ToString()(rVector[m_nLevel]); return aString; } @@ -355,7 +343,7 @@ InternalDataProvider::InternalDataProvider( aNewCategories.resize( nLength ); else if( nLength < nCatLength ) aDataSeq.realloc( nCatLength ); - transform( aNewCategories.begin(), aNewCategories.end(), aDataSeq.getConstArray(), + transform( aNewCategories.begin(), aNewCategories.end(), aDataSeq.begin(), aNewCategories.begin(), lcl_setAnyAtLevel(nL) ); } if( !nLevelCount ) @@ -907,11 +895,7 @@ Sequence< uno::Any > SAL_CALL InternalDataProvider::getDataByRangeRepresentation sal_Int32 nLevel = o3tl::toInt32(aRange.subView( strlen(lcl_aCategoriesLevelRangeNamePrefix) )); const std::vector< std::vector< uno::Any > > & aCategories( m_bDataInColumns ? m_aInternalData.getComplexRowLabels() : m_aInternalData.getComplexColumnLabels()); if( nLevel < lcl_getInnerLevelCount( aCategories ) ) - { - aResult.realloc( aCategories.size() ); - transform( aCategories.begin(), aCategories.end(), - aResult.getArray(), lcl_copyFromLevel(nLevel) ); - } + aResult = CommonFunctors::convertToSequence(aCategories, lcl_copyFromLevel(nLevel)); } else if( aRange == lcl_aCategoriesRangeName ) { @@ -925,9 +909,7 @@ Sequence< uno::Any > SAL_CALL InternalDataProvider::getDataByRangeRepresentation { // Maybe this 'else' part and the functions is not necessary anymore. const Sequence< OUString > aLabels = m_bDataInColumns ? getRowDescriptions() : getColumnDescriptions(); - aResult.realloc( aLabels.getLength() ); - std::transform( aLabels.begin(), aLabels.end(), - aResult.getArray(), CommonFunctors::makeAny< OUString >() ); + aResult = CommonFunctors::convertToSequence(aLabels, CommonFunctors::makeAny()); } } else @@ -939,11 +921,7 @@ Sequence< uno::Any > SAL_CALL InternalDataProvider::getDataByRangeRepresentation ? m_aInternalData.getColumnValues(nIndex) : m_aInternalData.getRowValues(nIndex); if( aData.hasElements() ) - { - aResult.realloc( aData.getLength()); - std::transform( aData.begin(), aData.end(), - aResult.getArray(), CommonFunctors::makeAny< double >()); - } + aResult = CommonFunctors::convertToSequence(aData, CommonFunctors::makeAny()); } } @@ -1006,8 +984,9 @@ void SAL_CALL InternalDataProvider::setDataByRangeRepresentation( if( nIndex>=0 ) { std::vector< double > aNewDataVec; + aNewDataVec.reserve(aNewData.getLength()); transform( aNewData.begin(), aNewData.end(), - back_inserter( aNewDataVec ), CommonFunctors::AnyToDouble()); + back_inserter( aNewDataVec ), CommonFunctors::ToDouble()); if( m_bDataInColumns ) m_aInternalData.setColumnValues( nIndex, aNewDataVec ); else @@ -1292,52 +1271,33 @@ namespace template< class Type > Sequence< Sequence< Type > > lcl_convertVectorVectorToSequenceSequence( const std::vector< std::vector< Type > >& rIn ) { - Sequence< Sequence< Type > > aRet; - sal_Int32 nOuterCount = rIn.size(); - if( nOuterCount ) - { - aRet.realloc(nOuterCount); - auto pRet = aRet.getArray(); - for( sal_Int32 nN=0; nN std::vector< std::vector< Type > > lcl_convertSequenceSequenceToVectorVector( const Sequence< Sequence< Type > >& rIn ) { std::vector< std::vector< Type > > aRet; - sal_Int32 nOuterCount = rIn.getLength(); - if( nOuterCount ) - { - aRet.resize(nOuterCount); - for( sal_Int32 nN=0; nN>( rIn[nN] ); - } + aRet.reserve(rIn.getLength()); + std::transform(rIn.begin(), rIn.end(), std::back_inserter(aRet), + [](auto& s) { return comphelper::sequenceToContainer>(s); }); return aRet; } -std::vector< Sequence< OUString > > lcl_convertComplexAnyVectorToStringSequence( const std::vector< std::vector< uno::Any > >& rIn ) +Sequence< Sequence< OUString > > lcl_convertComplexAnyVectorToStringSequence( const std::vector< std::vector< uno::Any > >& rIn ) { - std::vector< Sequence< OUString > > aRet; - sal_Int32 nOuterCount = rIn.size(); - if( nOuterCount ) - { - aRet.resize(nOuterCount); - for( sal_Int32 nN=0; nN > lcl_convertComplexStringSequenceToAnyVector( const Sequence< Sequence< OUString > >& rIn ) { std::vector< std::vector< uno::Any > > aRet; - sal_Int32 nOuterCount = rIn.getLength(); - aRet.reserve(nOuterCount); - for (sal_Int32 nN = 0; nN < nOuterCount; nN++) - aRet.push_back( lcl_StringToAnyVector( rIn[nN] ) ); + aRet.reserve(rIn.getLength()); + std::transform(rIn.begin(), rIn.end(), std::back_inserter(aRet), + [](auto& s) { return lcl_StringToAnyVector(s); }); return aRet; } @@ -1362,14 +1322,9 @@ sal_Int32 SplitCategoriesProvider_ForComplexDescriptions::getLevelCount() const } uno::Sequence< OUString > SplitCategoriesProvider_ForComplexDescriptions::getStringsForLevel( sal_Int32 nLevel ) const { - uno::Sequence< OUString > aResult; if( nLevel < lcl_getInnerLevelCount( m_rComplexDescriptions ) ) - { - aResult.realloc( m_rComplexDescriptions.size() ); - transform( m_rComplexDescriptions.begin(), m_rComplexDescriptions.end(), - aResult.getArray(), lcl_getStringFromLevelVector(nLevel) ); - } - return aResult; + return CommonFunctors::convertToSequence(m_rComplexDescriptions, lcl_getStringFromLevelVector(nLevel)); + return {}; } }//anonymous namespace @@ -1432,7 +1387,7 @@ void SAL_CALL InternalDataProvider::setAnyColumnDescriptions( const Sequence< Se // ____ XComplexDescriptionAccess ____ Sequence< Sequence< OUString > > SAL_CALL InternalDataProvider::getComplexRowDescriptions() { - return comphelper::containerToSequence(lcl_convertComplexAnyVectorToStringSequence( m_aInternalData.getComplexRowLabels() )); + return lcl_convertComplexAnyVectorToStringSequence( m_aInternalData.getComplexRowLabels() ); } void SAL_CALL InternalDataProvider::setComplexRowDescriptions( const Sequence< Sequence< OUString > >& aRowDescriptions ) { @@ -1440,7 +1395,7 @@ void SAL_CALL InternalDataProvider::setComplexRowDescriptions( const Sequence< S } Sequence< Sequence< OUString > > SAL_CALL InternalDataProvider::getComplexColumnDescriptions() { - return comphelper::containerToSequence(lcl_convertComplexAnyVectorToStringSequence( m_aInternalData.getComplexColumnLabels() )); + return lcl_convertComplexAnyVectorToStringSequence( m_aInternalData.getComplexColumnLabels() ); } void SAL_CALL InternalDataProvider::setComplexColumnDescriptions( const Sequence< Sequence< OUString > >& aColumnDescriptions ) { @@ -1461,7 +1416,7 @@ void SAL_CALL InternalDataProvider::setData( const Sequence< Sequence< double > void SAL_CALL InternalDataProvider::setRowDescriptions( const Sequence< OUString >& aRowDescriptions ) { std::vector< std::vector< uno::Any > > aComplexDescriptions( aRowDescriptions.getLength() ); - transform( aComplexDescriptions.begin(), aComplexDescriptions.end(), aRowDescriptions.getConstArray(), + transform( aComplexDescriptions.begin(), aComplexDescriptions.end(), aRowDescriptions.begin(), aComplexDescriptions.begin(), lcl_setAnyAtLevelFromStringSequence(0) ); m_aInternalData.setComplexRowLabels( std::move(aComplexDescriptions) ); } @@ -1469,7 +1424,7 @@ void SAL_CALL InternalDataProvider::setRowDescriptions( const Sequence< OUString void SAL_CALL InternalDataProvider::setColumnDescriptions( const Sequence< OUString >& aColumnDescriptions ) { std::vector< std::vector< uno::Any > > aComplexDescriptions( aColumnDescriptions.getLength() ); - transform( aComplexDescriptions.begin(), aComplexDescriptions.end(), aColumnDescriptions.getConstArray(), + transform( aComplexDescriptions.begin(), aComplexDescriptions.end(), aColumnDescriptions.begin(), aComplexDescriptions.begin(), lcl_setAnyAtLevelFromStringSequence(0) ); m_aInternalData.setComplexColumnLabels( std::move(aComplexDescriptions) ); } diff --git a/chart2/source/tools/MeanValueRegressionCurveCalculator.cxx b/chart2/source/tools/MeanValueRegressionCurveCalculator.cxx index aefd3f8f05aa..ac67a12e5e9b 100644 --- a/chart2/source/tools/MeanValueRegressionCurveCalculator.cxx +++ b/chart2/source/tools/MeanValueRegressionCurveCalculator.cxx @@ -42,18 +42,15 @@ void SAL_CALL MeanValueRegressionCurveCalculator::recalculateRegression( const uno::Sequence< double >& /*aXValues*/, const uno::Sequence< double >& aYValues ) { - const sal_Int32 nDataLength = aYValues.getLength(); - sal_Int32 nMax = nDataLength; + sal_Int32 nMax = aYValues.getLength(); double fSumY = 0.0; - const double * pY = aYValues.getConstArray(); - for( sal_Int32 i = 0; i < nDataLength; ++i ) + for (double y : aYValues) { - if( std::isnan( pY[i] ) || - std::isinf( pY[i] )) + if (std::isnan(y) || std::isinf(y)) --nMax; else - fSumY += pY[i]; + fSumY += y; } m_fCorrelationCoefficient = 0.0; @@ -70,12 +67,11 @@ void SAL_CALL MeanValueRegressionCurveCalculator::recalculateRegression( if( nMax > 1 ) { double fErrorSum = 0.0; - for( sal_Int32 i = 0; i < nDataLength; ++i ) + for (double y : aYValues) { - if( !std::isnan( pY[i] ) && - !std::isinf( pY[i] )) + if (!std::isnan(y) && !std::isinf(y)) { - double v = m_fMeanValue - pY[i]; + double v = m_fMeanValue - y; fErrorSum += (v*v); } } diff --git a/chart2/source/tools/UncachedDataSequence.cxx b/chart2/source/tools/UncachedDataSequence.cxx index 176eadafe8b1..b7929719df02 100644 --- a/chart2/source/tools/UncachedDataSequence.cxx +++ b/chart2/source/tools/UncachedDataSequence.cxx @@ -160,31 +160,25 @@ css::uno::Sequence< OUString > SAL_CALL UncachedDataSequence::getSupportedServic // ________ XNumericalDataSequence ________ Sequence< double > SAL_CALL UncachedDataSequence::getNumericalData() { - Sequence< double > aResult; std::unique_lock aGuard; if( m_xDataProvider.is()) { const Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation )); - aResult.realloc( aValues.getLength()); - std::transform( aValues.begin(), aValues.end(), - aResult.getArray(), CommonFunctors::AnyToDouble()); + return CommonFunctors::convertToSequence(aValues, CommonFunctors::ToDouble()); } - return aResult; + return {}; } // ________ XTextualDataSequence ________ Sequence< OUString > SAL_CALL UncachedDataSequence::getTextualData() { - Sequence< OUString > aResult; std::unique_lock aGuard; if( m_xDataProvider.is()) { const Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation )); - aResult.realloc( aValues.getLength()); - std::transform( aValues.begin(), aValues.end(), - aResult.getArray(), CommonFunctors::AnyToString()); + return CommonFunctors::convertToSequence(aValues, CommonFunctors::ToString()); } - return aResult; + return {}; } // ________ XDataSequence ________ diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index d01a877040b2..dc09a83f810a 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -1681,20 +1681,16 @@ void SAL_CALL ChartView::setPropertyValue( const OUString& rPropertyName if( ! (rValue >>= aZoomFactors) ) throw lang::IllegalArgumentException( "Property 'ZoomFactors' requires value of type Sequence< PropertyValue >", nullptr, 0 ); - sal_Int32 nFilterArgs = aZoomFactors.getLength(); - const beans::PropertyValue* pDataValues = aZoomFactors.getConstArray(); - while( nFilterArgs-- ) + for (auto& propval : aZoomFactors) { - if ( pDataValues->Name == "ScaleXNumerator" ) - pDataValues->Value >>= m_nScaleXNumerator; - else if ( pDataValues->Name == "ScaleXDenominator" ) - pDataValues->Value >>= m_nScaleXDenominator; - else if ( pDataValues->Name == "ScaleYNumerator" ) - pDataValues->Value >>= m_nScaleYNumerator; - else if ( pDataValues->Name == "ScaleYDenominator" ) - pDataValues->Value >>= m_nScaleYDenominator; - - pDataValues++; + if (propval.Name == "ScaleXNumerator") + propval.Value >>= m_nScaleXNumerator; + else if (propval.Name == "ScaleXDenominator") + propval.Value >>= m_nScaleXDenominator; + else if (propval.Name == "ScaleYNumerator") + propval.Value >>= m_nScaleYNumerator; + else if (propval.Name == "ScaleYDenominator") + propval.Value >>= m_nScaleYDenominator; } } else if( rPropertyName == "SdrViewIsInEditMode" ) -- cgit v1.2.3