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
431e302b
Commit
431e302b
authored
Oct 07, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add free function to set value in config_value_map
parent
5418edea
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
0 deletions
+83
-0
libcaf_core/caf/config_value.hpp
libcaf_core/caf/config_value.hpp
+25
-0
libcaf_core/src/config_value.cpp
libcaf_core/src/config_value.cpp
+44
-0
libcaf_core/test/config_value.cpp
libcaf_core/test/config_value.cpp
+14
-0
No files found.
libcaf_core/caf/config_value.hpp
View file @
431e302b
...
@@ -530,6 +530,31 @@ T get_or(const actor_system_config& cfg, string_view name,
...
@@ -530,6 +530,31 @@ T get_or(const actor_system_config& cfg, string_view name,
std
::
string
get_or
(
const
actor_system_config
&
cfg
,
string_view
name
,
std
::
string
get_or
(
const
actor_system_config
&
cfg
,
string_view
name
,
const
char
*
default_value
);
const
char
*
default_value
);
/// @private
void
put_impl
(
config_value
::
dictionary
&
dict
,
const
std
::
vector
<
string_view
>&
path
,
config_value
&
value
);
/// @private
void
put_impl
(
config_value
::
dictionary
&
dict
,
string_view
key
,
config_value
&
value
);
/// @private
void
put_impl
(
dictionary
<
config_value
::
dictionary
>&
dict
,
string_view
key
,
config_value
&
value
);
/// Converts `value` to a `config_value` and assigns it to `key`.
/// @param dict Dictionary of key-value pairs.
/// @param key Human-readable nested keys in the form `category.key`.
/// @param value New value for given `key`.
template
<
class
T
>
void
put
(
dictionary
<
config_value
::
dictionary
>&
dict
,
string_view
key
,
T
&&
value
)
{
config_value
tmp
{
std
::
forward
<
T
>
(
value
)};
put_impl
(
dict
,
key
,
tmp
);
}
/// @relates config_value
/// @relates config_value
bool
operator
<
(
const
config_value
&
x
,
const
config_value
&
y
);
bool
operator
<
(
const
config_value
&
x
,
const
config_value
&
y
);
...
...
libcaf_core/src/config_value.cpp
View file @
431e302b
...
@@ -146,5 +146,49 @@ std::string get_or(const actor_system_config& cfg, string_view name,
...
@@ -146,5 +146,49 @@ std::string get_or(const actor_system_config& cfg, string_view name,
return
get_or
(
content
(
cfg
),
name
,
default_value
);
return
get_or
(
content
(
cfg
),
name
,
default_value
);
}
}
void
put_impl
(
config_value
::
dictionary
&
dict
,
const
std
::
vector
<
string_view
>&
path
,
config_value
&
value
)
{
// Sanity check.
if
(
path
.
empty
())
return
;
// Navigate path.
auto
last
=
path
.
end
();
auto
back
=
last
-
1
;
auto
current
=
&
dict
;
// Resolve path by navigating the map-of-maps of create the necessary layout
// when needed.
for
(
auto
i
=
path
.
begin
();
i
!=
back
;
++
i
)
{
auto
iter
=
current
->
emplace
(
*
i
,
config_value
::
dictionary
{}).
first
;
if
(
auto
val
=
get_if
<
config_value
::
dictionary
>
(
&
iter
->
second
))
{
current
=
val
;
}
else
{
iter
->
second
=
config_value
::
dictionary
{};
current
=
&
get
<
config_value
::
dictionary
>
(
iter
->
second
);
}
}
// Set key-value pair on the leaf.
current
->
insert_or_assign
(
*
back
,
std
::
move
(
value
));
}
void
put_impl
(
config_value
::
dictionary
&
dict
,
string_view
key
,
config_value
&
value
)
{
std
::
vector
<
string_view
>
path
;
split
(
path
,
key
,
"."
);
put_impl
(
dict
,
path
,
value
);
}
void
put_impl
(
dictionary
<
config_value
::
dictionary
>&
dict
,
string_view
key
,
config_value
&
value
)
{
// Split the name into a path.
std
::
vector
<
string_view
>
path
;
split
(
path
,
key
,
"."
);
// Sanity check. At the very least, we need a category and a key.
if
(
path
.
size
()
<
2
)
return
;
auto
category
=
path
.
front
();
path
.
erase
(
path
.
begin
());
put_impl
(
dict
[
category
],
path
,
value
);
}
}
// namespace caf
}
// namespace caf
libcaf_core/test/config_value.cpp
View file @
431e302b
...
@@ -250,3 +250,17 @@ CAF_TEST(unsuccessful parsing) {
...
@@ -250,3 +250,17 @@ CAF_TEST(unsuccessful parsing) {
CAF_CHECK_EQUAL
(
parse
(
"{a=1,"
),
pec
::
unexpected_eof
);
CAF_CHECK_EQUAL
(
parse
(
"{a=1,"
),
pec
::
unexpected_eof
);
CAF_CHECK_EQUAL
(
parse
(
"{a=1 b=2}"
),
pec
::
unexpected_character
);
CAF_CHECK_EQUAL
(
parse
(
"{a=1 b=2}"
),
pec
::
unexpected_character
);
}
}
CAF_TEST
(
put
values
)
{
using
v
=
config_value
;
using
d
=
config_value
::
dictionary
;
using
dd
=
caf
::
dictionary
<
d
>
;
dd
content
;
put
(
content
,
"a.b"
,
42
);
CAF_CHECK_EQUAL
(
content
,
dd
({{
"a"
,
d
({{
"b"
,
v
{
42
}}})}}));
put
(
content
,
"a.b.c"
,
1
);
CAF_CHECK_EQUAL
(
content
,
dd
({{
"a"
,
d
({{
"b"
,
v
{
d
({{
"c"
,
v
{
1
}}})}}})}}));
put
(
content
,
"a.b.d"
,
2
);
CAF_CHECK_EQUAL
(
content
,
dd
({{
"a"
,
d
({{
"b"
,
v
{
d
({{
"c"
,
v
{
1
}},
{
"d"
,
v
{
2
}}})}}})}}));
}
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