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 )
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 ?
......
......@@ -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* );
......
......@@ -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);
......
......@@ -75,7 +75,7 @@ private:
int mnCurrentOption;
int mnCurrentElement;
double* mpRange;
std::unique_ptr<double[]> mpRange;
double mfMin, mfMax;
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