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
99972912
Commit
99972912
authored
Jan 10, 2021
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve parsing of booleans from config values
parent
70af2bb9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
1 deletion
+36
-1
libcaf_core/src/config_value.cpp
libcaf_core/src/config_value.cpp
+26
-1
libcaf_core/test/config_value.cpp
libcaf_core/test/config_value.cpp
+10
-0
No files found.
libcaf_core/src/config_value.cpp
View file @
99972912
...
...
@@ -220,7 +220,7 @@ expected<bool> config_value::to_boolean() const {
using
result_type
=
expected
<
bool
>
;
auto
f
=
detail
::
make_overload
(
no_conversions
<
bool
,
none_t
,
integer
,
real
,
timespan
,
uri
,
config_value
::
list
,
config_value
::
dictionary
>
(),
config_value
::
list
>
(),
[](
boolean
x
)
{
return
result_type
{
x
};
},
[](
const
std
::
string
&
x
)
{
if
(
x
==
"true"
)
{
...
...
@@ -233,6 +233,31 @@ expected<bool> config_value::to_boolean() const {
msg
+=
" to a boolean"
;
return
result_type
{
make_error
(
sec
::
conversion_failed
,
std
::
move
(
msg
))};
}
},
[](
const
dictionary
&
x
)
{
if
(
auto
i
=
x
.
find
(
"@type"
);
i
!=
x
.
end
()
&&
holds_alternative
<
std
::
string
>
(
i
->
second
))
{
const
auto
&
tn
=
get
<
std
::
string
>
(
i
->
second
);
if
(
tn
==
type_name_v
<
bool
>
)
{
if
(
auto
j
=
x
.
find
(
"value"
);
j
!=
x
.
end
())
{
return
j
->
second
.
to_boolean
();
}
else
{
std
::
string
msg
=
"missing value for object of type "
;
msg
+=
tn
;
return
result_type
{
make_error
(
sec
::
conversion_failed
,
std
::
move
(
msg
))};
}
}
else
{
std
::
string
msg
=
"cannot convert "
;
msg
+=
tn
;
msg
+=
" to a boolean"
;
return
result_type
{
make_error
(
sec
::
conversion_failed
,
std
::
move
(
msg
))};
}
}
else
{
std
::
string
msg
=
"cannot convert a dictionary to a boolean"
;
return
result_type
{
make_error
(
sec
::
conversion_failed
,
std
::
move
(
msg
))};
}
});
return
visit
(
f
,
data_
);
}
...
...
libcaf_core/test/config_value.cpp
View file @
99972912
...
...
@@ -97,6 +97,16 @@ SCENARIO("get_as can convert config values to boolean") {
}
}
}
GIVEN
(
"a config value with type annotation 'bool' and the value
\"
true
\"
"
)
{
config_value
x
;
x
.
as_dictionary
().
emplace
(
"@type"
,
"bool"
);
x
.
as_dictionary
().
emplace
(
"value"
,
"true"
);
WHEN
(
"using get_as with bool"
)
{
THEN
(
"conversion succeeds"
)
{
CHECK_EQ
(
get_as
<
bool
>
(
x
),
true
);
}
}
}
GIVEN
(
"non-boolean config_values"
)
{
WHEN
(
"using get_as with bool"
)
{
THEN
(
"conversion fails"
)
{
...
...
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