Kaydet (Commit) 858e6b26 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in SaneDlg

Change-Id: I712b733c9c24db2e2fcdc4b6ce16e38eaf0b27f0
Reviewed-on: https://gerrit.libreoffice.org/54167Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 6a017237
...@@ -888,7 +888,7 @@ bool Sane::Start( BitmapTransporter& rBitmap ) ...@@ -888,7 +888,7 @@ bool Sane::Start( BitmapTransporter& rBitmap )
return bSuccess; 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 && if( mppOptions[n]->constraint_type != SANE_CONSTRAINT_RANGE &&
mppOptions[n]->constraint_type != SANE_CONSTRAINT_WORD_LIST ) mppOptions[n]->constraint_type != SANE_CONSTRAINT_WORD_LIST )
...@@ -921,7 +921,7 @@ int Sane::GetRange( int n, double*& rpDouble ) ...@@ -921,7 +921,7 @@ int Sane::GetRange( int n, double*& rpDouble )
dbg_msg( "quantum range [ %lg ; %lg ; %lg ]\n", dbg_msg( "quantum range [ %lg ; %lg ; %lg ]\n",
fMin, fQuant, fMax ); fMin, fQuant, fMax );
nItems = static_cast<int>((fMax - fMin)/fQuant)+1; nItems = static_cast<int>((fMax - fMin)/fQuant)+1;
rpDouble = new double[ nItems ]; rpDouble.reset(new double[ nItems ]);
double fValue = fMin; double fValue = fMin;
for( i = 0; i < nItems; i++, fValue += fQuant ) for( i = 0; i < nItems; i++, fValue += fQuant )
rpDouble[i] = fValue; rpDouble[i] = fValue;
...@@ -932,7 +932,7 @@ int Sane::GetRange( int n, double*& rpDouble ) ...@@ -932,7 +932,7 @@ int Sane::GetRange( int n, double*& rpDouble )
{ {
dbg_msg( "normal range [ %lg %lg ]\n", dbg_msg( "normal range [ %lg %lg ]\n",
fMin, fMax ); fMin, fMax );
rpDouble = new double[2]; rpDouble.reset(new double[2]);
rpDouble[0] = fMin; rpDouble[0] = fMin;
rpDouble[1] = fMax; rpDouble[1] = fMax;
return 0; return 0;
...@@ -941,7 +941,7 @@ int Sane::GetRange( int n, double*& rpDouble ) ...@@ -941,7 +941,7 @@ int Sane::GetRange( int n, double*& rpDouble )
else else
{ {
nItems = mppOptions[n]->constraint.word_list[0]; nItems = mppOptions[n]->constraint.word_list[0];
rpDouble = new double[nItems]; rpDouble.reset(new double[nItems]);
for( i=0; i<nItems; i++ ) for( i=0; i<nItems; i++ )
{ {
rpDouble[i] = bIsFixed ? rpDouble[i] = bIsFixed ?
......
...@@ -130,7 +130,7 @@ public: ...@@ -130,7 +130,7 @@ public:
{ return mppOptions[n]->constraint_type; } { return mppOptions[n]->constraint_type; }
const char** GetStringConstraint( int n ) const char** GetStringConstraint( int n )
{ return const_cast<const char**>(mppOptions[n]->constraint.string_list); } { 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 ); inline int GetOptionElements( int n );
int GetOptionByName( const char* ); int GetOptionByName( const char* );
......
...@@ -396,7 +396,7 @@ void SaneDlg::InitFields() ...@@ -396,7 +396,7 @@ void SaneDlg::InitFields()
mpReslBox->Enable(); mpReslBox->Enable();
mpReslBox->SetValue( static_cast<long>(fRes) ); mpReslBox->SetValue( static_cast<long>(fRes) );
double *pDouble = nullptr; std::unique_ptr<double[]> pDouble;
nValue = mrSane.GetRange( nOption, pDouble ); nValue = mrSane.GetRange( nOption, pDouble );
if( nValue > -1 ) if( nValue > -1 )
{ {
...@@ -434,7 +434,6 @@ void SaneDlg::InitFields() ...@@ -434,7 +434,6 @@ void SaneDlg::InitFields()
} }
else else
mpReslBox->Enable( false ); mpReslBox->Enable( false );
delete [] pDouble;
} }
} }
else else
...@@ -485,7 +484,7 @@ void SaneDlg::InitFields() ...@@ -485,7 +484,7 @@ void SaneDlg::InitFields()
case 3: aBottomRight.setY( static_cast<int>(fValue) );break; case 3: aBottomRight.setY( static_cast<int>(fValue) );break;
} }
} }
double *pDouble = nullptr; std::unique_ptr<double[]> pDouble;
nValue = mrSane.GetRange( nOption, pDouble ); nValue = mrSane.GetRange( nOption, pDouble );
if( nValue > -1 ) if( nValue > -1 )
{ {
...@@ -513,7 +512,6 @@ void SaneDlg::InitFields() ...@@ -513,7 +512,6 @@ void SaneDlg::InitFields()
case 3: aMaxBottomRight.setY( static_cast<int>(fValue) );break; case 3: aMaxBottomRight.setY( static_cast<int>(fValue) );break;
} }
} }
delete [] pDouble;
pField->Enable(); pField->Enable();
} }
else else
...@@ -787,7 +785,7 @@ IMPL_LINK( SaneDlg, ModifyHdl, Edit&, rEdit, void ) ...@@ -787,7 +785,7 @@ IMPL_LINK( SaneDlg, ModifyHdl, Edit&, rEdit, void )
int nOption = mrSane.GetOptionByName( "resolution" ); int nOption = mrSane.GetOptionByName( "resolution" );
if( nOption != -1 ) if( nOption != -1 )
{ {
double* pDouble = nullptr; std::unique_ptr<double[]> pDouble;
int nValues = mrSane.GetRange( nOption, pDouble ); int nValues = mrSane.GetRange( nOption, pDouble );
if( nValues > 0 ) if( nValues > 0 )
{ {
...@@ -807,7 +805,6 @@ IMPL_LINK( SaneDlg, ModifyHdl, Edit&, rEdit, void ) ...@@ -807,7 +805,6 @@ IMPL_LINK( SaneDlg, ModifyHdl, Edit&, rEdit, void )
if( fRes > pDouble[ 1 ] ) if( fRes > pDouble[ 1 ] )
fRes = pDouble[ 1 ]; fRes = pDouble[ 1 ];
} }
delete[] pDouble;
mpReslBox->SetValue( static_cast<sal_uLong>(fRes) ); mpReslBox->SetValue( static_cast<sal_uLong>(fRes) );
} }
} }
...@@ -1021,18 +1018,13 @@ void SaneDlg::EstablishStringRange() ...@@ -1021,18 +1018,13 @@ void SaneDlg::EstablishStringRange()
void SaneDlg::EstablishQuantumRange() void SaneDlg::EstablishQuantumRange()
{ {
if( mpRange ) mpRange.reset();
{
delete [] mpRange;
mpRange = nullptr;
}
int nValues = mrSane.GetRange( mnCurrentOption, mpRange ); int nValues = mrSane.GetRange( mnCurrentOption, mpRange );
if( nValues == 0 ) if( nValues == 0 )
{ {
mfMin = mpRange[ 0 ]; mfMin = mpRange[ 0 ];
mfMax = mpRange[ 1 ]; mfMax = mpRange[ 1 ];
delete [] mpRange; mpRange.reset();
mpRange = nullptr;
EstablishNumericOption(); EstablishNumericOption();
} }
else if( nValues > 0 ) else if( nValues > 0 )
...@@ -1485,11 +1477,10 @@ bool SaneDlg::SetAdjustedNumericalValue( ...@@ -1485,11 +1477,10 @@ bool SaneDlg::SetAdjustedNumericalValue(
if( nElement < 0 || nElement >= mrSane.GetOptionElements( nOption ) ) if( nElement < 0 || nElement >= mrSane.GetOptionElements( nOption ) )
return false; return false;
double* pValues = nullptr; std::unique_ptr<double[]> pValues;
int nValues; int nValues;
if( ( nValues = mrSane.GetRange( nOption, pValues ) ) < 0 ) if( ( nValues = mrSane.GetRange( nOption, pValues ) ) < 0 )
{ {
delete [] pValues;
return false; return false;
} }
...@@ -1516,7 +1507,6 @@ bool SaneDlg::SetAdjustedNumericalValue( ...@@ -1516,7 +1507,6 @@ bool SaneDlg::SetAdjustedNumericalValue(
if( fValue > pValues[1] ) if( fValue > pValues[1] )
fValue = pValues[1]; fValue = pValues[1];
} }
delete [] pValues;
mrSane.SetOptionValue( nOption, fValue, nElement ); mrSane.SetOptionValue( nOption, fValue, nElement );
SAL_INFO("extensions.scanner", "yields " << fValue); SAL_INFO("extensions.scanner", "yields " << fValue);
......
...@@ -75,7 +75,7 @@ private: ...@@ -75,7 +75,7 @@ private:
int mnCurrentOption; int mnCurrentOption;
int mnCurrentElement; int mnCurrentElement;
double* mpRange; std::unique_ptr<double[]> mpRange;
double mfMin, mfMax; double mfMin, mfMax;
bool doScan; bool doScan;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment