diff options
author | Arkadiy Illarionov <qarkai@gmail.com> | 2018-12-19 21:53:06 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-12-20 08:15:54 +0100 |
commit | b38e690296e48657ec8c66427a6511f42f4b0115 (patch) | |
tree | 3ddf7f7df1bdba73552efa4a97cef92dff0bb4da /sccomp/source | |
parent | 45f0c58c615e1caf2bc8630924e2e4c89ac7bc4d (diff) |
Simplify containers iterations in scaddins, sccomp, scripting
Use range-based loop or replace with STL functions
Change-Id: I21ec2eea8f322e2792097d352fc352dc6099c7b7
Reviewed-on: https://gerrit.libreoffice.org/65461
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sccomp/source')
-rw-r--r-- | sccomp/source/solver/CoinMPSolver.cxx | 36 | ||||
-rw-r--r-- | sccomp/source/solver/LpsolveSolver.cxx | 36 |
2 files changed, 34 insertions, 38 deletions
diff --git a/sccomp/source/solver/CoinMPSolver.cxx b/sccomp/source/solver/CoinMPSolver.cxx index dbd19a4d9f43..d227e48d5f0f 100644 --- a/sccomp/source/solver/CoinMPSolver.cxx +++ b/sccomp/source/solver/CoinMPSolver.cxx @@ -86,40 +86,38 @@ void SAL_CALL CoinMPSolver::solve() // set all variables to zero //! store old values? //! use old values as initial values? - std::vector<table::CellAddress>::const_iterator aVarIter; - for ( aVarIter = aVariableCells.begin(); aVarIter != aVariableCells.end(); ++aVarIter ) + for ( const auto& rVarCell : aVariableCells ) { - SolverComponent::SetValue( mxDoc, *aVarIter, 0.0 ); + SolverComponent::SetValue( mxDoc, rVarCell, 0.0 ); } // read initial values from all dependent cells - ScSolverCellHashMap::iterator aCellsIter; - for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + for ( auto& rEntry : aCellsHash ) { - double fValue = SolverComponent::GetValue( mxDoc, aCellsIter->first ); - aCellsIter->second.push_back( fValue ); // store as first element, as-is + double fValue = SolverComponent::GetValue( mxDoc, rEntry.first ); + rEntry.second.push_back( fValue ); // store as first element, as-is } // loop through variables - for ( aVarIter = aVariableCells.begin(); aVarIter != aVariableCells.end(); ++aVarIter ) + for ( const auto& rVarCell : aVariableCells ) { - SolverComponent::SetValue( mxDoc, *aVarIter, 1.0 ); // set to 1 to examine influence + SolverComponent::SetValue( mxDoc, rVarCell, 1.0 ); // set to 1 to examine influence // read value change from all dependent cells - for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + for ( auto& rEntry : aCellsHash ) { - double fChanged = SolverComponent::GetValue( mxDoc, aCellsIter->first ); - double fInitial = aCellsIter->second.front(); - aCellsIter->second.push_back( fChanged - fInitial ); + double fChanged = SolverComponent::GetValue( mxDoc, rEntry.first ); + double fInitial = rEntry.second.front(); + rEntry.second.push_back( fChanged - fInitial ); } - SolverComponent::SetValue( mxDoc, *aVarIter, 2.0 ); // minimal test for linearity + SolverComponent::SetValue( mxDoc, rVarCell, 2.0 ); // minimal test for linearity - for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + for ( const auto& rEntry : aCellsHash ) { - double fInitial = aCellsIter->second.front(); - double fCoeff = aCellsIter->second.back(); // last appended: coefficient for this variable - double fTwo = SolverComponent::GetValue( mxDoc, aCellsIter->first ); + double fInitial = rEntry.second.front(); + double fCoeff = rEntry.second.back(); // last appended: coefficient for this variable + double fTwo = SolverComponent::GetValue( mxDoc, rEntry.first ); bool bLinear = rtl::math::approxEqual( fTwo, fInitial + 2.0 * fCoeff ) || rtl::math::approxEqual( fInitial, fTwo - 2.0 * fCoeff ); @@ -128,7 +126,7 @@ void SAL_CALL CoinMPSolver::solve() maStatus = SolverComponent::GetResourceString( RID_ERROR_NONLINEAR ); } - SolverComponent::SetValue( mxDoc, *aVarIter, 0.0 ); // set back to zero for examining next variable + SolverComponent::SetValue( mxDoc, rVarCell, 0.0 ); // set back to zero for examining next variable } xModel->unlockControllers(); diff --git a/sccomp/source/solver/LpsolveSolver.cxx b/sccomp/source/solver/LpsolveSolver.cxx index 08b56ff1f9e9..0eb7d08dafd6 100644 --- a/sccomp/source/solver/LpsolveSolver.cxx +++ b/sccomp/source/solver/LpsolveSolver.cxx @@ -123,40 +123,38 @@ void SAL_CALL LpsolveSolver::solve() // set all variables to zero //! store old values? //! use old values as initial values? - std::vector<table::CellAddress>::const_iterator aVarIter; - for ( aVarIter = aVariableCells.begin(); aVarIter != aVariableCells.end(); ++aVarIter ) + for ( const auto& rVarCell : aVariableCells ) { - SolverComponent::SetValue( mxDoc, *aVarIter, 0.0 ); + SolverComponent::SetValue( mxDoc, rVarCell, 0.0 ); } // read initial values from all dependent cells - ScSolverCellHashMap::iterator aCellsIter; - for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + for ( auto& rEntry : aCellsHash ) { - double fValue = SolverComponent::GetValue( mxDoc, aCellsIter->first ); - aCellsIter->second.push_back( fValue ); // store as first element, as-is + double fValue = SolverComponent::GetValue( mxDoc, rEntry.first ); + rEntry.second.push_back( fValue ); // store as first element, as-is } // loop through variables - for ( aVarIter = aVariableCells.begin(); aVarIter != aVariableCells.end(); ++aVarIter ) + for ( const auto& rVarCell : aVariableCells ) { - SolverComponent::SetValue( mxDoc, *aVarIter, 1.0 ); // set to 1 to examine influence + SolverComponent::SetValue( mxDoc, rVarCell, 1.0 ); // set to 1 to examine influence // read value change from all dependent cells - for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + for ( auto& rEntry : aCellsHash ) { - double fChanged = SolverComponent::GetValue( mxDoc, aCellsIter->first ); - double fInitial = aCellsIter->second.front(); - aCellsIter->second.push_back( fChanged - fInitial ); + double fChanged = SolverComponent::GetValue( mxDoc, rEntry.first ); + double fInitial = rEntry.second.front(); + rEntry.second.push_back( fChanged - fInitial ); } - SolverComponent::SetValue( mxDoc, *aVarIter, 2.0 ); // minimal test for linearity + SolverComponent::SetValue( mxDoc, rVarCell, 2.0 ); // minimal test for linearity - for ( aCellsIter = aCellsHash.begin(); aCellsIter != aCellsHash.end(); ++aCellsIter ) + for ( const auto& rEntry : aCellsHash ) { - double fInitial = aCellsIter->second.front(); - double fCoeff = aCellsIter->second.back(); // last appended: coefficient for this variable - double fTwo = SolverComponent::GetValue( mxDoc, aCellsIter->first ); + double fInitial = rEntry.second.front(); + double fCoeff = rEntry.second.back(); // last appended: coefficient for this variable + double fTwo = SolverComponent::GetValue( mxDoc, rEntry.first ); bool bLinear = rtl::math::approxEqual( fTwo, fInitial + 2.0 * fCoeff ) || rtl::math::approxEqual( fInitial, fTwo - 2.0 * fCoeff ); @@ -165,7 +163,7 @@ void SAL_CALL LpsolveSolver::solve() maStatus = SolverComponent::GetResourceString( RID_ERROR_NONLINEAR ); } - SolverComponent::SetValue( mxDoc, *aVarIter, 0.0 ); // set back to zero for examining next variable + SolverComponent::SetValue( mxDoc, rVarCell, 0.0 ); // set back to zero for examining next variable } xModel->unlockControllers(); |