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
3d8fd257
Commit
3d8fd257
authored
Aug 11, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix config_value ctor for list/map, add tests
parent
b397c962
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
2 deletions
+20
-2
libcaf_core/caf/config_value.hpp
libcaf_core/caf/config_value.hpp
+3
-1
libcaf_core/caf/detail/parse.hpp
libcaf_core/caf/detail/parse.hpp
+5
-0
libcaf_core/test/config_option.cpp
libcaf_core/test/config_option.cpp
+10
-1
libcaf_core/test/config_value.cpp
libcaf_core/test/config_value.cpp
+2
-0
No files found.
libcaf_core/caf/config_value.hpp
View file @
3d8fd257
...
...
@@ -176,6 +176,7 @@ private:
template
<
class
T
>
void
set_range
(
T
&
xs
,
std
::
true_type
)
{
auto
&
dict
=
as_dictionary
();
dict
.
clear
();
for
(
auto
&
kvp
:
xs
)
dict
.
emplace
(
kvp
.
first
,
std
::
move
(
kvp
.
second
));
}
...
...
@@ -183,7 +184,8 @@ private:
template
<
class
T
>
void
set_range
(
T
&
xs
,
std
::
false_type
)
{
auto
&
ls
=
as_list
();
ls
.
insert
(
ls
.
begin
(),
std
::
make_move_iterator
(
xs
.
begin
()),
ls
.
clear
();
ls
.
insert
(
ls
.
end
(),
std
::
make_move_iterator
(
xs
.
begin
()),
std
::
make_move_iterator
(
xs
.
end
()));
}
...
...
libcaf_core/caf/detail/parse.hpp
View file @
3d8fd257
...
...
@@ -109,6 +109,7 @@ enable_if_tt<is_iterable<T>> parse(parse_state& ps, T& xs) {
static
constexpr
auto
opening_char
=
is_map_type
?
'{'
:
'['
;
static
constexpr
auto
closing_char
=
is_map_type
?
'}'
:
']'
;
auto
out
=
std
::
inserter
(
xs
,
xs
.
end
());
// List/map using [] or {} notation.
if
(
ps
.
consume
(
opening_char
))
{
do
{
if
(
ps
.
consume
(
closing_char
))
{
...
...
@@ -130,6 +131,10 @@ enable_if_tt<is_iterable<T>> parse(parse_state& ps, T& xs) {
}
return
;
}
// An empty string simply results in an empty list/map.
if
(
ps
.
at_end
())
return
;
// List/map without [] or {}.
do
{
value_type
tmp
;
parse
(
ps
,
tmp
);
...
...
libcaf_core/test/config_option.cpp
View file @
3d8fd257
...
...
@@ -49,7 +49,8 @@ optional<T> read(string_view arg) {
auto
co
=
make_config_option
<
T
>
(
category
,
name
,
explanation
);
auto
res
=
co
.
parse
(
arg
);
if
(
res
&&
holds_alternative
<
T
>
(
*
res
))
{
CAF_CHECK_EQUAL
(
co
.
check
(
*
res
),
none
);
if
(
co
.
check
(
*
res
)
!=
none
)
CAF_ERROR
(
"co.parse() produced the wrong type!"
);
return
get
<
T
>
(
*
res
);
}
return
none
;
...
...
@@ -182,6 +183,14 @@ CAF_TEST(type timespan) {
CAF_CHECK_EQUAL
(
unbox
(
read
<
timespan
>
(
"500ns"
)),
dur
);
}
CAF_TEST
(
lists
)
{
using
int_list
=
std
::
vector
<
int
>
;
CAF_CHECK_EQUAL
(
read
<
int_list
>
(
""
),
int_list
({}));
CAF_CHECK_EQUAL
(
read
<
int_list
>
(
"[]"
),
int_list
({}));
CAF_CHECK_EQUAL
(
read
<
int_list
>
(
"1, 2, 3"
),
int_list
({
1
,
2
,
3
}));
CAF_CHECK_EQUAL
(
read
<
int_list
>
(
"[1, 2, 3]"
),
int_list
({
1
,
2
,
3
}));
}
CAF_TEST
(
flat
CLI
parsing
)
{
auto
x
=
make_config_option
<
std
::
string
>
(
"?foo"
,
"bar,b"
,
"test option"
);
CAF_CHECK_EQUAL
(
x
.
category
(),
"foo"
);
...
...
libcaf_core/test/config_value.cpp
View file @
3d8fd257
...
...
@@ -132,6 +132,8 @@ CAF_TEST(timespan) {
CAF_TEST
(
list
)
{
using
integer_list
=
std
::
vector
<
int64_t
>
;
auto
xs
=
make_config_value_list
(
1
,
2
,
3
);
auto
ys
=
config_value
{
integer_list
{
1
,
2
,
3
}};
CAF_CHECK_EQUAL
(
xs
,
ys
);
CAF_CHECK_EQUAL
(
to_string
(
xs
),
"[1, 2, 3]"
);
CAF_CHECK_EQUAL
(
xs
.
type_name
(),
"list"
_s
);
CAF_CHECK_EQUAL
(
holds_alternative
<
config_value
::
list
>
(
xs
),
true
);
...
...
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