Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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 Framework
Commits
254e30c6
Commit
254e30c6
authored
Jul 27, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing insert overload
parent
7085b6c6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
20 deletions
+35
-20
libcaf_io/caf/io/network/receive_buffer.hpp
libcaf_io/caf/io/network/receive_buffer.hpp
+19
-2
libcaf_io/test/receive_buffer.cpp
libcaf_io/test/receive_buffer.cpp
+16
-18
No files found.
libcaf_io/caf/io/network/receive_buffer.hpp
View file @
254e30c6
...
...
@@ -18,8 +18,9 @@
#pragma once
#include <memory>
#include <cstddef>
#include <cstring>
#include <memory>
#include "caf/allowed_unsafe_message_type.hpp"
...
...
@@ -142,7 +143,7 @@ public:
return
buffer_
.
get
()
+
size_
;
}
/// Returns an iterator to the reverse beginning.
/// Returns
j
an iterator to the reverse beginning.
inline
reverse_iterator
rbegin
()
noexcept
{
return
reverse_iterator
{
buffer_
.
get
()
+
size_
};
}
...
...
@@ -175,6 +176,22 @@ public:
/// Insert `value` before `pos`.
iterator
insert
(
iterator
pos
,
value_type
value
);
/// Insert `value` before `pos`.
template
<
class
InputIterator
>
iterator
insert
(
iterator
pos
,
InputIterator
first
,
InputIterator
last
)
{
auto
n
=
std
::
distance
(
first
,
last
);
if
(
n
==
0
)
return
pos
;
auto
offset
=
static_cast
<
size_t
>
(
std
::
distance
(
begin
(),
pos
));
auto
old_size
=
size_
;
resize
(
old_size
+
n
);
pos
=
begin
()
+
offset
;
if
(
offset
!=
old_size
)
{
memmove
(
pos
+
n
,
pos
,
old_size
-
offset
);
}
return
std
::
copy
(
first
,
last
,
pos
);
}
/// Append `value`.
void
push_back
(
value_type
value
);
...
...
libcaf_io/test/receive_buffer.cpp
View file @
254e30c6
...
...
@@ -38,6 +38,13 @@ struct fixture {
fixture
()
:
b
(
1024ul
),
vec
{
'h'
,
'a'
,
'l'
,
'l'
,
'o'
}
{
// nop
}
std
::
string
as_string
(
const
receive_buffer
&
xs
)
{
std
::
string
result
;
for
(
auto
&
x
:
xs
)
result
+=
static_cast
<
char
>
(
x
);
return
result
;
}
};
}
// namespace <anonymous>
...
...
@@ -131,26 +138,17 @@ CAF_TEST(push_back) {
CAF_TEST
(
insert
)
{
for
(
auto
c
:
vec
)
a
.
insert
(
a
.
end
(),
c
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
0
),
'h'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
1
),
'a'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
2
),
'l'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
3
),
'l'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
4
),
'o'
);
CAF_CHECK_EQUAL
(
as_string
(
a
),
"hallo"
);
a
.
insert
(
a
.
begin
(),
'!'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
0
),
'!'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
1
),
'h'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
2
),
'a'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
3
),
'l'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
4
),
'l'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
5
),
'o'
);
CAF_CHECK_EQUAL
(
as_string
(
a
),
"!hallo"
);
a
.
insert
(
a
.
begin
()
+
4
,
'-'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
0
),
'!'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
1
),
'h'
)
;
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
2
),
'a'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
3
),
'l'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
4
),
'-'
)
;
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
5
),
'l'
);
CAF_CHECK_EQUAL
(
*
(
a
.
data
()
+
6
),
'o'
);
CAF_CHECK_EQUAL
(
as_string
(
a
),
"!hal-lo"
);
std
::
string
foo
=
"foo:"
;
a
.
insert
(
a
.
begin
()
+
1
,
foo
.
begin
(),
foo
.
end
()
);
CAF_CHECK_EQUAL
(
as_string
(
a
),
"!foo:hal-lo"
);
std
::
string
bar
=
":bar"
;
a
.
insert
(
a
.
end
(),
bar
.
begin
(),
bar
.
end
()
);
CAF_CHECK_EQUAL
(
as_string
(
a
),
"!foo:hal-lo:bar"
);
}
CAF_TEST
(
shrink_to_fit
)
{
...
...
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