diff options
Diffstat (limited to 'chart2/source/tools/InternalData.cxx')
-rw-r--r-- | chart2/source/tools/InternalData.cxx | 91 |
1 files changed, 46 insertions, 45 deletions
diff --git a/chart2/source/tools/InternalData.cxx b/chart2/source/tools/InternalData.cxx index dd48289e831c..a0f5f087d09c 100644 --- a/chart2/source/tools/InternalData.cxx +++ b/chart2/source/tools/InternalData.cxx @@ -22,6 +22,7 @@ #include <strings.hrc> #include <comphelper/sequence.hxx> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #ifdef DEBUG_CHART2_TOOLS @@ -39,7 +40,6 @@ using ::com::sun::star::uno::Sequence; using namespace ::com::sun::star; -using namespace ::std; namespace chart { @@ -48,14 +48,14 @@ namespace { struct lcl_NumberedStringGenerator { - lcl_NumberedStringGenerator( const OUString & rStub, const OUString & rWildcard ) : + lcl_NumberedStringGenerator( const OUString & rStub, std::u16string_view rWildcard ) : m_aStub( rStub ), m_nCounter( 0 ), m_nStubStartIndex( rStub.indexOf( rWildcard )), - m_nWildcardLength( rWildcard.getLength()) + m_nWildcardLength( rWildcard.size()) { } - vector< uno::Any > operator()() + std::vector< uno::Any > operator()() { return { uno::Any(m_aStub.replaceAt( m_nStubStartIndex, m_nWildcardLength, OUString::number( ++m_nCounter ))) }; } @@ -113,12 +113,12 @@ void InternalData::createDefaultData() m_aRowLabels.clear(); m_aRowLabels.reserve( m_nRowCount ); generate_n( back_inserter( m_aRowLabels ), m_nRowCount, - lcl_NumberedStringGenerator( aRowName, "%ROWNUMBER" )); + lcl_NumberedStringGenerator( aRowName, u"%ROWNUMBER" )); m_aColumnLabels.clear(); m_aColumnLabels.reserve( m_nColumnCount ); generate_n( back_inserter( m_aColumnLabels ), m_nColumnCount, - lcl_NumberedStringGenerator( aColName, "%COLUMNNUMBER" )); + lcl_NumberedStringGenerator( aColName, u"%COLUMNNUMBER" )); } void InternalData::setData( const Sequence< Sequence< double > >& rDataInRows ) @@ -174,35 +174,35 @@ Sequence< double > InternalData::getRowValues( sal_Int32 nRowIndex ) const return Sequence< double >(); } -void InternalData::setColumnValues( sal_Int32 nColumnIndex, const vector< double > & rNewData ) +void InternalData::setColumnValues( sal_Int32 nColumnIndex, const std::vector< double > & rNewData ) { if( nColumnIndex < 0 ) return; enlargeData( nColumnIndex + 1, rNewData.size() ); tDataType aSlice = m_aData[ std::slice( nColumnIndex, m_nRowCount, m_nColumnCount ) ]; - for( vector< double >::size_type i = 0; i < rNewData.size(); ++i ) + for( std::vector< double >::size_type i = 0; i < rNewData.size(); ++i ) aSlice[i] = rNewData[i]; m_aData[ std::slice( nColumnIndex, m_nRowCount, m_nColumnCount ) ] = aSlice; } -void InternalData::setRowValues( sal_Int32 nRowIndex, const vector< double > & rNewData ) +void InternalData::setRowValues( sal_Int32 nRowIndex, const std::vector< double > & rNewData ) { if( nRowIndex < 0 ) return; enlargeData( rNewData.size(), nRowIndex+1 ); tDataType aSlice = m_aData[ std::slice( nRowIndex*m_nColumnCount, m_nColumnCount, 1 ) ]; - for( vector< double >::size_type i = 0; i < rNewData.size(); ++i ) + for( std::vector< double >::size_type i = 0; i < rNewData.size(); ++i ) aSlice[i] = rNewData[i]; m_aData[ std::slice( nRowIndex*m_nColumnCount, m_nColumnCount, 1 ) ]= aSlice; } -void InternalData::setComplexColumnLabel( sal_Int32 nColumnIndex, vector< uno::Any >&& rComplexLabel ) +void InternalData::setComplexColumnLabel( sal_Int32 nColumnIndex, std::vector< uno::Any >&& rComplexLabel ) { if( nColumnIndex < 0 ) return; - if( nColumnIndex >= static_cast< sal_Int32 >( m_aColumnLabels.size() ) ) + if( o3tl::make_unsigned(nColumnIndex) >= m_aColumnLabels.size() ) { m_aColumnLabels.resize(nColumnIndex+1); enlargeData( nColumnIndex+1, 0 ); @@ -212,19 +212,33 @@ void InternalData::setComplexColumnLabel( sal_Int32 nColumnIndex, vector< uno::A dump(); } -void InternalData::setComplexRowLabel( sal_Int32 nRowIndex, vector< uno::Any >&& rComplexLabel ) +void InternalData::setComplexRowLabel( sal_Int32 nRowIndex, std::vector< uno::Any >&& rComplexLabel ) { if( nRowIndex < 0 ) return; - if( nRowIndex >= static_cast< sal_Int32 >( m_aRowLabels.size() ) ) + if( o3tl::make_unsigned(nRowIndex) >= m_aRowLabels.size() ) { m_aRowLabels.resize(nRowIndex+1); enlargeData( 0, nRowIndex+1 ); } - sal_Int32 nSize = static_cast<sal_Int32>( m_aRowLabels[nRowIndex].size() ); - if( nSize >= 1 && !rComplexLabel.empty() ) + m_aRowLabels[nRowIndex] = std::move(rComplexLabel); + + dump(); +} + +void InternalData::setComplexCategoryLabel(sal_Int32 nRowIndex, std::vector< uno::Any >&& rComplexLabel) +{ + if (nRowIndex < 0) + return; + if (o3tl::make_unsigned(nRowIndex) >= m_aRowLabels.size()) + { + m_aRowLabels.resize(nRowIndex + 1); + enlargeData(0, nRowIndex + 1); + } + sal_Int32 nSize = static_cast<sal_Int32>(m_aRowLabels[nRowIndex].size()); + if (nSize >= 1 && !rComplexLabel.empty()) { - m_aRowLabels[nRowIndex].resize(nSize+1); + m_aRowLabels[nRowIndex].resize(nSize + 1); m_aRowLabels[nRowIndex][nSize] = rComplexLabel[0]; } else @@ -233,19 +247,19 @@ void InternalData::setComplexRowLabel( sal_Int32 nRowIndex, vector< uno::Any >&& } } -vector< uno::Any > InternalData::getComplexColumnLabel( sal_Int32 nColumnIndex ) const +std::vector< uno::Any > InternalData::getComplexColumnLabel( sal_Int32 nColumnIndex ) const { if( nColumnIndex < static_cast< sal_Int32 >( m_aColumnLabels.size() ) ) return m_aColumnLabels[nColumnIndex]; else - return vector< uno::Any >(); + return std::vector< uno::Any >(); } -vector< uno::Any > InternalData::getComplexRowLabel( sal_Int32 nRowIndex ) const +std::vector< uno::Any > InternalData::getComplexRowLabel( sal_Int32 nRowIndex ) const { if( nRowIndex < static_cast< sal_Int32 >( m_aRowLabels.size() ) ) return m_aRowLabels[nRowIndex]; else - return vector< uno::Any >(); + return std::vector< uno::Any >(); } void InternalData::swapRowWithNext( sal_Int32 nRowIndex ) @@ -258,14 +272,10 @@ void InternalData::swapRowWithNext( sal_Int32 nRowIndex ) { size_t nIndex1 = nColIdx + nRowIndex*m_nColumnCount; size_t nIndex2 = nIndex1 + m_nColumnCount; - double fTemp = m_aData[nIndex1]; - m_aData[nIndex1] = m_aData[nIndex2]; - m_aData[nIndex2] = fTemp; + std::swap(m_aData[nIndex1], m_aData[nIndex2]); } - vector< uno::Any > aTemp( m_aRowLabels[nRowIndex] ); - m_aRowLabels[nRowIndex] = m_aRowLabels[nRowIndex + 1]; - m_aRowLabels[nRowIndex + 1] = aTemp; + std::swap(m_aRowLabels[nRowIndex], m_aRowLabels[nRowIndex + 1]); } void InternalData::swapColumnWithNext( sal_Int32 nColumnIndex ) @@ -278,14 +288,10 @@ void InternalData::swapColumnWithNext( sal_Int32 nColumnIndex ) { size_t nIndex1 = nColumnIndex + nRowIdx*m_nColumnCount; size_t nIndex2 = nIndex1 + 1; - double fTemp = m_aData[nIndex1]; - m_aData[nIndex1] = m_aData[nIndex2]; - m_aData[nIndex2] = fTemp; + std::swap(m_aData[nIndex1], m_aData[nIndex2]); } - vector< uno::Any > aTemp( m_aColumnLabels[nColumnIndex] ); - m_aColumnLabels[nColumnIndex] = m_aColumnLabels[nColumnIndex + 1]; - m_aColumnLabels[nColumnIndex + 1] = aTemp; + std::swap(m_aColumnLabels[nColumnIndex], m_aColumnLabels[nColumnIndex + 1]); } bool InternalData::enlargeData( sal_Int32 nColumnCount, sal_Int32 nRowCount ) @@ -305,8 +311,7 @@ bool InternalData::enlargeData( sal_Int32 nColumnCount, sal_Int32 nRowCount ) aNewData[ std::slice( nCol, m_nRowCount, nNewColumnCount ) ] ) = m_aData[ std::slice( nCol, m_nRowCount, m_nColumnCount ) ]; - m_aData.resize( nNewSize ); - m_aData = aNewData; + m_aData = std::move(aNewData); } m_nColumnCount = nNewColumnCount; m_nRowCount = nNewRowCount; @@ -336,12 +341,11 @@ void InternalData::insertColumn( sal_Int32 nAfterIndex ) m_aData[ std::slice( nCol - 1, m_nRowCount, m_nColumnCount ) ] ); m_nColumnCount = nNewColumnCount; - m_aData.resize( nNewSize ); - m_aData = aNewData; + m_aData = std::move(aNewData); // labels if( nAfterIndex < static_cast< sal_Int32 >( m_aColumnLabels.size())) - m_aColumnLabels.insert( m_aColumnLabels.begin() + (nAfterIndex + 1), vector< uno::Any >(1) ); + m_aColumnLabels.insert( m_aColumnLabels.begin() + (nAfterIndex + 1), std::vector< uno::Any >(1) ); dump(); } @@ -394,12 +398,11 @@ void InternalData::insertRow( sal_Int32 nAfterIndex ) } m_nRowCount = nNewRowCount; - m_aData.resize( nNewSize ); - m_aData = aNewData; + m_aData = std::move(aNewData); // labels if( nAfterIndex < static_cast< sal_Int32 >( m_aRowLabels.size())) - m_aRowLabels.insert( m_aRowLabels.begin() + nIndex, vector< uno::Any > (1)); + m_aRowLabels.insert( m_aRowLabels.begin() + nIndex, std::vector< uno::Any > (1)); dump(); } @@ -426,8 +429,7 @@ void InternalData::deleteColumn( sal_Int32 nAtIndex ) m_aData[ std::slice( nCol + 1, m_nRowCount, m_nColumnCount ) ] ); m_nColumnCount = nNewColumnCount; - m_aData.resize( nNewSize ); - m_aData = aNewData; + m_aData = std::move(aNewData); // labels if( nAtIndex < static_cast< sal_Int32 >( m_aColumnLabels.size())) @@ -462,8 +464,7 @@ void InternalData::deleteRow( sal_Int32 nAtIndex ) } m_nRowCount = nNewRowCount; - m_aData.resize( nNewSize ); - m_aData = aNewData; + m_aData = std::move(aNewData); // labels if( nAtIndex < static_cast< sal_Int32 >( m_aRowLabels.size())) |