summaryrefslogtreecommitdiff
path: root/chart2/source/tools/InternalData.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'chart2/source/tools/InternalData.cxx')
-rw-r--r--chart2/source/tools/InternalData.cxx72
1 files changed, 34 insertions, 38 deletions
diff --git a/chart2/source/tools/InternalData.cxx b/chart2/source/tools/InternalData.cxx
index b93dbe33ae88..e6e926078eb3 100644
--- a/chart2/source/tools/InternalData.cxx
+++ b/chart2/source/tools/InternalData.cxx
@@ -21,6 +21,8 @@
#include <ResId.hxx>
#include <strings.hrc>
+#include <comphelper/sequence.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#ifdef DEBUG_CHART2_TOOLS
@@ -38,7 +40,6 @@
using ::com::sun::star::uno::Sequence;
using namespace ::com::sun::star;
-using namespace ::std;
namespace chart
{
@@ -47,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 ))) };
}
@@ -68,11 +69,13 @@ private:
template< typename T >
Sequence< T > lcl_ValarrayToSequence( const std::valarray< T > & rValarray )
{
- // is there a more elegant way of conversion?
- Sequence< T > aResult( rValarray.size());
- for( size_t i = 0; i < rValarray.size(); ++i )
- aResult[i] = rValarray[i];
- return aResult;
+#if defined __GLIBCXX__ && (!defined _GLIBCXX_RELEASE || _GLIBCXX_RELEASE < 12)
+ // workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103022
+ if (!size(rValarray))
+ return Sequence<T>();
+#endif
+
+ return comphelper::containerToSequence(rValarray);
}
} // anonymous namespace
@@ -110,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 )
@@ -147,9 +150,10 @@ void InternalData::setData( const Sequence< Sequence< double > >& rDataInRows )
Sequence< Sequence< double > > InternalData::getData() const
{
Sequence< Sequence< double > > aResult( m_nRowCount );
+ auto aResultRange = asNonConstRange(aResult);
for( sal_Int32 i=0; i<m_nRowCount; ++i )
- aResult[i] = lcl_ValarrayToSequence< tDataType::value_type >(
+ aResultRange[i] = lcl_ValarrayToSequence< tDataType::value_type >(
m_aData[ std::slice( i*m_nColumnCount, m_nColumnCount, 1 ) ] );
return aResult;
@@ -170,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 );
@@ -208,11 +212,11 @@ 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 );
@@ -229,19 +233,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 )
@@ -254,14 +258,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 )
@@ -274,14 +274,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 )
@@ -337,7 +333,7 @@ void InternalData::insertColumn( sal_Int32 nAfterIndex )
// 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();
}
@@ -395,7 +391,7 @@ void InternalData::insertRow( sal_Int32 nAfterIndex )
// 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();
}