Commit 14d694f0 authored by Hauke Goldhammer's avatar Hauke Goldhammer

Make bb::stream_reader compatible with gcc4.8

parent 2f4b8d7d
...@@ -41,14 +41,14 @@ struct stream_reader_state { ...@@ -41,14 +41,14 @@ struct stream_reader_state {
// nop // nop
} }
void init(InputStream&& src_stream) { void init(std::unique_ptr<InputStream> src_stream) {
stream = std::move(src_stream); stream = std::move(src_stream);
} }
// -- properties ------------------------------------------------------------- // -- properties -------------------------------------------------------------
size_t at_end() const { size_t at_end() const {
return !stream; return !(*stream);
} }
// -- member variables ------------------------------------------------------- // -- member variables -------------------------------------------------------
...@@ -57,7 +57,8 @@ struct stream_reader_state { ...@@ -57,7 +57,8 @@ struct stream_reader_state {
const char* name; const char* name;
/// Stream /// Stream
InputStream stream; // TODO: change after having raised the minimum GCC version to 5.
std::unique_ptr<InputStream> stream;
/// Caches the stream line we are about to stream. /// Caches the stream line we are about to stream.
std::string line; std::string line;
...@@ -71,7 +72,8 @@ using stream_source_type = stateful_actor<stream_reader_state<InputStream>>; ...@@ -71,7 +72,8 @@ using stream_source_type = stateful_actor<stream_reader_state<InputStream>>;
/// policy to all given stream sinks. /// policy to all given stream sinks.
template <class Policy, class InputStream, class Handle, class... Handles> template <class Policy, class InputStream, class Handle, class... Handles>
behavior stream_reader(stream_source_type<InputStream>* self, behavior stream_reader(stream_source_type<InputStream>* self,
InputStream src_stream, Handle sink, Handles... sinks) { std::unique_ptr<InputStream> src_stream, Handle sink,
Handles... sinks) {
using value_type = typename Policy::value_type; using value_type = typename Policy::value_type;
self->state.init(std::move(src_stream)); self->state.init(std::move(src_stream));
// Fail early if we got nothing to stream. // Fail early if we got nothing to stream.
...@@ -87,7 +89,7 @@ behavior stream_reader(stream_source_type<InputStream>* self, ...@@ -87,7 +89,7 @@ behavior stream_reader(stream_source_type<InputStream>* self,
auto& st = self->state; auto& st = self->state;
Policy pol; Policy pol;
size_t i = 0; size_t i = 0;
while (i < hint && getline(st.stream, st.line)) { while (i < hint && getline(*(st.stream), st.line)) {
if (auto count = pol(st.line, out)) { if (auto count = pol(st.line, out)) {
i += *count; i += *count;
} else { } else {
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "caf/test/dsl.hpp" #include "caf/test/dsl.hpp"
#include <memory>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -53,7 +54,6 @@ TESTEE(stream_reader_sink) { ...@@ -53,7 +54,6 @@ TESTEE(stream_reader_sink) {
}, },
// Consumer // Consumer
[=](unit_t&, value_type val) { [=](unit_t&, value_type val) {
CAF_MESSAGE(self->name() << " " << val);
self->state.vec.emplace_back(std::move(val)); self->state.vec.emplace_back(std::move(val));
}, },
// cleanup and produce result message // cleanup and produce result message
...@@ -101,14 +101,15 @@ CAF_TEST(int_policy) { ...@@ -101,14 +101,15 @@ CAF_TEST(int_policy) {
CAF_TEST(stream_to_sink) { CAF_TEST(stream_to_sink) {
scoped_actor self{sys}; scoped_actor self{sys};
std::string test_stringvalues = "1 2 3 4 5 6 7 78 1254 1 20\n4 56 78 95"; std::string test_stringvalues = "1 2 3 4 5 6 7 78 1254 1 20\n4 56 78 95";
std::istringstream test_stream(test_stringvalues); std::unique_ptr<std::istringstream> ptr_test_stream{
new std::istringstream(test_stringvalues)};
std::vector<value_type> test_container{1, 2, 3, 4, 5, 6, 7, 78, std::vector<value_type> test_container{1, 2, 3, 4, 5, 6, 7, 78,
1254, 1, 20, 4, 56, 78, 95}; 1254, 1, 20, 4, 56, 78, 95};
auto sink = sys.spawn(stream_reader_sink); auto sink = sys.spawn(stream_reader_sink);
auto src auto src
= sys.spawn(bb::stream_reader<bb::tokenized_integer_reader<value_type>, = sys.spawn(bb::stream_reader<bb::tokenized_integer_reader<value_type>,
std::istringstream, actor>, std::istringstream, actor>,
std::move(test_stream), sink); std::move(ptr_test_stream), sink);
auto mon = sys.spawn(stream_monitor); auto mon = sys.spawn(stream_monitor);
self->send(mon, join_atom::value, src); self->send(mon, join_atom::value, src);
run(); run();
...@@ -119,7 +120,8 @@ CAF_TEST(stream_to_sink) { ...@@ -119,7 +120,8 @@ CAF_TEST(stream_to_sink) {
CAF_TEST(stream_to_sinks) { CAF_TEST(stream_to_sinks) {
scoped_actor self{sys}; scoped_actor self{sys};
std::string test_stringvalues = "1 2 3 4 5 6 7 78 1254 1 20\n4 56 78 95"; std::string test_stringvalues = "1 2 3 4 5 6 7 78 1254 1 20\n4 56 78 95";
std::istringstream test_stream(test_stringvalues); std::unique_ptr<std::istringstream> ptr_test_stream{
new std::istringstream(test_stringvalues)};
std::vector<value_type> test_container{1, 2, 3, 4, 5, 6, 7, 78, std::vector<value_type> test_container{1, 2, 3, 4, 5, 6, 7, 78,
1254, 1, 20, 4, 56, 78, 95}; 1254, 1, 20, 4, 56, 78, 95};
auto snk1 = sys.spawn(stream_reader_sink); auto snk1 = sys.spawn(stream_reader_sink);
...@@ -128,7 +130,7 @@ CAF_TEST(stream_to_sinks) { ...@@ -128,7 +130,7 @@ CAF_TEST(stream_to_sinks) {
auto src auto src
= sys.spawn(bb::stream_reader<bb::tokenized_integer_reader<value_type>, = sys.spawn(bb::stream_reader<bb::tokenized_integer_reader<value_type>,
std::istringstream, actor, actor, actor>, std::istringstream, actor, actor, actor>,
std::move(test_stream), snk1, snk2, snk3); std::move(ptr_test_stream), snk1, snk2, snk3);
auto mon = sys.spawn(stream_monitor); auto mon = sys.spawn(stream_monitor);
self->send(mon, join_atom::value, src); self->send(mon, join_atom::value, src);
run(); run();
......
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