Kaydet (Commit) b6297280 authored tarafından Daniel Robertson's avatar Daniel Robertson Kaydeden (comit) Noel Grandin

Replace simple while loops with range-based for

Replace simple while loops with range-based for-loops when apropriate.
There should be no side effects due to this change.

Change-Id: I0c39d4c10c991354248e864a09333144974c953c
Reviewed-on: https://gerrit.libreoffice.org/19281Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
Tested-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst 143fb0a4
......@@ -490,12 +490,10 @@ void ShapeImporter::importPolygons(uno::Reference<beans::XPropertySet> const& xP
aPoint.setY((*pInnerSequence).Y);
aPoly.append( aPoint );
}
UnoViewVector::const_iterator aIter=(mrContext.mrViewContainer).begin();
UnoViewVector::const_iterator aEnd=(mrContext.mrViewContainer).end();
while(aIter != aEnd)
for( const auto& pView : mrContext.mrViewContainer )
{
::cppcanvas::PolyPolygonSharedPtr pPolyPoly(
::cppcanvas::BaseGfxFactory::createPolyPolygon( (*aIter)->getCanvas(),
::cppcanvas::BaseGfxFactory::createPolyPolygon( pView->getCanvas(),
aPoly ) );
if( pPolyPoly )
{
......@@ -504,7 +502,6 @@ void ShapeImporter::importPolygons(uno::Reference<beans::XPropertySet> const& xP
pPolyPoly->draw();
maPolygons.push_back(pPolyPoly);
}
++aIter;
}
}
......
......@@ -231,15 +231,11 @@ namespace slideshow
bool bRet(true);
VectorOfDocTreeNodes::const_iterator aIter( rSubsets.begin() );
const VectorOfDocTreeNodes::const_iterator aEnd ( rSubsets.end() );
while( aIter != aEnd )
for( const auto& rSubset : rSubsets )
{
if( !pRenderer->drawSubset( aIter->getStartIndex(),
aIter->getEndIndex() ) )
if( !pRenderer->drawSubset( rSubset.getStartIndex(),
rSubset.getEndIndex() ) )
bRet = false;
++aIter;
}
return bRet;
......
......@@ -53,11 +53,9 @@ namespace slideshow
{
LayerSharedPtr pCurrLayer;
ViewLayerSharedPtr pCurrViewLayer;
LayerShapeMap::const_iterator aIter( maAllShapes.begin() );
const LayerShapeMap::const_iterator aEnd ( maAllShapes.end() );
while( aIter != aEnd )
for( const auto& rShape : maAllShapes )
{
LayerSharedPtr pLayer = aIter->second.lock();
LayerSharedPtr pLayer = rShape.second.lock();
if( pLayer && pLayer != pCurrLayer )
{
pCurrLayer = pLayer;
......@@ -65,9 +63,7 @@ namespace slideshow
}
if( pCurrViewLayer )
shapeFunc(aIter->first,pCurrViewLayer);
++aIter;
shapeFunc(rShape.first,pCurrViewLayer);
}
}
......@@ -470,16 +466,14 @@ namespace slideshow
// send update() calls to every shape in the
// maUpdateShapes set, which is _animated_ (i.e. a
// sprite).
const ShapeUpdateSet::const_iterator aEnd=maUpdateShapes.end();
ShapeUpdateSet::const_iterator aCurrShape=maUpdateShapes.begin();
while( aCurrShape != aEnd )
for( const auto& pShape : maUpdateShapes )
{
if( (*aCurrShape)->isBackgroundDetached() )
if( pShape->isBackgroundDetached() )
{
// can update shape directly, without
// affecting layer content (shape is
// currently displayed in a sprite)
if( !(*aCurrShape)->update() )
if( !pShape->update() )
bRet = false; // delay error exit
}
else
......@@ -492,10 +486,8 @@ namespace slideshow
// cannot update shape directly, it's not
// animated and update() calls will prolly
// overwrite other page content.
addUpdateArea( *aCurrShape );
addUpdateArea( pShape );
}
++aCurrShape;
}
maUpdateShapes.clear();
......@@ -528,11 +520,9 @@ namespace slideshow
bool bIsCurrLayerUpdating(false);
Layer::EndUpdater aEndUpdater;
LayerSharedPtr pCurrLayer;
LayerShapeMap::const_iterator aIter( maAllShapes.begin() );
const LayerShapeMap::const_iterator aEnd ( maAllShapes.end() );
while( aIter != aEnd )
for( const auto& rShape : maAllShapes )
{
LayerSharedPtr pLayer = aIter->second.lock();
LayerSharedPtr pLayer = rShape.second.lock();
if( pLayer != pCurrLayer )
{
pCurrLayer = pLayer;
......@@ -543,14 +533,12 @@ namespace slideshow
}
if( bIsCurrLayerUpdating &&
!aIter->first->isBackgroundDetached() &&
pCurrLayer->isInsideUpdateArea(aIter->first) )
!rShape.first->isBackgroundDetached() &&
pCurrLayer->isInsideUpdateArea(rShape.first) )
{
if( !aIter->first->render() )
if( !rShape.first->render() )
bRet = false;
}
++aIter;
}
return bRet;
......@@ -639,9 +627,7 @@ namespace slideshow
bool bRet( true );
ViewLayerSharedPtr pTmpLayer( new DummyLayer( rTargetCanvas ) );
LayerShapeMap::const_iterator aIter( maAllShapes.begin() );
const LayerShapeMap::const_iterator aEnd ( maAllShapes.end() );
while( aIter != aEnd )
for( const auto& rShape : maAllShapes )
{
try
{
......@@ -650,11 +636,11 @@ namespace slideshow
// ViewLayer. Since we add the shapes in the
// maShapeSet order (which is also the render order),
// this is equivalent to a subsequent render() call)
aIter->first->addViewLayer( pTmpLayer,
rShape.first->addViewLayer( pTmpLayer,
true );
// and remove again, this is only temporary
aIter->first->removeViewLayer( pTmpLayer );
rShape.first->removeViewLayer( pTmpLayer );
}
catch( uno::Exception& )
{
......@@ -667,8 +653,6 @@ namespace slideshow
// at least one shape could not be rendered
bRet = false;
}
++aIter;
}
return bRet;
......
......@@ -332,27 +332,23 @@ namespace internal
uno::Sequence< animations::TargetProperties > aRes( aShapeHash.size() );
::std::size_t nCurrIndex(0);
XShapeHash::const_iterator aCurr( aShapeHash.begin() );
const XShapeHash::const_iterator aEnd ( aShapeHash.end() );
while( aCurr != aEnd )
for( const auto& rIter : aShapeHash )
{
animations::TargetProperties& rCurrProps( aRes[ nCurrIndex++ ] );
if( aCurr->first.mnParagraphIndex == -1 )
if( rIter.first.mnParagraphIndex == -1 )
{
rCurrProps.Target = uno::makeAny( aCurr->first.mxRef );
rCurrProps.Target = uno::makeAny( rIter.first.mxRef );
}
else
{
rCurrProps.Target = uno::makeAny(
presentation::ParagraphTarget(
aCurr->first.mxRef,
aCurr->first.mnParagraphIndex ) );
rIter.first.mxRef,
rIter.first.mnParagraphIndex ) );
}
rCurrProps.Properties = ::comphelper::containerToSequence( aCurr->second );
++aCurr;
rCurrProps.Properties = ::comphelper::containerToSequence( rIter.second );
}
return aRes;
......
......@@ -885,18 +885,14 @@ ActivitySharedPtr SlideShowImpl::createSlideTransition(
PolygonMap::iterator SlideShowImpl::findPolygons( uno::Reference<drawing::XDrawPage> const& xDrawPage)
{
// TODO(P2) : Optimze research in the map.
bool bFound = false;
PolygonMap::iterator aIter=maPolygons.begin();
while(aIter!=maPolygons.end() && !bFound)
{
if(aIter->first == xDrawPage)
bFound = true;
else
++aIter;
}
PolygonMap::iterator aEnd = maPolygons.end();
for( PolygonMap::iterator aIter = maPolygons.begin();
aIter != aEnd;
++aIter )
if( aIter->first == xDrawPage )
return aIter;
return aEnd;
}
SlideSharedPtr SlideShowImpl::makeSlide(
......@@ -1444,25 +1440,16 @@ void SlideShowImpl::registerUserPaintPolygons( const uno::Reference< lang::XMult
aPropLayer <<= false;
xLayerPropSet->setPropertyValue("IsLocked", aPropLayer);
PolygonMap::iterator aIter=maPolygons.begin();
PolyPolygonVector aPolygons;
::cppcanvas::PolyPolygonSharedPtr pPolyPoly;
::basegfx::B2DPolyPolygon b2DPolyPoly;
//Register polygons for each slide
while(aIter!=maPolygons.end())
for( const auto& rPoly : maPolygons )
{
aPolygons = aIter->second;
PolyPolygonVector aPolygons = rPoly.second;
//Get shapes for the slide
::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes > Shapes(aIter->first, ::com::sun::star::uno::UNO_QUERY);
::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes > Shapes(rPoly.first, ::com::sun::star::uno::UNO_QUERY);
//Retrieve polygons for one slide
for( PolyPolygonVector::iterator aIterPoly=aPolygons.begin(),
aEnd=aPolygons.end();
aIterPoly!=aEnd; ++aIterPoly )
for( const auto pPolyPoly : aPolygons )
{
pPolyPoly = (*aIterPoly);
b2DPolyPoly = ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(pPolyPoly->getUNOPolyPolygon());
::basegfx::B2DPolyPolygon b2DPolyPoly = ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(pPolyPoly->getUNOPolyPolygon());
//Normally there is only one polygon
for(sal_uInt32 i=0; i< b2DPolyPoly.count();i++)
......@@ -1531,7 +1518,6 @@ void SlideShowImpl::registerUserPaintPolygons( const uno::Reference< lang::XMult
}
}
}
++aIter;
}
}
......@@ -2113,13 +2099,11 @@ sal_Bool SlideShowImpl::update( double & nNextTimeout )
(!bRet ||
nNextTimeout > 1.0) )
{
UnoViewVector::const_iterator aCurr(maViewContainer.begin());
const UnoViewVector::const_iterator aEnd(maViewContainer.end());
while( aCurr != aEnd )
for( const auto& pView : maViewContainer )
{
try
{
uno::Reference< presentation::XSlideShowView > xView( (*aCurr)->getUnoView(),
uno::Reference< presentation::XSlideShowView > xView( pView->getUnoView(),
uno::UNO_QUERY_THROW );
uno::Reference< util::XUpdatable > xUpdatable( xView->getCanvas(),
uno::UNO_QUERY_THROW );
......@@ -2135,8 +2119,6 @@ sal_Bool SlideShowImpl::update( double & nNextTimeout )
comphelper::anyToString( cppu::getCaughtException() ),
RTL_TEXTENCODING_UTF8 ).getStr() );
}
++aCurr;
}
mbSlideShowIdle = true;
......
......@@ -283,23 +283,19 @@ class LayerSpriteContainer
SpriteVector aValidSprites;
// check all sprites for validity and set new priority
SpriteVector::iterator aCurrSprite( maSprites.begin() );
const SpriteVector::iterator aEnd( maSprites.end() );
while( aCurrSprite != aEnd )
for( const auto& rSprite : maSprites )
{
cppcanvas::CustomSpriteSharedPtr pCurrSprite( aCurrSprite->mpSprite.lock() );
cppcanvas::CustomSpriteSharedPtr pCurrSprite( rSprite.mpSprite.lock() );
if( pCurrSprite )
{
// only copy still valid sprites over to the refreshed
// sprite vector.
aValidSprites.push_back( *aCurrSprite );
aValidSprites.push_back( rSprite );
pCurrSprite->setPriority(
getSpritePriority( aValidSprites.size()-1 ));
}
++aCurrSprite;
}
// replace sprite list with pruned one
......@@ -1173,22 +1169,18 @@ void SlideView::pruneLayers( bool bWithViewLayerUpdate ) const
getTransformation() );
// check all layers for validity, and retain only the live ones
ViewLayerVector::const_iterator aCurr( maViewLayers.begin() );
const ViewLayerVector::const_iterator aEnd( maViewLayers.end() );
while( aCurr != aEnd )
for( const auto& rView : maViewLayers )
{
std::shared_ptr< SlideViewLayer > xCurrLayer( aCurr->lock() );
std::shared_ptr< SlideViewLayer > xCurrLayer( rView.lock() );
if (xCurrLayer)
if ( xCurrLayer )
{
aValidLayers.push_back(xCurrLayer);
aValidLayers.push_back( xCurrLayer );
if( bWithViewLayerUpdate )
xCurrLayer->updateView( rCurrTransform,
maUserSize );
}
++aCurr;
}
// replace layer list with pruned one
......
......@@ -453,16 +453,12 @@ void SlideChangeBase::viewsChanged()
if( mbFinished )
return;
ViewsVecT::iterator aIter( maViewData.begin() );
ViewsVecT::iterator const aEnd ( maViewData.end() );
while( aIter != aEnd )
for( auto& pView : maViewData )
{
// clear stale info (both bitmaps and sprites prolly need a
// resize)
clearViewEntry( *aIter );
addSprites( *aIter );
++aIter;
clearViewEntry( pView );
addSprites( pView );
}
}
......
......@@ -141,16 +141,13 @@ public:
mxFactory( xFactory )
{
// create one transition per view
UnoViewVector::const_iterator aCurrView (rViewContainer.begin());
const UnoViewVector::const_iterator aEnd(rViewContainer.end());
while( aCurrView != aEnd )
for( const auto& rView : rViewContainer )
{
if(! addTransition( *aCurrView ) )
if( !addTransition( rView ) )
return;
ENSURE_OR_THROW(maTransitions.back() && maTransitions.back()->mxTransition.is(),
"Failed to create plugin transition");
++aCurrView;
}
mbSuccess = true;
}
......@@ -159,13 +156,11 @@ public:
{
mxFactory.clear();
::std::vector< TransitionViewPair* >::const_iterator aCurrView (maTransitions.begin());
::std::vector< TransitionViewPair* >::const_iterator aEnd(maTransitions.end());
while( aCurrView != aEnd )
for( const auto& pCurrView : maTransitions )
{
delete (*aCurrView);
++aCurrView;
delete pCurrView;
}
maTransitions.clear();
}
......@@ -204,43 +199,33 @@ public:
OSL_TRACE("PluginSlideChange viewAdded");
SlideChangeBase::viewAdded( rView );
::std::vector< TransitionViewPair* >::const_iterator aCurrView (maTransitions.begin());
::std::vector< TransitionViewPair* >::const_iterator aEnd(maTransitions.end());
bool bKnown = false;
while( aCurrView != aEnd )
for( const auto& pCurrView : maTransitions )
{
if( (*aCurrView)->mpView == rView )
{
bKnown = true;
break;
}
++aCurrView;
if( pCurrView->mpView == rView )
return;
}
if( !bKnown )
{
OSL_TRACE("need to be added");
OSL_TRACE( "need to be added" );
addTransition( rView );
}
}
virtual void viewRemoved( const UnoViewSharedPtr& rView ) SAL_OVERRIDE
{
OSL_TRACE("PluginSlideChange viewRemoved");
SlideChangeBase::viewRemoved( rView );
::std::vector< TransitionViewPair* >::iterator aCurrView (maTransitions.begin());
::std::vector< TransitionViewPair* >::const_iterator aEnd(maTransitions.end());
while( aCurrView != aEnd )
for( ::std::vector< TransitionViewPair* >::iterator aIter =maTransitions.begin();
aIter != aEnd;
++aIter )
{
if( (*aCurrView)->mpView == rView )
if( ( *aIter )->mpView == rView )
{
OSL_TRACE( "view removed" );
delete (*aCurrView);
maTransitions.erase( aCurrView );
delete ( *aIter );
maTransitions.erase( aIter );
break;
}
++aCurrView;
}
}
......@@ -249,21 +234,17 @@ public:
OSL_TRACE("PluginSlideChange viewChanged");
SlideChangeBase::viewChanged( rView );
::std::vector< TransitionViewPair* >::const_iterator aCurrView (maTransitions.begin());
::std::vector< TransitionViewPair* >::const_iterator aEnd(maTransitions.end());
while( aCurrView != aEnd )
for( const auto& pCurrView : maTransitions )
{
if( (*aCurrView)->mpView == rView )
if( pCurrView->mpView == rView )
{
OSL_TRACE( "view changed" );
(*aCurrView)->mxTransition->viewChanged( rView->getUnoView(),
pCurrView->mxTransition->viewChanged( rView->getUnoView(),
getLeavingBitmap(ViewEntry(rView))->getXBitmap(),
getEnteringBitmap(ViewEntry(rView))->getXBitmap() );
}
else
OSL_TRACE( "view did not changed" );
++aCurrView;
}
}
......@@ -272,15 +253,13 @@ public:
OSL_TRACE("PluginSlideChange viewsChanged");
SlideChangeBase::viewsChanged();
::std::vector< TransitionViewPair* >::const_iterator aCurrView (maTransitions.begin());
::std::vector< TransitionViewPair* >::const_iterator aEnd(maTransitions.end());
while( aCurrView != aEnd )
for( const auto& pCurrView : maTransitions )
{
OSL_TRACE( "view changed" );
(*aCurrView)->mxTransition->viewChanged( (*aCurrView)->mpView->getUnoView(),
getLeavingBitmap(ViewEntry((*aCurrView)->mpView))->getXBitmap(),
getEnteringBitmap(ViewEntry((*aCurrView)->mpView))->getXBitmap() );
++aCurrView;
UnoViewSharedPtr pView = pCurrView->mpView;
pCurrView->mxTransition->viewChanged( pView->getUnoView(),
getLeavingBitmap(ViewEntry(pView))->getXBitmap(),
getEnteringBitmap(ViewEntry(pView))->getXBitmap() );
}
}
......
......@@ -77,19 +77,15 @@ void WaitSymbol::setVisible( const bool bVisible )
{
mbVisible = bVisible;
ViewsVecT::const_iterator aIter( maViews.begin() );
ViewsVecT::const_iterator const aEnd ( maViews.end() );
while( aIter != aEnd )
for( const auto& rView : maViews )
{
if( aIter->second )
if( rView.second )
{
if( bVisible )
aIter->second->show();
rView.second->show();
else
aIter->second->hide();
rView.second->hide();
}
++aIter;
}
// sprites changed, need a screen update for this frame.
......@@ -176,14 +172,11 @@ void WaitSymbol::viewChanged( const UnoViewSharedPtr& rView )
void WaitSymbol::viewsChanged()
{
// reposition sprites on all views
ViewsVecT::const_iterator aIter( maViews.begin() );
ViewsVecT::const_iterator const aEnd ( maViews.end() );
while( aIter != aEnd )
for( const auto& rView : maViews )
{
if( aIter->second )
aIter->second->movePixel(
calcSpritePos( aIter->first ));
++aIter;
if( rView.second )
rView.second->movePixel(
calcSpritePos( rView.first ) );
}
}
......
......@@ -102,19 +102,15 @@ template< typename ListenerT > struct ListenerOperations
FuncT func )
{
bool bRet(false);
typename ContainerT::const_iterator aCurr( rContainer.begin() );
typename ContainerT::const_iterator const aEnd ( rContainer.end() );
while( aCurr != aEnd )
for( const auto& rCurr : rContainer )
{
if( FunctionApply< typename FuncT::result_type,
typename ContainerT::value_type >::apply(
func,
*aCurr) )
rCurr) )
{
bRet = true;
}
++aCurr;
}
// true: at least one handler returned true
......@@ -137,16 +133,12 @@ struct ListenerOperations< boost::weak_ptr<ListenerTargetT> >
static bool notifySingleListener( ContainerT& rContainer,
FuncT func )
{
typename ContainerT::const_iterator aCurr( rContainer.begin() );
typename ContainerT::const_iterator const aEnd ( rContainer.end() );
while( aCurr != aEnd )
for( const auto& rCurr : rContainer )
{
boost::shared_ptr<ListenerTargetT> pListener( aCurr->lock() );
boost::shared_ptr<ListenerTargetT> pListener( rCurr.lock() );
if( pListener && func(pListener) )
return true;
++aCurr;
}
return false;
......@@ -158,11 +150,9 @@ struct ListenerOperations< boost::weak_ptr<ListenerTargetT> >
FuncT func )
{
bool bRet(false);
typename ContainerT::const_iterator aCurr( rContainer.begin() );
typename ContainerT::const_iterator const aEnd ( rContainer.end() );
while( aCurr != aEnd )
for( const auto& rCurr : rContainer )
{
boost::shared_ptr<ListenerTargetT> pListener( aCurr->lock() );
boost::shared_ptr<ListenerTargetT> pListener( rCurr.lock() );
if( pListener.get() &&
FunctionApply< typename FuncT::result_type,
......@@ -170,8 +160,6 @@ struct ListenerOperations< boost::weak_ptr<ListenerTargetT> >
{
bRet = true;
}
++aCurr;
}
return bRet;
......@@ -186,14 +174,10 @@ struct ListenerOperations< boost::weak_ptr<ListenerTargetT> >
ContainerT aAliveListeners;
aAliveListeners.reserve(rContainer.size());
typename ContainerT::const_iterator aCurr( rContainer.begin() );
typename ContainerT::const_iterator const aEnd ( rContainer.end() );
while( aCurr != aEnd )
for( const auto& rCurr : rContainer )
{
if( !aCurr->expired() )
aAliveListeners.push_back( *aCurr );
++aCurr;
if( !rCurr.expired() )
aAliveListeners.push_back( rCurr );
}
std::swap( rContainer, aAliveListeners );
......
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