Kaydet (Commit) a811d6ef authored tarafından Daniel Robertson's avatar Daniel Robertson Kaydeden (comit) Thorsten Behrens

slideshow: replace for_each with range-based for

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. In addition, replace while loops
with range-based for loops when possible and complex implementations
of boost::bind with lambda expressions.

Change-Id: I6adfb18197bd1b8627719adfca2e4c36d58a0e05
Reviewed-on: https://gerrit.libreoffice.org/17786Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
Tested-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst b190574b
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "activity.hxx" #include "activity.hxx"
#include "activitiesqueue.hxx" #include "activitiesqueue.hxx"
#include <boost/mem_fn.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <algorithm> #include <algorithm>
...@@ -51,12 +50,10 @@ namespace slideshow ...@@ -51,12 +50,10 @@ namespace slideshow
// dispose all queue entries // dispose all queue entries
try try
{ {
std::for_each( maCurrentActivitiesWaiting.begin(), for( const auto& pActivity : maCurrentActivitiesWaiting )
maCurrentActivitiesWaiting.end(), pActivity->dispose();
boost::mem_fn( &Disposable::dispose ) ); for( const auto& pActivity : maCurrentActivitiesReinsert )
std::for_each( maCurrentActivitiesReinsert.begin(), pActivity->dispose();
maCurrentActivitiesReinsert.end(),
boost::mem_fn( &Disposable::dispose ) );
} }
catch (uno::Exception &) catch (uno::Exception &)
{ {
...@@ -169,9 +166,8 @@ namespace slideshow ...@@ -169,9 +166,8 @@ namespace slideshow
void ActivitiesQueue::processDequeued() void ActivitiesQueue::processDequeued()
{ {
// notify all dequeued activities from last round // notify all dequeued activities from last round
::std::for_each( maDequeuedActivities.begin(), for( const auto& pActivity : maDequeuedActivities )
maDequeuedActivities.end(), pActivity->dequeued();
::boost::mem_fn( &Activity::dequeued ) );
maDequeuedActivities.clear(); maDequeuedActivities.clear();
} }
...@@ -183,14 +179,12 @@ namespace slideshow ...@@ -183,14 +179,12 @@ namespace slideshow
void ActivitiesQueue::clear() void ActivitiesQueue::clear()
{ {
// dequeue all entries: // dequeue all entries:
std::for_each( maCurrentActivitiesWaiting.begin(), for( const auto& pActivity : maCurrentActivitiesWaiting )
maCurrentActivitiesWaiting.end(), pActivity->dequeued();
boost::mem_fn( &Activity::dequeued ) );
ActivityQueue().swap( maCurrentActivitiesWaiting ); ActivityQueue().swap( maCurrentActivitiesWaiting );
std::for_each( maCurrentActivitiesReinsert.begin(), for( const auto& pActivity : maCurrentActivitiesReinsert )
maCurrentActivitiesReinsert.end(), pActivity->dequeued();
boost::mem_fn( &Activity::dequeued ) );
ActivityQueue().swap( maCurrentActivitiesReinsert ); ActivityQueue().swap( maCurrentActivitiesReinsert );
} }
} }
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include "nodetools.hxx" #include "nodetools.hxx"
#include "generateevent.hxx" #include "generateevent.hxx"
#include <boost/bind.hpp>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
...@@ -624,10 +623,8 @@ void BaseNode::notifyDeactivating( const AnimationNodeSharedPtr& rNotifier ) ...@@ -624,10 +623,8 @@ void BaseNode::notifyDeactivating( const AnimationNodeSharedPtr& rNotifier )
void BaseNode::notifyEndListeners() const void BaseNode::notifyEndListeners() const
{ {
// notify all listeners // notify all listeners
std::for_each( maDeactivatingListeners.begin(), for( const auto& rListner : maDeactivatingListeners )
maDeactivatingListeners.end(), rListner->notifyDeactivating( mpSelf );
boost::bind( &AnimationNode::notifyDeactivating, _1,
boost::cref(mpSelf) ) );
// notify state change // notify state change
maContext.mrEventMultiplexer.notifyAnimationEnd( mpSelf ); maContext.mrEventMultiplexer.notifyAnimationEnd( mpSelf );
......
...@@ -64,10 +64,8 @@ PointerSymbol::PointerSymbol( uno::Reference<rendering::XBitmap> const & xBitm ...@@ -64,10 +64,8 @@ PointerSymbol::PointerSymbol( uno::Reference<rendering::XBitmap> const & xBitm
maPos(), maPos(),
mbVisible(false) mbVisible(false)
{ {
std::for_each( rViewContainer.begin(), for( const auto& rView : rViewContainer )
rViewContainer.end(), viewAdded( rView );
[this]( const UnoViewSharedPtr& sp )
{ this->viewAdded(sp); } );
} }
void PointerSymbol::setVisible( const bool bVisible ) void PointerSymbol::setVisible( const bool bVisible )
...@@ -76,19 +74,15 @@ void PointerSymbol::setVisible( const bool bVisible ) ...@@ -76,19 +74,15 @@ void PointerSymbol::setVisible( const bool bVisible )
{ {
mbVisible = bVisible; mbVisible = bVisible;
ViewsVecT::const_iterator aIter( maViews.begin() ); for( const auto& rView : maViews )
ViewsVecT::const_iterator const aEnd ( maViews.end() );
while( aIter != aEnd )
{ {
if( aIter->second ) if( rView.second )
{ {
if( bVisible ) if( bVisible )
aIter->second->show(); rView.second->show();
else else
aIter->second->hide(); rView.second->hide();
} }
++aIter;
} }
// sprites changed, need a screen update for this frame. // sprites changed, need a screen update for this frame.
...@@ -173,14 +167,11 @@ void PointerSymbol::viewChanged( const UnoViewSharedPtr& rView ) ...@@ -173,14 +167,11 @@ void PointerSymbol::viewChanged( const UnoViewSharedPtr& rView )
void PointerSymbol::viewsChanged() void PointerSymbol::viewsChanged()
{ {
// reposition sprites on all views // reposition sprites on all views
ViewsVecT::const_iterator aIter( maViews.begin() ); for( const auto& rView : maViews )
ViewsVecT::const_iterator const aEnd ( maViews.end() );
while( aIter != aEnd )
{ {
if( aIter->second ) if( rView.second )
aIter->second->movePixel( rView.second->movePixel(
calcSpritePos( aIter->first )); calcSpritePos( rView.first ) );
++aIter;
} }
} }
...@@ -191,18 +182,15 @@ void PointerSymbol::viewsChanged(const geometry::RealPoint2D pos) ...@@ -191,18 +182,15 @@ void PointerSymbol::viewsChanged(const geometry::RealPoint2D pos)
maPos = pos; maPos = pos;
// reposition sprites on all views // reposition sprites on all views
ViewsVecT::const_iterator aIter( maViews.begin() ); for( const auto& rView : maViews )
ViewsVecT::const_iterator const aEnd ( maViews.end() );
while( aIter != aEnd )
{ {
if( aIter->second ) if( rView.second )
{ {
aIter->second->movePixel( rView.second->movePixel(
calcSpritePos( aIter->first )); calcSpritePos( rView.first ) );
mrScreenUpdater.notifyUpdate(); mrScreenUpdater.notifyUpdate();
mrScreenUpdater.commitUpdates(); mrScreenUpdater.commitUpdates();
} }
++aIter;
} }
} }
} }
......
...@@ -167,11 +167,8 @@ RehearseTimingsActivity::RehearseTimingsActivity( const SlideShowContext& rConte ...@@ -167,11 +167,8 @@ RehearseTimingsActivity::RehearseTimingsActivity( const SlideShowContext& rConte
maSpriteSizePixel.setY( metric.GetLineHeight() * 11 / 10 ); maSpriteSizePixel.setY( metric.GetLineHeight() * 11 / 10 );
mnYOffset = (metric.GetAscent() + (metric.GetLineHeight() / 20)); mnYOffset = (metric.GetAscent() + (metric.GetLineHeight() / 20));
std::for_each( rContext.mrViewContainer.begin(), for( const auto& rView : rContext.mrViewContainer )
rContext.mrViewContainer.end(), viewAdded( rView );
boost::bind( &RehearseTimingsActivity::viewAdded,
this,
_1 ));
} }
RehearseTimingsActivity::~RehearseTimingsActivity() RehearseTimingsActivity::~RehearseTimingsActivity()
......
...@@ -137,20 +137,18 @@ namespace internal ...@@ -137,20 +137,18 @@ namespace internal
mpImpl->mbUpdateAllRequest ) mpImpl->mbUpdateAllRequest )
{ {
// unconditionally update all views // unconditionally update all views
std::for_each( mpImpl->mrViewContainer.begin(), for( const auto& pView : mpImpl->mrViewContainer )
mpImpl->mrViewContainer.end(), {
mpImpl->mbViewClobbered ? if( mpImpl->mbViewClobbered )
boost::mem_fn(&View::paintScreen) : pView->paintScreen();
boost::mem_fn(&View::updateScreen) ); else
pView->updateScreen();
}
} }
else if( !mpImpl->maViewUpdateRequests.empty() ) else if( !mpImpl->maViewUpdateRequests.empty() )
{ {
// update notified views only // update notified views only
UpdateRequestVector::const_iterator aIter( for( const auto& rViewUpdateRequest : mpImpl->maViewUpdateRequests )
mpImpl->maViewUpdateRequests.begin() );
const UpdateRequestVector::const_iterator aEnd(
mpImpl->maViewUpdateRequests.end() );
while( aIter != aEnd )
{ {
// TODO(P1): this is O(n^2) in the number of views, if // TODO(P1): this is O(n^2) in the number of views, if
// lots of views notify updates. // lots of views notify updates.
...@@ -159,15 +157,13 @@ namespace internal ...@@ -159,15 +157,13 @@ namespace internal
UnoViewVector::const_iterator aFoundView; UnoViewVector::const_iterator aFoundView;
if( (aFoundView=std::find(mpImpl->mrViewContainer.begin(), if( (aFoundView=std::find(mpImpl->mrViewContainer.begin(),
aEndOfViews, aEndOfViews,
aIter->first)) != aEndOfViews ) rViewUpdateRequest.first)) != aEndOfViews )
{ {
if( aIter->second ) if( rViewUpdateRequest.second )
(*aFoundView)->paintScreen(); // force-paint (*aFoundView)->paintScreen(); // force-paint
else else
(*aFoundView)->updateScreen(); // update changes only (*aFoundView)->updateScreen(); // update changes only
} }
++aIter;
} }
} }
...@@ -195,9 +191,8 @@ namespace internal ...@@ -195,9 +191,8 @@ namespace internal
// TODO(F2): This will interfere with other updates, since it // TODO(F2): This will interfere with other updates, since it
// happens out-of-sync with main animation loop. Might cause // happens out-of-sync with main animation loop. Might cause
// artifacts. // artifacts.
std::for_each( mpImpl->mrViewContainer.begin(), for( auto const& pView : mpImpl->mrViewContainer )
mpImpl->mrViewContainer.end(), pView->updateScreen();
boost::mem_fn(&View::updateScreen) );
} }
void ScreenUpdater::lockUpdates() void ScreenUpdater::lockUpdates()
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "viewappletshape.hxx" #include "viewappletshape.hxx"
#include "tools.hxx" #include "tools.hxx"
#include <boost/bind.hpp>
#include <algorithm> #include <algorithm>
...@@ -128,15 +127,12 @@ namespace slideshow ...@@ -128,15 +127,12 @@ namespace slideshow
void AppletShape::implViewChanged( const UnoViewSharedPtr& rView ) void AppletShape::implViewChanged( const UnoViewSharedPtr& rView )
{ {
const ::basegfx::B2DRectangle& rBounds = getBounds();
// determine ViewAppletShape that needs update // determine ViewAppletShape that needs update
ViewAppletShapeVector::const_iterator aIter(maViewAppletShapes.begin()); for( const auto& pViewAppletShape : maViewAppletShapes )
ViewAppletShapeVector::const_iterator const aEnd (maViewAppletShapes.end());
while( aIter != aEnd )
{ {
if( (*aIter)->getViewLayer()->isOnView(rView) ) if( pViewAppletShape->getViewLayer()->isOnView( rView ) )
(*aIter)->resize(getBounds()); pViewAppletShape->resize( rBounds );
++aIter;
} }
} }
...@@ -145,12 +141,9 @@ namespace slideshow ...@@ -145,12 +141,9 @@ namespace slideshow
void AppletShape::implViewsChanged() void AppletShape::implViewsChanged()
{ {
// resize all ViewShapes // resize all ViewShapes
::std::for_each( maViewAppletShapes.begin(), const ::basegfx::B2DRectangle& rBounds = getBounds();
maViewAppletShapes.end(), for( const auto& pViewAppletShape : maViewAppletShapes )
::boost::bind( pViewAppletShape->resize( rBounds );
&ViewAppletShape::resize,
_1,
AppletShape::getBounds()) );
} }
...@@ -190,21 +183,18 @@ namespace slideshow ...@@ -190,21 +183,18 @@ namespace slideshow
OSL_ENSURE( ::std::count_if(maViewAppletShapes.begin(), OSL_ENSURE( ::std::count_if(maViewAppletShapes.begin(),
aEnd, aEnd,
::boost::bind<bool>( [&rLayer]
::std::equal_to< ViewLayerSharedPtr >(), ( const ViewAppletShapeSharedPtr& pShape )
::boost::bind( &ViewAppletShape::getViewLayer, _1 ), { return rLayer == pShape->getViewLayer(); } ) < 2,
::boost::cref( rLayer ) ) ) < 2,
"AppletShape::removeViewLayer(): Duplicate ViewLayer entries!" ); "AppletShape::removeViewLayer(): Duplicate ViewLayer entries!" );
ViewAppletShapeVector::iterator aIter; ViewAppletShapeVector::iterator aIter;
if( (aIter=::std::remove_if( maViewAppletShapes.begin(), if( (aIter=::std::remove_if( maViewAppletShapes.begin(),
aEnd, aEnd,
::boost::bind<bool>( [&rLayer]
::std::equal_to< ViewLayerSharedPtr >(), ( const ViewAppletShapeSharedPtr& pShape )
::boost::bind( &ViewAppletShape::getViewLayer, { return rLayer == pShape->getViewLayer(); } ) ) == aEnd )
_1 ),
::boost::cref( rLayer ) ) )) == aEnd )
{ {
// view layer seemingly was not added, failed // view layer seemingly was not added, failed
return false; return false;
...@@ -231,10 +221,9 @@ namespace slideshow ...@@ -231,10 +221,9 @@ namespace slideshow
// redraw all view shapes, by calling their update() method // redraw all view shapes, by calling their update() method
if( ::std::count_if( maViewAppletShapes.begin(), if( ::std::count_if( maViewAppletShapes.begin(),
maViewAppletShapes.end(), maViewAppletShapes.end(),
::boost::bind<bool>( [&rCurrBounds]
::boost::mem_fn( &ViewAppletShape::render ), ( const ViewAppletShapeSharedPtr& pShape )
_1, { return pShape->render( rCurrBounds ); } )
::boost::cref( rCurrBounds ) ) )
!= static_cast<ViewAppletShapeVector::difference_type>(maViewAppletShapes.size()) ) != static_cast<ViewAppletShapeVector::difference_type>(maViewAppletShapes.size()) )
{ {
// at least one of the ViewShape::update() calls did return // at least one of the ViewShape::update() calls did return
...@@ -249,11 +238,10 @@ namespace slideshow ...@@ -249,11 +238,10 @@ namespace slideshow
bool AppletShape::implStartIntrinsicAnimation() bool AppletShape::implStartIntrinsicAnimation()
{ {
::std::for_each( maViewAppletShapes.begin(), const ::basegfx::B2DRectangle& rBounds = getBounds();
maViewAppletShapes.end(), for( const auto& pViewAppletShape : maViewAppletShapes )
::boost::bind( &ViewAppletShape::startApplet, pViewAppletShape->startApplet( rBounds );
_1,
getBounds()) );
mbIsPlaying = true; mbIsPlaying = true;
return true; return true;
...@@ -263,9 +251,8 @@ namespace slideshow ...@@ -263,9 +251,8 @@ namespace slideshow
bool AppletShape::implEndIntrinsicAnimation() bool AppletShape::implEndIntrinsicAnimation()
{ {
::std::for_each( maViewAppletShapes.begin(), for( const auto& pViewAppletShape : maViewAppletShapes )
maViewAppletShapes.end(), pViewAppletShape->endApplet();
::boost::mem_fn( &ViewAppletShape::endApplet ) );
mbIsPlaying = false; mbIsPlaying = false;
......
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
#include "drawshapesubsetting.hxx" #include "drawshapesubsetting.hxx"
#include "drawshape.hxx" #include "drawshape.hxx"
#include <boost/bind.hpp>
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <limits> #include <limits>
...@@ -400,11 +398,8 @@ namespace slideshow ...@@ -400,11 +398,8 @@ namespace slideshow
// the whole shape set // the whole shape set
// determine new subset range // determine new subset range
::std::for_each( maSubsetShapes.begin(), for( const auto& pShape : maSubsetShapes )
maSubsetShapes.end(), updateSubsetBounds( pShape );
::boost::bind(&DrawShapeSubsetting::updateSubsetBounds,
this,
_1 ) );
updateSubsets(); updateSubsets();
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "shape.hxx" #include "shape.hxx"
#include "tools.hxx" #include "tools.hxx"
#include <boost/bind.hpp>
#include <algorithm> #include <algorithm>
...@@ -105,29 +104,21 @@ namespace slideshow ...@@ -105,29 +104,21 @@ namespace slideshow
void MediaShape::implViewChanged( const UnoViewSharedPtr& rView ) void MediaShape::implViewChanged( const UnoViewSharedPtr& rView )
{ {
const ::basegfx::B2DRectangle& rBounds = getBounds();
// determine ViewMediaShape that needs update // determine ViewMediaShape that needs update
ViewMediaShapeVector::const_iterator aIter(maViewMediaShapes.begin()); for( const auto& pViewMediaShape : maViewMediaShapes )
ViewMediaShapeVector::const_iterator const aEnd (maViewMediaShapes.end()); if( pViewMediaShape->getViewLayer()->isOnView( rView ) )
while( aIter != aEnd ) pViewMediaShape->resize( rBounds );
{
if( (*aIter)->getViewLayer()->isOnView(rView) )
(*aIter)->resize(getBounds());
++aIter;
}
} }
void MediaShape::implViewsChanged() void MediaShape::implViewsChanged()
{ {
const ::basegfx::B2DRectangle& rBounds = getBounds();
// resize all ViewShapes // resize all ViewShapes
::std::for_each( maViewMediaShapes.begin(), for( const auto& pViewMediaShape : maViewMediaShapes )
maViewMediaShapes.end(), pViewMediaShape->resize( rBounds );
::boost::bind(
&ViewMediaShape::resize,
_1,
getBounds()) );
} }
...@@ -156,21 +147,18 @@ namespace slideshow ...@@ -156,21 +147,18 @@ namespace slideshow
OSL_ENSURE( ::std::count_if(maViewMediaShapes.begin(), OSL_ENSURE( ::std::count_if(maViewMediaShapes.begin(),
aEnd, aEnd,
::boost::bind<bool>( [&rLayer]
::std::equal_to< ViewLayerSharedPtr >(), ( const ViewMediaShapeSharedPtr& pShape )
::boost::bind( &ViewMediaShape::getViewLayer, _1 ), { return rLayer == pShape->getViewLayer(); } ) < 2,
::boost::cref( rLayer ) ) ) < 2,
"MediaShape::removeViewLayer(): Duplicate ViewLayer entries!" ); "MediaShape::removeViewLayer(): Duplicate ViewLayer entries!" );
ViewMediaShapeVector::iterator aIter; ViewMediaShapeVector::iterator aIter;
if( (aIter=::std::remove_if( maViewMediaShapes.begin(), if( (aIter=::std::remove_if( maViewMediaShapes.begin(),
aEnd, aEnd,
::boost::bind<bool>( [&rLayer]
::std::equal_to< ViewLayerSharedPtr >(), ( const ViewMediaShapeSharedPtr& pShape )
::boost::bind( &ViewMediaShape::getViewLayer, { return rLayer == pShape->getViewLayer(); } ) ) == aEnd )
_1 ),
::boost::cref( rLayer ) ) )) == aEnd )
{ {
// view layer seemingly was not added, failed // view layer seemingly was not added, failed
return false; return false;
...@@ -197,10 +185,9 @@ namespace slideshow ...@@ -197,10 +185,9 @@ namespace slideshow
// redraw all view shapes, by calling their update() method // redraw all view shapes, by calling their update() method
if( ::std::count_if( maViewMediaShapes.begin(), if( ::std::count_if( maViewMediaShapes.begin(),
maViewMediaShapes.end(), maViewMediaShapes.end(),
::boost::bind<bool>( [&rCurrBounds]
::boost::mem_fn( &ViewMediaShape::render ), ( const ViewMediaShapeSharedPtr& pShape )
_1, { return pShape->render( rCurrBounds ); } )
::boost::cref( rCurrBounds ) ) )
!= static_cast<ViewMediaShapeVector::difference_type>(maViewMediaShapes.size()) ) != static_cast<ViewMediaShapeVector::difference_type>(maViewMediaShapes.size()) )
{ {
// at least one of the ViewShape::update() calls did return // at least one of the ViewShape::update() calls did return
...@@ -215,9 +202,8 @@ namespace slideshow ...@@ -215,9 +202,8 @@ namespace slideshow
bool MediaShape::implStartIntrinsicAnimation() bool MediaShape::implStartIntrinsicAnimation()
{ {
::std::for_each( maViewMediaShapes.begin(), for( const auto& pViewMediaShape : maViewMediaShapes )
maViewMediaShapes.end(), pViewMediaShape->startMedia();
::boost::mem_fn( &ViewMediaShape::startMedia ) );
mbIsPlaying = true; mbIsPlaying = true;
...@@ -228,9 +214,8 @@ namespace slideshow ...@@ -228,9 +214,8 @@ namespace slideshow
bool MediaShape::implEndIntrinsicAnimation() bool MediaShape::implEndIntrinsicAnimation()
{ {
::std::for_each( maViewMediaShapes.begin(), for( const auto& pViewMediaShape : maViewMediaShapes )
maViewMediaShapes.end(), pViewMediaShape->endMedia();
::boost::mem_fn( &ViewMediaShape::endMedia ) );
mbIsPlaying = false; mbIsPlaying = false;
...@@ -241,9 +226,8 @@ namespace slideshow ...@@ -241,9 +226,8 @@ namespace slideshow
bool MediaShape::implPauseIntrinsicAnimation() bool MediaShape::implPauseIntrinsicAnimation()
{ {
::std::for_each( maViewMediaShapes.begin(), for( const auto& pViewMediaShape : maViewMediaShapes )
maViewMediaShapes.end(), pViewMediaShape->pauseMedia();
::boost::mem_fn( &ViewMediaShape::pauseMedia ) );
mbIsPlaying = false; mbIsPlaying = false;
...@@ -261,10 +245,8 @@ namespace slideshow ...@@ -261,10 +245,8 @@ namespace slideshow
void MediaShape::implSetIntrinsicAnimationTime(double fTime) void MediaShape::implSetIntrinsicAnimationTime(double fTime)
{ {
::std::for_each( maViewMediaShapes.begin(), for( const auto& pViewMediaShape : maViewMediaShapes )
maViewMediaShapes.end(), pViewMediaShape->setMediaTime( fTime );
::boost::bind( &ViewMediaShape::setMediaTime,
_1, boost::cref(fTime)) );
} }
......
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