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
bc8b21fc
Commit
bc8b21fc
authored
Jan 14, 2021
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow dot-separated notation in config files
parent
b08139c6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
2 deletions
+52
-2
libcaf_core/caf/detail/parser/read_config.hpp
libcaf_core/caf/detail/parser/read_config.hpp
+12
-2
libcaf_core/test/actor_system_config.cpp
libcaf_core/test/actor_system_config.cpp
+40
-0
No files found.
libcaf_core/caf/detail/parser/read_config.hpp
View file @
bc8b21fc
...
@@ -116,6 +116,15 @@ void read_config_map(State& ps, Consumer&& consumer) {
...
@@ -116,6 +116,15 @@ void read_config_map(State& ps, Consumer&& consumer) {
auto
alnum_or_dash
=
[](
char
x
)
{
auto
alnum_or_dash
=
[](
char
x
)
{
return
isalnum
(
x
)
||
x
==
'-'
||
x
==
'_'
;
return
isalnum
(
x
)
||
x
==
'-'
||
x
==
'_'
;
};
};
auto
set_key
=
[
&
consumer
,
&
key
]
{
std
::
string
tmp
;
tmp
.
swap
(
key
);
consumer
.
key
(
std
::
move
(
tmp
));
};
auto
recurse
=
[
&
consumer
,
&
set_key
]()
->
decltype
(
auto
)
{
set_key
();
return
consumer
.
begin_map
();
};
// clang-format off
// clang-format off
start
();
start
();
term_state
(
init
)
{
term_state
(
init
)
{
...
@@ -131,13 +140,14 @@ void read_config_map(State& ps, Consumer&& consumer) {
...
@@ -131,13 +140,14 @@ void read_config_map(State& ps, Consumer&& consumer) {
// Reads a key of a "key=value" line.
// Reads a key of a "key=value" line.
state
(
read_key_name
)
{
state
(
read_key_name
)
{
transition
(
read_key_name
,
alnum_or_dash
,
key
+=
ch
)
transition
(
read_key_name
,
alnum_or_dash
,
key
+=
ch
)
fsm_transition
(
read_config_map
(
ps
,
recurse
()),
done
,
'.'
)
epsilon
(
await_assignment
)
epsilon
(
await_assignment
)
}
}
// Reads the assignment operator in a "key=value" line.
// Reads the assignment operator in a "key=value" line.
state
(
await_assignment
)
{
state
(
await_assignment
)
{
transition
(
await_assignment
,
"
\t
"
)
transition
(
await_assignment
,
"
\t
"
)
transition
(
await_value
,
"=:"
,
consumer
.
key
(
std
::
move
(
key
)
))
transition
(
await_value
,
"=:"
,
set_key
(
))
epsilon
(
await_value
,
'{'
,
consumer
.
key
(
std
::
move
(
key
)
))
epsilon
(
await_value
,
'{'
,
set_key
(
))
}
}
// Reads the value in a "key=value" line.
// Reads the value in a "key=value" line.
state
(
await_value
)
{
state
(
await_value
)
{
...
...
libcaf_core/test/actor_system_config.cpp
View file @
bc8b21fc
...
@@ -297,4 +297,44 @@ CAF_TEST(basic and basic containers options) {
...
@@ -297,4 +297,44 @@ CAF_TEST(basic and basic containers options) {
string_map
({{
"a"
,
"1"
},
{
"b"
,
"2"
},
{
"c"
,
"3"
}}));
string_map
({{
"a"
,
"1"
},
{
"b"
,
"2"
},
{
"c"
,
"3"
}}));
}
}
SCENARIO
(
"config files allow both nested and dot-separated values"
)
{
GIVEN
(
"the option my.answer.value"
)
{
config_option_adder
{
cfg
.
custom_options
(),
"my.answer"
}
.
add
<
int32_t
>
(
"first"
,
"the first answer"
)
.
add
<
int32_t
>
(
"second"
,
"the second answer"
);
std
::
vector
<
std
::
string
>
allowed_input_strings
{
"my { answer { first = 1, second = 2 } }"
,
"my.answer { first = 1, second = 2 }"
,
"my { answer.first = 1, answer.second = 2 }"
,
"my.answer.first = 1, my.answer.second = 2"
,
"my { answer { first = 1 }, answer.second = 2 }"
,
"my { answer.first = 1, answer { second = 2} }"
,
"my.answer.first = 1, my { answer { second = 2 } }"
,
};
auto
make_result
=
[]
{
settings
answer
;
answer
[
"first"
]
=
1
;
answer
[
"second"
]
=
2
;
settings
my
;
my
[
"answer"
]
=
std
::
move
(
answer
);
settings
result
;
result
[
"my"
]
=
std
::
move
(
my
);
return
result
;
};
auto
result
=
make_result
();
for
(
const
auto
&
input_string
:
allowed_input_strings
)
{
WHEN
(
"parsing the file input '"
<<
input_string
<<
"'"
)
{
std
::
istringstream
input
{
input_string
};
auto
err
=
cfg
.
parse
(
string_list
{},
input
);
THEN
(
"the actor system contains values for my.answer.(first|second)"
)
{
CHECK_EQ
(
err
,
error
{});
CHECK_EQ
(
get_or
(
cfg
,
"my.answer.first"
,
-
1
),
1
);
CHECK_EQ
(
get_or
(
cfg
,
"my.answer.second"
,
-
1
),
2
);
CHECK_EQ
(
content
(
cfg
),
result
);
}
}
}
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
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