diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-05-08 10:29:21 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-05-14 11:10:09 +0200 |
commit | 858e6b266476e5a18111fce883465e734942a50f (patch) | |
tree | 69b25cee1f74a1c8c3db9e49f98701f755d04877 /extensions | |
parent | 6a017237e01a25ce6901d1cf85ac0408f8935b11 (diff) |
loplugin:useuniqueptr in SaneDlg
Change-Id: I712b733c9c24db2e2fcdc4b6ce16e38eaf0b27f0
Reviewed-on: https://gerrit.libreoffice.org/54167
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/source/scanner/sane.cxx | 8 | ||||
-rw-r--r-- | extensions/source/scanner/sane.hxx | 2 | ||||
-rw-r--r-- | extensions/source/scanner/sanedlg.cxx | 22 | ||||
-rw-r--r-- | extensions/source/scanner/sanedlg.hxx | 2 |
4 files changed, 12 insertions, 22 deletions
diff --git a/extensions/source/scanner/sane.cxx b/extensions/source/scanner/sane.cxx index 90eb652282b2..614aaccf8145 100644 --- a/extensions/source/scanner/sane.cxx +++ b/extensions/source/scanner/sane.cxx @@ -888,7 +888,7 @@ bool Sane::Start( BitmapTransporter& rBitmap ) return bSuccess; } -int Sane::GetRange( int n, double*& rpDouble ) +int Sane::GetRange( int n, std::unique_ptr<double[]>& rpDouble ) { if( mppOptions[n]->constraint_type != SANE_CONSTRAINT_RANGE && mppOptions[n]->constraint_type != SANE_CONSTRAINT_WORD_LIST ) @@ -921,7 +921,7 @@ int Sane::GetRange( int n, double*& rpDouble ) dbg_msg( "quantum range [ %lg ; %lg ; %lg ]\n", fMin, fQuant, fMax ); nItems = static_cast<int>((fMax - fMin)/fQuant)+1; - rpDouble = new double[ nItems ]; + rpDouble.reset(new double[ nItems ]); double fValue = fMin; for( i = 0; i < nItems; i++, fValue += fQuant ) rpDouble[i] = fValue; @@ -932,7 +932,7 @@ int Sane::GetRange( int n, double*& rpDouble ) { dbg_msg( "normal range [ %lg %lg ]\n", fMin, fMax ); - rpDouble = new double[2]; + rpDouble.reset(new double[2]); rpDouble[0] = fMin; rpDouble[1] = fMax; return 0; @@ -941,7 +941,7 @@ int Sane::GetRange( int n, double*& rpDouble ) else { nItems = mppOptions[n]->constraint.word_list[0]; - rpDouble = new double[nItems]; + rpDouble.reset(new double[nItems]); for( i=0; i<nItems; i++ ) { rpDouble[i] = bIsFixed ? diff --git a/extensions/source/scanner/sane.hxx b/extensions/source/scanner/sane.hxx index 7145ab133b27..94fe3eb45baa 100644 --- a/extensions/source/scanner/sane.hxx +++ b/extensions/source/scanner/sane.hxx @@ -130,7 +130,7 @@ public: { return mppOptions[n]->constraint_type; } const char** GetStringConstraint( int n ) { return const_cast<const char**>(mppOptions[n]->constraint.string_list); } - int GetRange( int, double*& ); + int GetRange( int, std::unique_ptr<double[]>& ); inline int GetOptionElements( int n ); int GetOptionByName( const char* ); diff --git a/extensions/source/scanner/sanedlg.cxx b/extensions/source/scanner/sanedlg.cxx index f7062a13f283..ff4e7db39e14 100644 --- a/extensions/source/scanner/sanedlg.cxx +++ b/extensions/source/scanner/sanedlg.cxx @@ -396,7 +396,7 @@ void SaneDlg::InitFields() mpReslBox->Enable(); mpReslBox->SetValue( static_cast<long>(fRes) ); - double *pDouble = nullptr; + std::unique_ptr<double[]> pDouble; nValue = mrSane.GetRange( nOption, pDouble ); if( nValue > -1 ) { @@ -434,7 +434,6 @@ void SaneDlg::InitFields() } else mpReslBox->Enable( false ); - delete [] pDouble; } } else @@ -485,7 +484,7 @@ void SaneDlg::InitFields() case 3: aBottomRight.setY( static_cast<int>(fValue) );break; } } - double *pDouble = nullptr; + std::unique_ptr<double[]> pDouble; nValue = mrSane.GetRange( nOption, pDouble ); if( nValue > -1 ) { @@ -513,7 +512,6 @@ void SaneDlg::InitFields() case 3: aMaxBottomRight.setY( static_cast<int>(fValue) );break; } } - delete [] pDouble; pField->Enable(); } else @@ -787,7 +785,7 @@ IMPL_LINK( SaneDlg, ModifyHdl, Edit&, rEdit, void ) int nOption = mrSane.GetOptionByName( "resolution" ); if( nOption != -1 ) { - double* pDouble = nullptr; + std::unique_ptr<double[]> pDouble; int nValues = mrSane.GetRange( nOption, pDouble ); if( nValues > 0 ) { @@ -807,7 +805,6 @@ IMPL_LINK( SaneDlg, ModifyHdl, Edit&, rEdit, void ) if( fRes > pDouble[ 1 ] ) fRes = pDouble[ 1 ]; } - delete[] pDouble; mpReslBox->SetValue( static_cast<sal_uLong>(fRes) ); } } @@ -1021,18 +1018,13 @@ void SaneDlg::EstablishStringRange() void SaneDlg::EstablishQuantumRange() { - if( mpRange ) - { - delete [] mpRange; - mpRange = nullptr; - } + mpRange.reset(); int nValues = mrSane.GetRange( mnCurrentOption, mpRange ); if( nValues == 0 ) { mfMin = mpRange[ 0 ]; mfMax = mpRange[ 1 ]; - delete [] mpRange; - mpRange = nullptr; + mpRange.reset(); EstablishNumericOption(); } else if( nValues > 0 ) @@ -1485,11 +1477,10 @@ bool SaneDlg::SetAdjustedNumericalValue( if( nElement < 0 || nElement >= mrSane.GetOptionElements( nOption ) ) return false; - double* pValues = nullptr; + std::unique_ptr<double[]> pValues; int nValues; if( ( nValues = mrSane.GetRange( nOption, pValues ) ) < 0 ) { - delete [] pValues; return false; } @@ -1516,7 +1507,6 @@ bool SaneDlg::SetAdjustedNumericalValue( if( fValue > pValues[1] ) fValue = pValues[1]; } - delete [] pValues; mrSane.SetOptionValue( nOption, fValue, nElement ); SAL_INFO("extensions.scanner", "yields " << fValue); diff --git a/extensions/source/scanner/sanedlg.hxx b/extensions/source/scanner/sanedlg.hxx index 91dd9843bd1a..87f998a526e9 100644 --- a/extensions/source/scanner/sanedlg.hxx +++ b/extensions/source/scanner/sanedlg.hxx @@ -75,7 +75,7 @@ private: int mnCurrentOption; int mnCurrentElement; - double* mpRange; + std::unique_ptr<double[]> mpRange; double mfMin, mfMax; bool doScan; |