Skip to content

Commit

Permalink
Replace boost with C++11 where applicable [DISCL-391]
Browse files Browse the repository at this point in the history
Notes:
- FramePtr must remain a boost::shared_ptr as long as Tide is
  serializing it and does not mandate boost >= 1.56.
- boost::signals2 for Stream::disconnected is hard to replace,
  however it is only used internally by QmlStreamerImpl.cpp.
- program_options and unit_test could be optional.
  • Loading branch information
Raphael Dumusc committed Sep 26, 2016
1 parent 757a3a0 commit 28652a5
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 125 deletions.
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ set(DEFLECT_LICENSE BSD)
set(DEFLECT_DEPENDENT_LIBRARIES Boost)
set(DEFLECT_DEB_DEPENDS freeglut3-dev libxi-dev libxmu-dev
libjpeg-turbo8-dev libturbojpeg
libboost-date-time-dev libboost-program-options-dev libboost-system-dev
libboost-test-dev libboost-thread-dev
libboost-program-options-dev libboost-test-dev
qtbase5-dev qtdeclarative5-dev)
set(DEFLECT_PORT_DEPENDS boost freeglut qt5)

include(Common)

common_find_package(Boost REQUIRED COMPONENTS date_time program_options system
thread unit_test_framework)
common_find_package(Boost REQUIRED COMPONENTS program_options
unit_test_framework)
common_find_package(GLUT)
common_find_package(LibJpegTurbo REQUIRED)
common_find_package(OpenGL)
Expand Down
2 changes: 2 additions & 0 deletions apps/DesktopStreamer/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
#include <QScreen>

#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>

#ifdef _WIN32
typedef __int32 int32_t;
Expand Down
3 changes: 2 additions & 1 deletion apps/SimpleStreamer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@

#include <deflect/Stream.h>

#include <string>
#include <cmath>
#include <iostream>
#include <string>

#ifdef __APPLE__
# include <OpenGL/gl.h>
Expand Down
2 changes: 2 additions & 0 deletions deflect/FrameDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include "Frame.h"
#include "ReceiveBuffer.h"

#include <cassert>

namespace deflect
{

Expand Down
2 changes: 1 addition & 1 deletion deflect/ImageSegmenter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************************/
/* Copyright (c) 2013-2015, EPFL/Blue Brain Project */
/* Copyright (c) 2013-2016, EPFL/Blue Brain Project */
/* Raphael Dumusc <[email protected]> */
/* [email protected] */
/* All rights reserved. */
Expand Down
6 changes: 3 additions & 3 deletions deflect/ImageSegmenter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************************/
/* Copyright (c) 2013-2015, EPFL/Blue Brain Project */
/* Copyright (c) 2013-2016, EPFL/Blue Brain Project */
/* Raphael Dumusc <[email protected]> */
/* [email protected] */
/* All rights reserved. */
Expand Down Expand Up @@ -47,7 +47,7 @@
#include <deflect/MTQueue.h>
#include <deflect/Segment.h>

#include <boost/function/function1.hpp>
#include <functional>
#include <vector>

namespace deflect
Expand All @@ -63,7 +63,7 @@ class ImageSegmenter
DEFLECT_API ImageSegmenter();

/** Function called on each segment. */
typedef boost::function< bool( const Segment& ) > Handler;
using Handler = std::function< bool( const Segment& ) >;

/**
* Generate segments.
Expand Down
12 changes: 6 additions & 6 deletions deflect/ReceiveBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

#include "ReceiveBuffer.h"

#include <cassert>

namespace deflect
{

Expand Down Expand Up @@ -91,10 +93,9 @@ bool ReceiveBuffer::hasCompleteFrame() const
assert( !_sourceBuffers.empty( ));

// Check if all sources for Stream have reached the same index
for( SourceBufferMap::const_iterator it = _sourceBuffers.begin();
it != _sourceBuffers.end(); ++it )
for( const auto& kv : _sourceBuffers )
{
const SourceBuffer& buffer = it->second;
const auto& buffer = kv.second;
if( buffer.backFrameIndex <= _lastFrameComplete )
return false;
}
Expand All @@ -104,10 +105,9 @@ bool ReceiveBuffer::hasCompleteFrame() const
Segments ReceiveBuffer::popFrame()
{
Segments frame;
for( SourceBufferMap::iterator it = _sourceBuffers.begin();
it != _sourceBuffers.end(); ++it )
for( auto& kv : _sourceBuffers )
{
SourceBuffer& buffer = it->second;
auto& buffer = kv.second;
frame.insert( frame.end(), buffer.segments.front().begin(),
buffer.segments.front().end( ));
buffer.pop();
Expand Down
4 changes: 1 addition & 3 deletions deflect/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

#ifdef DEFLECT_USE_SERVUS
# include <servus/servus.h>
# include <boost/lexical_cast.hpp>
#endif

#include <QThread>
Expand Down Expand Up @@ -77,8 +76,7 @@ Server::Server( const int port )
{
if( !listen( QHostAddress::Any, port ))
{
const QString err =
QString( "could not listen on port: %1" ).arg( port );
const auto err = QString( "could not listen on port: %1" ).arg( port );
throw std::runtime_error( err.toStdString( ));
}
#ifdef DEFLECT_USE_SERVUS
Expand Down
12 changes: 3 additions & 9 deletions deflect/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,11 @@
#include <deflect/Event.h>
#include <deflect/ImageWrapper.h>

#include <future>
#include <memory>
#include <string>

#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829
// needed for future.hpp with Boost 1.41
# include <boost/thread/mutex.hpp>
# include <boost/thread/condition_variable.hpp>

# include <boost/thread/future.hpp>
# include <boost/signals2/signal.hpp>
#endif
#include <boost/signals2/signal.hpp>

class Application;

Expand Down Expand Up @@ -132,7 +126,7 @@ class Stream
/** @name Asynchronous send API */
//@{
/** Future signaling success of asyncSend(). @version 1.1 */
typedef boost::unique_future< bool > Future;
using Future = std::future< bool >;

/**
* Send an image and finish the frame asynchronously.
Expand Down
4 changes: 2 additions & 2 deletions deflect/StreamPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ bool StreamPrivate::send( const ImageWrapper& image )
return false;
}

const ImageSegmenter::Handler sendFunc =
boost::bind( &StreamPrivate::sendPixelStreamSegment, this, _1 );
const auto sendFunc = std::bind( &StreamPrivate::sendPixelStreamSegment,
this, std::placeholders::_1 );
return imageSegmenter.generate( image, sendFunc );
}

Expand Down
10 changes: 5 additions & 5 deletions deflect/StreamSendWorker.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************************/
/* Copyright (c) 2013-2014, EPFL/Blue Brain Project */
/* Copyright (c) 2013-2016, EPFL/Blue Brain Project */
/* [email protected] */
/* All rights reserved. */
/* */
Expand Down Expand Up @@ -47,7 +47,7 @@ namespace deflect
StreamSendWorker::StreamSendWorker( StreamPrivate& stream )
: _stream( stream )
, _running( true )
, _thread( boost::bind( &StreamSendWorker::_run, this ))
, _thread( std::bind( &StreamSendWorker::_run, this ))
{}

StreamSendWorker::~StreamSendWorker()
Expand All @@ -57,7 +57,7 @@ StreamSendWorker::~StreamSendWorker()

void StreamSendWorker::_run()
{
boost::mutex::scoped_lock lock( _mutex );
std::unique_lock<std::mutex> lock( _mutex );
while( true )
{
while( _requests.empty() && _running )
Expand All @@ -75,7 +75,7 @@ void StreamSendWorker::_run()
void StreamSendWorker::_stop()
{
{
boost::mutex::scoped_lock lock( _mutex );
std::lock_guard<std::mutex> lock( _mutex );
_running = false;
_condition.notify_all();
}
Expand All @@ -90,7 +90,7 @@ void StreamSendWorker::_stop()

Stream::Future StreamSendWorker::enqueueImage( const ImageWrapper& image )
{
boost::mutex::scoped_lock lock( _mutex );
std::lock_guard<std::mutex> lock( _mutex );
PromisePtr promise( new Promise );
_requests.push_back( Request( promise, image ));
_condition.notify_all();
Expand Down
22 changes: 9 additions & 13 deletions deflect/StreamSendWorker.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************************/
/* Copyright (c) 2013-2014, EPFL/Blue Brain Project */
/* Copyright (c) 2013-2016, EPFL/Blue Brain Project */
/* [email protected] */
/* All rights reserved. */
/* */
Expand Down Expand Up @@ -40,12 +40,8 @@
#ifndef DEFLECT_STREAMSENDWORKER_H
#define DEFLECT_STREAMSENDWORKER_H

// needed for future.hpp with Boost 1.41
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>

#include <boost/thread/future.hpp>
#include <boost/thread/thread.hpp>
#include <mutex>
#include <thread>
#include <deque>

#include "Stream.h" // Stream::Future
Expand Down Expand Up @@ -76,16 +72,16 @@ class StreamSendWorker
/** Stop the worker and clear any pending image send requests. */
void _stop();

typedef boost::promise< bool > Promise;
typedef boost::shared_ptr< Promise > PromisePtr;
typedef std::pair< PromisePtr, ImageWrapper > Request;
using Promise = std::promise< bool >;
using PromisePtr = std::shared_ptr< Promise >;
using Request = std::pair< PromisePtr, ImageWrapper >;

StreamPrivate& _stream;
std::deque< Request > _requests;
boost::mutex _mutex;
boost::condition _condition;
std::mutex _mutex;
std::condition_variable _condition;
bool _running;
boost::thread _thread;
std::thread _thread;
};

}
Expand Down
3 changes: 1 addition & 2 deletions deflect/qt/QmlStreamerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,7 @@ bool QmlStreamer::Impl::_setupDeflectStream()
if( !_stream->isConnected( ))
return false;

_stream->disconnected.connect(
boost::bind( &QmlStreamer::Impl::streamClosed, this ));
_stream->disconnected.connect( [this](){ emit streamClosed(); } );

if( !_stream->registerForEvents( ))
return false;
Expand Down
3 changes: 3 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog {#Changelog}

### 0.12.0 (git master)

* [130](https://github.com/BlueBrain/Deflect/pull/130)
Replaced boost by C++11 where applicable. It is still required in two places:
Stream::disconnected signal, FramePtr (for serialization with boost in Tide).
* [129](https://github.com/BlueBrain/Deflect/pull/129)
Cleared Deflect from boost::serialization that was used exclusively by Tide.
* [128](https://github.com/BlueBrain/Deflect/pull/128)
Expand Down
17 changes: 8 additions & 9 deletions tests/cpp/ImageSegmenterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ namespace ut = boost::unit_test;
#include <deflect/Segment.h>

#include <QMutex>
#include <boost/bind.hpp>

static bool append( deflect::Segments& segments,
const deflect::Segment& segment )
Expand Down Expand Up @@ -74,8 +73,8 @@ BOOST_AUTO_TEST_CASE( testImageSegmenterSegmentParameters )
deflect::ImageWrapper imageWrapper( data, 4, 8, deflect::RGB );

deflect::Segments segments;
const deflect::ImageSegmenter::Handler appendFunc =
boost::bind( &append, boost::ref( segments ), _1 );
const auto appendFunc = std::bind( &append, std::ref( segments ),
std::placeholders::_1 );

{
deflect::ImageSegmenter segmenter;
Expand Down Expand Up @@ -164,8 +163,8 @@ BOOST_AUTO_TEST_CASE( testImageSegmenterSingleSegmentData )

deflect::ImageSegmenter segmenter;
deflect::Segments segments;
const deflect::ImageSegmenter::Handler appendFunc =
boost::bind( &append, boost::ref( segments ), _1 );
const auto appendFunc = std::bind( &append, std::ref( segments ),
std::placeholders::_1 );

segmenter.generate( imageWrapper, appendFunc );
BOOST_REQUIRE_EQUAL( segments.size(), 1 );
Expand Down Expand Up @@ -226,8 +225,8 @@ BOOST_AUTO_TEST_CASE( testImageSegmenterUniformSegmentationData )

deflect::ImageSegmenter segmenter;
deflect::Segments segments;
const deflect::ImageSegmenter::Handler appendFunc =
boost::bind( &append, boost::ref( segments ), _1 );
const auto appendFunc = std::bind( &append, std::ref( segments ),
std::placeholders::_1 );

segmenter.setNominalSegmentDimensions( 2, 4 );
segmenter.generate( imageWrapper, appendFunc );
Expand Down Expand Up @@ -301,8 +300,8 @@ BOOST_AUTO_TEST_CASE( testImageSegmenterNonUniformSegmentationData )

deflect::ImageSegmenter segmenter;
deflect::Segments segments;
const deflect::ImageSegmenter::Handler appendFunc =
boost::bind( &append, boost::ref( segments ), _1 );
const auto appendFunc = std::bind( &append, std::ref( segments ),
std::placeholders::_1 );

segmenter.setNominalSegmentDimensions( 3, 5 );
segmenter.generate( imageWrapper, appendFunc );
Expand Down
6 changes: 2 additions & 4 deletions tests/cpp/SegmentDecoderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ namespace ut = boost::unit_test;
#include <deflect/Segment.h>
#include <deflect/SegmentDecoder.h>

#include <boost/bind.hpp>

#include <QMutex>

void fillTestImage( std::vector<char>& data )
Expand Down Expand Up @@ -114,8 +112,8 @@ BOOST_AUTO_TEST_CASE( testImageSegmentationWithCompressionAndDecompression )

deflect::Segments segments;
deflect::ImageSegmenter segmenter;
const deflect::ImageSegmenter::Handler appendFunc =
boost::bind( &append, boost::ref( segments ), _1 );
const auto appendFunc = std::bind( &append, std::ref( segments ),
std::placeholders::_1 );

segmenter.generate( imageWrapper, appendFunc );
BOOST_REQUIRE_EQUAL( segments.size(), 1 );
Expand Down
Loading

0 comments on commit 28652a5

Please sign in to comment.