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
cf2df9b2
Commit
cf2df9b2
authored
Sep 24, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test custom config_value_access specializations
parent
44127021
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
libcaf_core/test/settings.cpp
libcaf_core/test/settings.cpp
+53
-0
No files found.
libcaf_core/test/settings.cpp
View file @
cf2df9b2
...
...
@@ -82,8 +82,51 @@ const config_value& unpack(const settings& x, string_view key,
keys
...);
}
struct
foobar
{
int
foo
=
0
;
int
bar
=
0
;
};
}
// namespace
namespace
caf
{
// Enable users to configure foobar's like this:
// my-value {
// foo = 42
// bar = 23
// }
template
<
>
struct
config_value_access
<
foobar
>
{
static
bool
is
(
const
config_value
&
x
)
{
auto
dict
=
caf
::
get_if
<
config_value
::
dictionary
>
(
&
x
);
if
(
dict
!=
nullptr
)
{
return
caf
::
get_if
<
int
>
(
dict
,
"foo"
)
!=
none
&&
caf
::
get_if
<
int
>
(
dict
,
"bar"
)
!=
none
;
}
return
false
;
}
static
optional
<
foobar
>
get_if
(
const
config_value
*
x
)
{
foobar
result
;
if
(
!
is
(
*
x
))
return
none
;
const
auto
&
dict
=
caf
::
get
<
config_value
::
dictionary
>
(
*
x
);
result
.
foo
=
caf
::
get
<
int
>
(
dict
,
"foo"
);
result
.
bar
=
caf
::
get
<
int
>
(
dict
,
"bar"
);
return
result
;
}
static
foobar
get
(
const
config_value
&
x
)
{
auto
result
=
get_if
(
&
x
);
if
(
!
result
)
CAF_RAISE_ERROR
(
"invalid type found"
);
return
std
::
move
(
*
result
);
}
};
}
// namespace caf
CAF_TEST_FIXTURE_SCOPE
(
settings_tests
,
fixture
)
CAF_TEST
(
put
)
{
...
...
@@ -159,4 +202,14 @@ CAF_TEST(get_or) {
CAF_CHECK_EQUAL
(
get_or
(
x
,
"goodbye"
,
"nobody"
),
"nobody"
_s
);
}
CAF_TEST
(
custom
type
)
{
put
(
x
,
"my-value.foo"
,
42
);
put
(
x
,
"my-value.bar"
,
24
);
CAF_REQUIRE
(
holds_alternative
<
foobar
>
(
x
,
"my-value"
));
CAF_REQUIRE
(
get_if
<
foobar
>
(
&
x
,
"my-value"
)
!=
caf
::
none
);
auto
fb
=
get
<
foobar
>
(
x
,
"my-value"
);
CAF_CHECK_EQUAL
(
fb
.
foo
,
42
);
CAF_CHECK_EQUAL
(
fb
.
bar
,
24
);
}
CAF_TEST_FIXTURE_SCOPE_END
()
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