diff options
author | Daniel Robertson <danlrobertson89@gmail.com> | 2015-08-15 15:19:18 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2015-08-15 18:51:31 +0000 |
commit | 849f1d37d575bc752c8f987c7541dbd4bfd998c1 (patch) | |
tree | ee0d97e3bb02208aade7c77aee7f142cf0f2307c /canvas | |
parent | Resolves: tdf#93358 resync attribute pattern that may have changed (diff) | |
download | core-849f1d37d575bc752c8f987c7541dbd4bfd998c1.tar.gz core-849f1d37d575bc752c8f987c7541dbd4bfd998c1.zip |
canvas: replace for_each with range-based for-loop
Replace ::std::for_each for a more readable range-based for loop in
cases in which the function object to be applied by for_each is more
readable as the body of a for loop.
Change-Id: I6f96833d7f251d44e2308278bb92a7d49fd49bcd
Reviewed-on: https://gerrit.libreoffice.org/17763
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'canvas')
-rw-r--r-- | canvas/source/cairo/cairo_spritecanvashelper.cxx | 103 | ||||
-rw-r--r-- | canvas/source/tools/page.cxx | 7 | ||||
-rw-r--r-- | canvas/source/tools/pagemanager.cxx | 7 | ||||
-rw-r--r-- | canvas/source/tools/spriteredrawmanager.cxx | 17 | ||||
-rw-r--r-- | canvas/source/tools/surfaceproxy.cxx | 35 |
5 files changed, 45 insertions, 124 deletions
diff --git a/canvas/source/cairo/cairo_spritecanvashelper.cxx b/canvas/source/cairo/cairo_spritecanvashelper.cxx index a297810b591c..a1b16436739c 100644 --- a/canvas/source/cairo/cairo_spritecanvashelper.cxx +++ b/canvas/source/cairo/cairo_spritecanvashelper.cxx @@ -19,7 +19,6 @@ #include <sal/config.h> -#include <boost/bind.hpp> #include <boost/cast.hpp> #include <basegfx/range/b2drectangle.hxx> @@ -87,47 +86,6 @@ namespace cairocanvas cairo_restore( pCairo.get() ); } - - /** Repaint sprite at original position - - Used for opaque updates, which render directly to the - device buffer. - */ - void spriteRedrawStub( const CairoSharedPtr& pCairo, - const ::canvas::Sprite::Reference& rSprite ) - { - if( rSprite.is() ) - { - ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw( pCairo, false ); - } - } - - /** Repaint sprite at given position - - Used for generic update, which renders into device buffer. - */ - void spriteRedrawStub2( const CairoSharedPtr& pCairo, - const ::canvas::Sprite::Reference& rSprite ) - { - if( rSprite.is() ) - { - ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw( pCairo, true ); - } - } - - /** Repaint sprite at original position - - Used for opaque updates from scrollUpdate(), which render - directly to the front buffer. - */ - void spriteRedrawStub3( const CairoSharedPtr& pCairo, - const ::canvas::SpriteRedrawManager::AreaComponent& rComponent ) - { - const ::canvas::Sprite::Reference& rSprite( rComponent.second.getSprite() ); - - if( rSprite.is() ) - ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw( pCairo, false ); - } } SpriteCanvasHelper::SpriteCanvasHelper() : @@ -242,10 +200,9 @@ namespace cairocanvas // repaint all active sprites on top of background into // VDev. mpRedrawManager->forEachSprite( - ::boost::bind( - &spriteRedraw, - boost::cref(pCompositingCairo), - _1 ) ); + [&pCompositingCairo]( const Sprite::Reference rSprite ) + { spriteRedraw( pCompositingCairo, rSprite ); } + ); // flush to screen cairo_rectangle( pWindowCairo.get(), 0, 0, rSize.getX(), rSize.getY() ); @@ -328,12 +285,13 @@ namespace cairocanvas // opaque sprite content) // repaint all affected sprites directly to output device - ::std::for_each( rUpdateArea.maComponentList.begin(), - rUpdateArea.maComponentList.end(), - ::boost::bind( - &spriteRedrawStub3, - boost::cref(pCompositingCairo), - _1 ) ); + for( const auto& rComponent : rUpdateArea.maComponentList ) + { + const ::canvas::Sprite::Reference& rSprite( rComponent.second.getSprite() ); + if( rSprite.is() ) + ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw( + pCompositingCairo, true ); + } } else { @@ -386,12 +344,9 @@ namespace cairocanvas // repaint uncovered areas from sprite. Need to actually // clip here, since we're only repainting _parts_ of the // sprite - ::std::for_each( aUnscrollableAreas.begin(), - aUnscrollableAreas.end(), - ::boost::bind( &opaqueUpdateSpriteArea, - ::boost::cref(aFirst->second.getSprite()), - boost::cref(pCompositingCairo), - _1 ) ); + for( const auto& rArea : aUnscrollableAreas ) + opaqueUpdateSpriteArea( aFirst->second.getSprite(), + pCompositingCairo, rArea ); } // repaint uncovered areas from backbuffer - take the @@ -401,12 +356,9 @@ namespace cairocanvas ::basegfx::computeSetDifference( aUncoveredAreas, rUpdateArea.maTotalBounds, ::basegfx::B2DRange( rDestRect ) ); - ::std::for_each( aUncoveredAreas.begin(), - aUncoveredAreas.end(), - ::boost::bind( &repaintBackground, - boost::cref(pCompositingCairo), - mpOwningSpriteCanvas->getBufferSurface(), - _1 ) ); + for( const auto& rArea : aUncoveredAreas ) + repaintBackground( pCompositingCairo, + mpOwningSpriteCanvas->getBufferSurface(), rArea ); cairo_rectangle( pWindowCairo.get(), 0, 0, rSize.getX(), rSize.getY() ); cairo_clip( pWindowCairo.get() ); @@ -443,12 +395,12 @@ namespace cairocanvas cairo_clip( pCompositingCairo.get() ); // repaint all affected sprites directly to output device - ::std::for_each( rSortedUpdateSprites.begin(), - rSortedUpdateSprites.end(), - ::boost::bind( - &spriteRedrawStub, - boost::cref(pCompositingCairo), - _1 ) ); + for( const auto& rSprite : rSortedUpdateSprites ) + { + if( rSprite.is() ) + ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw( + pCompositingCairo, false ); + } // flush to screen cairo_rectangle( pWindowCairo.get(), 0, 0, rDeviceSize.getX(), rDeviceSize.getY() ); @@ -512,11 +464,12 @@ namespace cairocanvas // repaint all affected sprites on top of background into // VDev. - ::std::for_each( rSortedUpdateSprites.begin(), - rSortedUpdateSprites.end(), - ::boost::bind( &spriteRedrawStub2, - boost::cref(pCompositingCairo), - _1 ) ); + for( const auto& rSprite : rSortedUpdateSprites ) + { + if( rSprite.is() ) + ::boost::polymorphic_downcast< Sprite* >( rSprite.get() )->redraw( + pCompositingCairo, true ); + } // flush to screen cairo_rectangle( pWindowCairo.get(), aOutputPosition.X(), aOutputPosition.Y(), aOutputSize.Width(), aOutputSize.Height() ); diff --git a/canvas/source/tools/page.cxx b/canvas/source/tools/page.cxx index d80a67b0b79e..b942b3b9fa15 100644 --- a/canvas/source/tools/page.cxx +++ b/canvas/source/tools/page.cxx @@ -19,8 +19,6 @@ #include <sal/config.h> -#include <boost/mem_fn.hpp> - #include "page.hxx" namespace canvas @@ -35,9 +33,8 @@ namespace canvas { if(!(isValid())) { - ::std::for_each( mpFragments.begin(), - mpFragments.end(), - ::boost::mem_fn(&PageFragment::refresh)); + for( const auto& rFragmentPtr : mpFragments ) + rFragmentPtr->refresh(); } } diff --git a/canvas/source/tools/pagemanager.cxx b/canvas/source/tools/pagemanager.cxx index 726f41ec01f1..aa1eaa0dc7f4 100644 --- a/canvas/source/tools/pagemanager.cxx +++ b/canvas/source/tools/pagemanager.cxx @@ -19,8 +19,6 @@ #include <sal/config.h> -#include <boost/mem_fn.hpp> - #include "pagemanager.hxx" namespace canvas @@ -189,9 +187,8 @@ namespace canvas void PageManager::validatePages() { - ::std::for_each( maPages.begin(), - maPages.end(), - ::boost::mem_fn(&Page::validate)); + for( const auto& rPagePtr : maPages ) + rPagePtr->validate(); } diff --git a/canvas/source/tools/spriteredrawmanager.cxx b/canvas/source/tools/spriteredrawmanager.cxx index 94d3d40fd45f..8e2bebf49cfc 100644 --- a/canvas/source/tools/spriteredrawmanager.cxx +++ b/canvas/source/tools/spriteredrawmanager.cxx @@ -27,6 +27,7 @@ #include <tools/diagnose_ex.h> #include <canvas/spriteredrawmanager.hxx> +#include <boost/range/adaptor/reversed.hpp> namespace canvas { @@ -406,10 +407,8 @@ namespace canvas // now, calc the _true_ update area, by merging all sprite's // true update areas into one rectangle ::basegfx::B2DRange aTrueArea( rUpdateArea.maComponentList.begin()->second.getUpdateArea() ); - ::std::for_each( rUpdateArea.maComponentList.begin(), - rUpdateArea.maComponentList.end(), - [&aTrueArea]( const ::std::pair< ::basegfx::B2DRange, SpriteInfo >& cp ) - { aTrueArea.expand(cp.second.getUpdateArea()); } ); + for( const auto& rArea : rUpdateArea.maComponentList ) + aTrueArea.expand(rArea.second.getUpdateArea()); const SpriteConnectedRanges::ComponentListType::const_iterator aEnd( rUpdateArea.maComponentList.end() ); @@ -452,14 +451,8 @@ namespace canvas // this object, is the owner of the sprites. After all, a // sprite without a canvas to render into makes not terribly // much sense. - - // TODO(Q3): Once boost 1.33 is in, change back to for_each - // with ::boost::mem_fn. For the time being, explicit loop due - // to cdecl declaration of all UNO methods. - ListOfSprites::reverse_iterator aCurr( maSprites.rbegin() ); - ListOfSprites::reverse_iterator aEnd( maSprites.rend() ); - while( aCurr != aEnd ) - (*aCurr++)->dispose(); + for( const auto& rCurr : boost::adaptors::reverse(maSprites) ) + rCurr->dispose(); maSprites.clear(); } diff --git a/canvas/source/tools/surfaceproxy.cxx b/canvas/source/tools/surfaceproxy.cxx index 1dfdd9c83d6f..e35ad4d490dc 100644 --- a/canvas/source/tools/surfaceproxy.cxx +++ b/canvas/source/tools/surfaceproxy.cxx @@ -22,7 +22,6 @@ #include <basegfx/polygon/b2dpolygoncutandtouch.hxx> #include <basegfx/polygon/b2dpolygontriangulator.hxx> #include <basegfx/polygon/b2dpolypolygontools.hxx> -#include <boost/bind.hpp> #include "surfaceproxy.hxx" @@ -90,9 +89,8 @@ namespace canvas void SurfaceProxy::setColorBufferDirty() { - ::std::for_each( maSurfaceList.begin(), - maSurfaceList.end(), - ::boost::mem_fn(&Surface::setColorBufferDirty)); + for( const auto& rSurfacePtr : maSurfaceList ) + rSurfacePtr->setColorBufferDirty(); } @@ -103,13 +101,8 @@ namespace canvas const ::basegfx::B2DPoint& rPos, const ::basegfx::B2DHomMatrix& rTransform ) { - ::std::for_each( maSurfaceList.begin(), - maSurfaceList.end(), - ::boost::bind( &Surface::draw, - _1, - fAlpha, - ::boost::cref(rPos), - ::boost::cref(rTransform))); + for( const auto& rSurfacePtr : maSurfaceList ) + rSurfacePtr->draw( fAlpha, rPos, rTransform ); return true; } @@ -123,14 +116,8 @@ namespace canvas const ::basegfx::B2DRange& rArea, const ::basegfx::B2DHomMatrix& rTransform ) { - ::std::for_each( maSurfaceList.begin(), - maSurfaceList.end(), - ::boost::bind(&Surface::drawRectangularArea, - _1, - fAlpha, - ::boost::cref(rPos), - ::boost::cref(rArea), - ::boost::cref(rTransform))); + for( const auto& rSurfacePtr : maSurfaceList ) + rSurfacePtr->drawRectangularArea( fAlpha, rPos, rArea, rTransform ); return true; } @@ -160,14 +147,8 @@ namespace canvas RTL_TEXTENCODING_ASCII_US).getStr() ); #endif - ::std::for_each( maSurfaceList.begin(), - maSurfaceList.end(), - ::boost::bind(&Surface::drawWithClip, - _1, - fAlpha, - ::boost::cref(rPos), - ::boost::cref(rTriangulatedPolygon), - ::boost::cref(rTransform))); + for( const auto& rSurfacePtr : maSurfaceList ) + rSurfacePtr->drawWithClip( fAlpha, rPos, rTriangulatedPolygon, rTransform ); return true; } |