Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
actor-incubator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
actor-incubator
Commits
14d694f0
Commit
14d694f0
authored
Mar 21, 2019
by
Hauke Goldhammer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make bb::stream_reader compatible with gcc4.8
parent
2f4b8d7d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
10 deletions
+14
-10
libcaf_bb/caf/bb/stream_reader.hpp
libcaf_bb/caf/bb/stream_reader.hpp
+7
-5
libcaf_bb/test/stream_reader.cpp
libcaf_bb/test/stream_reader.cpp
+7
-5
No files found.
libcaf_bb/caf/bb/stream_reader.hpp
View file @
14d694f0
...
@@ -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
{
...
...
libcaf_bb/test/stream_reader.cpp
View file @
14d694f0
...
@@ -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
\n
4 56 78 95"
;
std
::
string
test_stringvalues
=
"1 2 3 4 5 6 7 78 1254 1 20
\n
4 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
\n
4 56 78 95"
;
std
::
string
test_stringvalues
=
"1 2 3 4 5 6 7 78 1254 1 20
\n
4 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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment