diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2018-01-12 20:24:28 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2018-01-12 20:24:28 +0100 |
commit | 32bd0425cc53bab05f7ab03252b37ccd6abc7dda (patch) | |
tree | 2c92daf8afd33c605525a90e81fee60734cfc327 /extensions/source/scanner | |
parent | c578d1c81274a1c0e5bdbdf5654bb4e186afdf49 (diff) |
More loplugin:cstylecast: extensions
auto-rewrite with <https://gerrit.libreoffice.org/#/c/47798/> "Enable
loplugin:cstylecast for some more cases" plus
solenv/clang-format/reformat-formatted-files
Change-Id: If5cd78704f10a98524a113c67cdc09529f745c74
Diffstat (limited to 'extensions/source/scanner')
-rw-r--r-- | extensions/source/scanner/grid.cxx | 22 | ||||
-rw-r--r-- | extensions/source/scanner/sane.cxx | 50 | ||||
-rw-r--r-- | extensions/source/scanner/sanedlg.cxx | 66 | ||||
-rw-r--r-- | extensions/source/scanner/scanunx.cxx | 8 |
4 files changed, 73 insertions, 73 deletions
diff --git a/extensions/source/scanner/grid.cxx b/extensions/source/scanner/grid.cxx index b0cc583aca43..a5b195756830 100644 --- a/extensions/source/scanner/grid.cxx +++ b/extensions/source/scanner/grid.cxx @@ -315,13 +315,13 @@ Point GridWindow::transform( double x, double y ) { Point aRet; - aRet.X() = (long)( ( x - m_fMinX ) * - (double)m_aGridArea.GetWidth() / ( m_fMaxX - m_fMinX ) + aRet.X() = static_cast<long>( ( x - m_fMinX ) * + static_cast<double>(m_aGridArea.GetWidth()) / ( m_fMaxX - m_fMinX ) + m_aGridArea.Left() ); - aRet.Y() = (long)( + aRet.Y() = static_cast<long>( m_aGridArea.Bottom() - ( y - m_fMinY ) * - (double)m_aGridArea.GetHeight() / ( m_fMaxY - m_fMinY ) ); + static_cast<double>(m_aGridArea.GetHeight()) / ( m_fMaxY - m_fMinY ) ); return aRet; } @@ -331,8 +331,8 @@ void GridWindow::transform( const Point& rOriginal, double& x, double& y ) const long nHeight = m_aGridArea.GetHeight(); if (!nWidth || !nHeight) return; - x = ( rOriginal.X() - m_aGridArea.Left() ) * (m_fMaxX - m_fMinX) / (double)nWidth + m_fMinX; - y = ( m_aGridArea.Bottom() - rOriginal.Y() ) * (m_fMaxY - m_fMinY) / (double)nHeight + m_fMinY; + x = ( rOriginal.X() - m_aGridArea.Left() ) * (m_fMaxX - m_fMinX) / static_cast<double>(nWidth) + m_fMinX; + y = ( m_aGridArea.Bottom() - rOriginal.Y() ) * (m_fMaxY - m_fMinY) / static_cast<double>(nHeight) + m_fMinY; } void GridWindow::drawLine(vcl::RenderContext& rRenderContext, double x1, double y1, double x2, double y2 ) @@ -344,8 +344,8 @@ void GridWindow::computeChunk( double fMin, double fMax, double& fChunkOut, doub { // get a nice chunk size like 10, 100, 25 or such fChunkOut = ( fMax - fMin ) / 6.0; - int logchunk = (int)std::log10( fChunkOut ); - int nChunk = (int)( fChunkOut / std::exp( (double)(logchunk-1) * M_LN10 ) ); + int logchunk = static_cast<int>(std::log10( fChunkOut )); + int nChunk = static_cast<int>( fChunkOut / std::exp( static_cast<double>(logchunk-1) * M_LN10 ) ); if( nChunk >= 75 ) nChunk = 100; else if( nChunk >= 35 ) @@ -358,10 +358,10 @@ void GridWindow::computeChunk( double fMin, double fMax, double& fChunkOut, doub nChunk = 10; else nChunk = 5; - fChunkOut = (double) nChunk * exp( (double)(logchunk-1) * M_LN10 ); + fChunkOut = static_cast<double>(nChunk) * exp( static_cast<double>(logchunk-1) * M_LN10 ); // compute whole chunks fitting into fMin - nChunk = (int)( fMin / fChunkOut ); - fMinChunkOut = (double)nChunk * fChunkOut; + nChunk = static_cast<int>( fMin / fChunkOut ); + fMinChunkOut = static_cast<double>(nChunk) * fChunkOut; while( fMinChunkOut < fMin ) fMinChunkOut += fChunkOut; } diff --git a/extensions/source/scanner/sane.cxx b/extensions/source/scanner/sane.cxx index a22cda021bd4..be0d5bd40527 100644 --- a/extensions/source/scanner/sane.cxx +++ b/extensions/source/scanner/sane.cxx @@ -123,7 +123,7 @@ SANE_Status Sane::ControlOption( int nOption, SANE_Action nAction, { SANE_Int nInfo = 0; - SANE_Status nStatus = p_control_option( maHandle, (SANE_Int)nOption, + SANE_Status nStatus = p_control_option( maHandle, static_cast<SANE_Int>(nOption), nAction, pData, &nInfo ); DUMP_STATE( nStatus, "sane_control_option" ); #if OSL_DEBUG_LEVEL > 0 @@ -271,7 +271,7 @@ void Sane::ReloadOptions() fprintf( stderr, "Error: sane driver returned %s while reading number of options !\n", p_strstatus( nStatus ) ); mnOptions = pOptions[ 0 ]; - if( (size_t)pZero->size > sizeof( SANE_Word ) ) + if( static_cast<size_t>(pZero->size) > sizeof( SANE_Word ) ) fprintf( stderr, "driver returned numer of options with larger size tha SANE_Word !!!\n" ); if( mppOptions ) delete [] mppOptions; @@ -384,7 +384,7 @@ bool Sane::GetOptionValue( int n, double& rRet, int nElement ) { bSuccess = true; if( mppOptions[n]->type == SANE_TYPE_INT ) - rRet = (double)pRet[ nElement ]; + rRet = static_cast<double>(pRet[ nElement ]); else rRet = SANE_UNFIX( pRet[nElement] ); } @@ -406,7 +406,7 @@ bool Sane::GetOptionValue( int n, double* pSet ) if( mppOptions[n]->type == SANE_TYPE_FIXED ) pSet[i] = SANE_UNFIX( pFixedSet[i] ); else - pSet[i] = (double) pFixedSet[i]; + pSet[i] = static_cast<double>(pFixedSet[i]); } return true; } @@ -440,7 +440,7 @@ void Sane::SetOptionValue( int n, double fSet, int nElement ) if( nStatus == SANE_STATUS_GOOD ) { pSet[nElement] = mppOptions[n]->type == SANE_TYPE_INT ? - (SANE_Word)fSet : SANE_FIX( fSet ); + static_cast<SANE_Word>(fSet) : SANE_FIX( fSet ); ControlOption( n, SANE_ACTION_SET_VALUE, pSet.get() ); } } @@ -448,7 +448,7 @@ void Sane::SetOptionValue( int n, double fSet, int nElement ) { SANE_Word nSetTo = mppOptions[n]->type == SANE_TYPE_INT ? - (SANE_Word)fSet : SANE_FIX( fSet ); + static_cast<SANE_Word>(fSet) : SANE_FIX( fSet ); ControlOption( n, SANE_ACTION_SET_VALUE, &nSetTo ); } @@ -465,7 +465,7 @@ void Sane::SetOptionValue( int n, double const * pSet ) if( mppOptions[n]->type == SANE_TYPE_FIXED ) pFixedSet[i] = SANE_FIX( pSet[i] ); else - pFixedSet[i] = (SANE_Word)pSet[i]; + pFixedSet[i] = static_cast<SANE_Word>(pSet[i]); } ControlOption( n, SANE_ACTION_SET_VALUE, pFixedSet.get() ); } @@ -494,7 +494,7 @@ static inline sal_uInt8 ReadValue( FILE* fp, int depth ) return 0; } - return (sal_uInt8)( nWord / 256 ); + return static_cast<sal_uInt8>( nWord / 256 ); } sal_uInt8 nByte; size_t items_read = fread( &nByte, 1, 1, fp ); @@ -556,7 +556,7 @@ bool Sane::Start( BitmapTransporter& rBitmap ) GetOptionValue( nOption, fBRx ) && GetOptionUnit( nOption ) == SANE_UNIT_MM ) { - nWidthMM = (int)fabs(fBRx - fTLx); + nWidthMM = static_cast<int>(fabs(fBRx - fTLx)); } } if( ( nOption = GetOptionByName( "tl-y" ) ) != -1 && @@ -568,7 +568,7 @@ bool Sane::Start( BitmapTransporter& rBitmap ) GetOptionValue( nOption, fBRy ) && GetOptionUnit( nOption ) == SANE_UNIT_MM ) { - nHeightMM = (int)fabs(fBRy - fTLy); + nHeightMM = static_cast<int>(fabs(fBRy - fTLy)); } } if( ( nOption = GetOptionByName( "resolution" ) ) != -1 ) @@ -632,11 +632,11 @@ bool Sane::Start( BitmapTransporter& rBitmap ) { aParams.format = (SANE_Frame)5; } - fprintf( stderr, "format: %s\n", ppFormats[ (int)aParams.format ] ); + fprintf( stderr, "format: %s\n", ppFormats[ static_cast<int>(aParams.format) ] ); fprintf( stderr, "last_frame: %s\n", aParams.last_frame ? "TRUE" : "FALSE" ); - fprintf( stderr, "depth: %d\n", (int)aParams.depth ); - fprintf( stderr, "pixels_per_line: %d\n", (int)aParams.pixels_per_line ); - fprintf( stderr, "bytes_per_line: %d\n", (int)aParams.bytes_per_line ); + fprintf( stderr, "depth: %d\n", static_cast<int>(aParams.depth) ); + fprintf( stderr, "pixels_per_line: %d\n", static_cast<int>(aParams.pixels_per_line) ); + fprintf( stderr, "bytes_per_line: %d\n", static_cast<int>(aParams.bytes_per_line) ); #endif if( ! pBuffer ) { @@ -707,7 +707,7 @@ bool Sane::Start( BitmapTransporter& rBitmap ) struct timeval tv; FD_ZERO( &fdset ); - FD_SET( (int)fd, &fdset ); + FD_SET( static_cast<int>(fd), &fdset ); tv.tv_sec = 5; tv.tv_usec = 0; if( select( fd+1, &fdset, nullptr, nullptr, &tv ) == 0 ) @@ -735,16 +735,16 @@ bool Sane::Start( BitmapTransporter& rBitmap ) int nFrameLength = ftell( pFrame ); fseek( pFrame, 0, SEEK_SET ); - sal_uInt32 nWidth = (sal_uInt32) aParams.pixels_per_line; - sal_uInt32 nHeight = (sal_uInt32) (nFrameLength / aParams.bytes_per_line); + sal_uInt32 nWidth = static_cast<sal_uInt32>(aParams.pixels_per_line); + sal_uInt32 nHeight = static_cast<sal_uInt32>(nFrameLength / aParams.bytes_per_line); if( ! bWidthSet ) { if( ! fResl ) fResl = 300; // if all else fails that's a good guess if( ! nWidthMM ) - nWidthMM = (int)(((double)nWidth / fResl) * 25.4); + nWidthMM = static_cast<int>((static_cast<double>(nWidth) / fResl) * 25.4); if( ! nHeightMM ) - nHeightMM = (int)(((double)nHeight / fResl) * 25.4); + nHeightMM = static_cast<int>((static_cast<double>(nHeight) / fResl) * 25.4); SAL_INFO("extensions.scanner", "set dimensions to(" << nWidth << ", " << nHeight << ") Pixel, (" << nWidthMM << ", " << nHeightMM << ") mm, resolution is " << fResl); @@ -915,15 +915,15 @@ int Sane::GetRange( int n, double*& rpDouble ) } else { - fMin = (double)mppOptions[n]->constraint.range->min; - fMax = (double)mppOptions[n]->constraint.range->max; - fQuant = (double)mppOptions[n]->constraint.range->quant; + fMin = static_cast<double>(mppOptions[n]->constraint.range->min); + fMax = static_cast<double>(mppOptions[n]->constraint.range->max); + fQuant = static_cast<double>(mppOptions[n]->constraint.range->quant); } if( fQuant != 0.0 ) { dbg_msg( "quantum range [ %lg ; %lg ; %lg ]\n", fMin, fQuant, fMax ); - nItems = (int)((fMax - fMin)/fQuant)+1; + nItems = static_cast<int>((fMax - fMin)/fQuant)+1; rpDouble = new double[ nItems ]; double fValue = fMin; for( i = 0; i < nItems; i++, fValue += fQuant ) @@ -949,7 +949,7 @@ int Sane::GetRange( int n, double*& rpDouble ) { rpDouble[i] = bIsFixed ? SANE_UNFIX( mppOptions[n]->constraint.word_list[i+1] ) : - (double)mppOptions[n]->constraint.word_list[i+1]; + static_cast<double>(mppOptions[n]->constraint.word_list[i+1]); } dbg_msg( "wordlist [ %lg ... %lg ]\n", rpDouble[ 0 ], rpDouble[ nItems-1 ] ); @@ -971,7 +971,7 @@ OUString Sane::GetOptionUnitName( int n ) { OUString aText; SANE_Unit nUnit = mppOptions[n]->unit; - size_t nUnitAsSize = (size_t)nUnit; + size_t nUnitAsSize = static_cast<size_t>(nUnit); if (nUnitAsSize >= SAL_N_ELEMENTS( ppUnits )) aText = "[unknown units]"; else diff --git a/extensions/source/scanner/sanedlg.cxx b/extensions/source/scanner/sanedlg.cxx index 83bea0e05367..5a35b7f1026b 100644 --- a/extensions/source/scanner/sanedlg.cxx +++ b/extensions/source/scanner/sanedlg.cxx @@ -393,7 +393,7 @@ void SaneDlg::InitFields() { mpReslBox->Enable(); - mpReslBox->SetValue( (long)fRes ); + mpReslBox->SetValue( static_cast<long>(fRes) ); double *pDouble = nullptr; nValue = mrSane.GetRange( nOption, pDouble ); if( nValue > -1 ) @@ -401,33 +401,33 @@ void SaneDlg::InitFields() assert(pDouble); if( nValue ) { - mpReslBox->SetMin( (long)pDouble[0] ); - mpReslBox->SetMax( (long)pDouble[ nValue-1 ] ); + mpReslBox->SetMin( static_cast<long>(pDouble[0]) ); + mpReslBox->SetMax( static_cast<long>(pDouble[ nValue-1 ]) ); for( i=0; i<nValue; i++ ) { - if( i == 0 || i == nValue-1 || ! ( ((int)pDouble[i]) % 20) ) - mpReslBox->InsertValue( (long)pDouble[i] ); + if( i == 0 || i == nValue-1 || ! ( static_cast<int>(pDouble[i]) % 20) ) + mpReslBox->InsertValue( static_cast<long>(pDouble[i]) ); } } else { - mpReslBox->SetMin( (long)pDouble[0] ); - mpReslBox->SetMax( (long)pDouble[1] ); - mpReslBox->InsertValue( (long)pDouble[0] ); + mpReslBox->SetMin( static_cast<long>(pDouble[0]) ); + mpReslBox->SetMax( static_cast<long>(pDouble[1]) ); + mpReslBox->InsertValue( static_cast<long>(pDouble[0]) ); // Can only select 75 and 2400 dpi in Scanner dialogue // scanner allows random setting of dpi resolution, a slider might be useful // support that // workaround: offer at least some more standard dpi resolution between // min and max value int bGot300 = 0; - for ( long nRes = (long) pDouble[0] * 2; nRes < (long) pDouble[1]; nRes = nRes * 2 ) + for ( long nRes = static_cast<long>(pDouble[0]) * 2; nRes < static_cast<long>(pDouble[1]); nRes = nRes * 2 ) { if ( !bGot300 && nRes > 300 ) { nRes = 300; bGot300 = 1; } mpReslBox->InsertValue(nRes); } - mpReslBox->InsertValue( (long)pDouble[1] ); + mpReslBox->InsertValue( static_cast<long>(pDouble[1]) ); } } else @@ -469,18 +469,18 @@ void SaneDlg::InitFields() if( mrSane.GetOptionUnit( nOption ) == SANE_UNIT_MM ) { pField->SetUnit( FUNIT_MM ); - pField->SetValue( (int)fValue, FUNIT_MM ); + pField->SetValue( static_cast<int>(fValue), FUNIT_MM ); } else // SANE_UNIT_PIXEL { - pField->SetValue( (int)fValue, FUNIT_CUSTOM ); + pField->SetValue( static_cast<int>(fValue), FUNIT_CUSTOM ); pField->SetCustomUnitText("Pixel"); } switch( i ) { - case 0: aTopLeft.X() = (int)fValue;break; - case 1: aTopLeft.Y() = (int)fValue;break; - case 2: aBottomRight.X() = (int)fValue;break; - case 3: aBottomRight.Y() = (int)fValue;break; + case 0: aTopLeft.X() = static_cast<int>(fValue);break; + case 1: aTopLeft.Y() = static_cast<int>(fValue);break; + case 2: aBottomRight.X() = static_cast<int>(fValue);break; + case 3: aBottomRight.Y() = static_cast<int>(fValue);break; } } double *pDouble = nullptr; @@ -489,11 +489,11 @@ void SaneDlg::InitFields() { if( pDouble ) { - pField->SetMin( (long)pDouble[0] ); + pField->SetMin( static_cast<long>(pDouble[0]) ); if( nValue ) - pField->SetMax( (long)pDouble[ nValue-1 ] ); + pField->SetMax( static_cast<long>(pDouble[ nValue-1 ]) ); else - pField->SetMax( (long)pDouble[ 1 ] ); + pField->SetMax( static_cast<long>(pDouble[ 1 ]) ); delete [] pDouble; } switch( i ) { @@ -506,10 +506,10 @@ void SaneDlg::InitFields() else { switch( i ) { - case 0: aMinTopLeft.X() = (int)fValue;break; - case 1: aMinTopLeft.Y() = (int)fValue;break; - case 2: aMaxBottomRight.X() = (int)fValue;break; - case 3: aMaxBottomRight.Y() = (int)fValue;break; + case 0: aMinTopLeft.X() = static_cast<int>(fValue);break; + case 1: aMinTopLeft.Y() = static_cast<int>(fValue);break; + case 2: aMaxBottomRight.X() = static_cast<int>(fValue);break; + case 3: aMaxBottomRight.Y() = static_cast<int>(fValue);break; } } pField->Enable(); @@ -636,7 +636,7 @@ IMPL_LINK( SaneDlg, ClickBtnHdl, Button*, pButton, void ) std::unique_ptr<double[]> x(new double[ nElements ]); std::unique_ptr<double[]> y(new double[ nElements ]); for( int i = 0; i < nElements; i++ ) - x[ i ] = (double)i; + x[ i ] = static_cast<double>(i); mrSane.GetOptionValue( mnCurrentOption, y.get() ); ScopedVclPtrInstance< GridDialog > aGrid( x.get(), y.get(), nElements, this ); @@ -659,7 +659,7 @@ IMPL_LINK( SaneDlg, ClickBtnHdl, Button*, pButton, void ) } if( pButton == mpOKButton || pButton == mpScanButton ) { - double fRes = (double)mpReslBox->GetValue(); + double fRes = static_cast<double>(mpReslBox->GetValue()); SetAdjustedNumericalValue( "resolution", fRes ); UpdateScanArea(true); SaveState(); @@ -779,7 +779,7 @@ IMPL_LINK( SaneDlg, ModifyHdl, Edit&, rEdit, void ) } else if( &rEdit == mpReslBox ) { - double fRes = (double)mpReslBox->GetValue(); + double fRes = static_cast<double>(mpReslBox->GetValue()); int nOption = mrSane.GetOptionByName( "resolution" ); if( nOption != -1 ) { @@ -804,7 +804,7 @@ IMPL_LINK( SaneDlg, ModifyHdl, Edit&, rEdit, void ) fRes = pDouble[ 1 ]; } delete[] pDouble; - mpReslBox->SetValue( (sal_uLong)fRes ); + mpReslBox->SetValue( static_cast<sal_uLong>(fRes) ); } } else if( &rEdit == mpNumericEdit ) @@ -874,7 +874,7 @@ void SaneDlg::AcquirePreview() UpdateScanArea( true ); // set small resolution for preview - double fResl = (double)mpReslBox->GetValue(); + double fResl = static_cast<double>(mpReslBox->GetValue()); SetAdjustedNumericalValue( "resolution", 30.0 ); int nOption = mrSane.GetOptionByName( "preview" ); @@ -905,7 +905,7 @@ void SaneDlg::AcquirePreview() } SetAdjustedNumericalValue( "resolution", fResl ); - mpReslBox->SetValue( (sal_uLong)fResl ); + mpReslBox->SetValue( static_cast<sal_uLong>(fResl) ); mpPreview->UpdatePreviewBounds(); mpPreview->Invalidate(); @@ -1299,10 +1299,10 @@ void SaneDlg::UpdateScanArea(bool bSend) if( mrSane.IsOpen() ) { - SetAdjustedNumericalValue( "tl-x", (double)aUL.X() ); - SetAdjustedNumericalValue( "tl-y", (double)aUL.Y() ); - SetAdjustedNumericalValue( "br-x", (double)aBR.X() ); - SetAdjustedNumericalValue( "br-y", (double)aBR.Y() ); + SetAdjustedNumericalValue( "tl-x", static_cast<double>(aUL.X()) ); + SetAdjustedNumericalValue( "tl-y", static_cast<double>(aUL.Y()) ); + SetAdjustedNumericalValue( "br-x", static_cast<double>(aBR.X()) ); + SetAdjustedNumericalValue( "br-y", static_cast<double>(aBR.Y()) ); } } diff --git a/extensions/source/scanner/scanunx.cxx b/extensions/source/scanner/scanunx.cxx index 45015ef127f1..20fdb2b52e70 100644 --- a/extensions/source/scanner/scanunx.cxx +++ b/extensions/source/scanner/scanunx.cxx @@ -248,7 +248,7 @@ sal_Bool ScannerManager::configureScannerAndScan( ScannerContext& scanner_contex SAL_INFO("extensions.scanner", "ScannerManager::configureScanner"); - if( scanner_context.InternalData < 0 || (sal_uLong)scanner_context.InternalData >= rSanes.size() ) + if( scanner_context.InternalData < 0 || static_cast<sal_uLong>(scanner_context.InternalData) >= rSanes.size() ) throw ScannerException( "Scanner does not exist", Reference< XScannerManager >( this ), @@ -284,7 +284,7 @@ void ScannerManager::startScan( const ScannerContext& scanner_context, SAL_INFO("extensions.scanner", "ScannerManager::startScan"); - if( scanner_context.InternalData < 0 || (sal_uLong)scanner_context.InternalData >= rSanes.size() ) + if( scanner_context.InternalData < 0 || static_cast<sal_uLong>(scanner_context.InternalData) >= rSanes.size() ) throw ScannerException( "Scanner does not exist", Reference< XScannerManager >( this ), @@ -309,7 +309,7 @@ ScanError ScannerManager::getError( const ScannerContext& scanner_context ) osl::MutexGuard aGuard( theSaneProtector::get() ); sanevec &rSanes = theSanes::get().m_aSanes; - if( scanner_context.InternalData < 0 || (sal_uLong)scanner_context.InternalData >= rSanes.size() ) + if( scanner_context.InternalData < 0 || static_cast<sal_uLong>(scanner_context.InternalData) >= rSanes.size() ) throw ScannerException( "Scanner does not exist", Reference< XScannerManager >( this ), @@ -327,7 +327,7 @@ Reference< css::awt::XBitmap > ScannerManager::getBitmap( const ScannerContext& osl::MutexGuard aGuard( theSaneProtector::get() ); sanevec &rSanes = theSanes::get().m_aSanes; - if( scanner_context.InternalData < 0 || (sal_uLong)scanner_context.InternalData >= rSanes.size() ) + if( scanner_context.InternalData < 0 || static_cast<sal_uLong>(scanner_context.InternalData) >= rSanes.size() ) throw ScannerException( "Scanner does not exist", Reference< XScannerManager >( this ), |