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
a4d0e2ef
Commit
a4d0e2ef
authored
Jan 17, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Drop the implicit global category
parent
bff39e81
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
20 deletions
+33
-20
libcaf_core/src/actor_system_config.cpp
libcaf_core/src/actor_system_config.cpp
+3
-1
libcaf_core/src/config_option_set.cpp
libcaf_core/src/config_option_set.cpp
+4
-6
libcaf_core/src/ini_consumer.cpp
libcaf_core/src/ini_consumer.cpp
+11
-6
libcaf_core/src/settings.cpp
libcaf_core/src/settings.cpp
+8
-0
libcaf_core/test/config_option_set.cpp
libcaf_core/test/config_option_set.cpp
+4
-4
libcaf_core/test/ini_consumer.cpp
libcaf_core/test/ini_consumer.cpp
+3
-3
No files found.
libcaf_core/src/actor_system_config.cpp
View file @
a4d0e2ef
...
...
@@ -302,7 +302,9 @@ actor_system_config& actor_system_config::set_impl(string_view name,
auto
opt
=
custom_options_
.
qualified_name_lookup
(
name
);
if
(
opt
!=
nullptr
&&
opt
->
check
(
value
)
==
none
)
{
opt
->
store
(
value
);
auto
&
dict
=
content
[
opt
->
category
()].
as_dictionary
();
auto
category
=
opt
->
category
();
auto
&
dict
=
category
==
"global"
?
content
:
content
[
category
].
as_dictionary
();
dict
[
opt
->
long_name
()]
=
std
::
move
(
value
);
}
return
*
this
;
...
...
libcaf_core/src/config_option_set.cpp
View file @
a4d0e2ef
...
...
@@ -124,17 +124,15 @@ auto config_option_set::parse(settings& config, argument_iterator first,
auto
opt_name
=
opt
.
long_name
();
auto
opt_ctg
=
opt
.
category
();
// Try inserting a new submap into the config or fill existing one.
auto
&
entry
=
config
[
opt_ctg
];
if
(
!
holds_alternative
<
config_value
::
dictionary
>
(
entry
))
entry
=
config_value
::
dictionary
{};
auto
&
submap
=
get
<
config_value
::
dictionary
>
(
entry
);
auto
&
entry
=
opt_ctg
==
"global"
?
config
:
config
[
opt_ctg
].
as_dictionary
();
// Flags only consume the current element.
if
(
opt
.
is_flag
())
{
if
(
arg_begin
!=
arg_end
)
return
pec
::
illegal_argument
;
config_value
cfg_true
{
true
};
opt
.
store
(
cfg_true
);
submap
[
opt_name
]
=
cfg_true
;
entry
[
opt_name
]
=
cfg_true
;
}
else
{
if
(
arg_begin
==
arg_end
)
return
pec
::
missing_argument
;
...
...
@@ -158,7 +156,7 @@ auto config_option_set::parse(settings& config, argument_iterator first,
}
}
opt
.
store
(
*
val
);
submap
[
opt_name
]
=
std
::
move
(
*
val
);
entry
[
opt_name
]
=
std
::
move
(
*
val
);
}
return
pec
::
success
;
};
...
...
libcaf_core/src/ini_consumer.cpp
View file @
a4d0e2ef
...
...
@@ -170,13 +170,18 @@ void ini_consumer::key(std::string name) {
void
ini_consumer
::
value_impl
(
config_value
&&
x
)
{
using
dict_type
=
config_value
::
dictionary
;
auto
dict
=
get_if
<
dict_type
>
(
&
x
);
auto
&
dst
=
cfg_
.
emplace
(
current_key
,
dict_type
{}).
first
->
second
;
if
(
dict
!=
nullptr
&&
!
dict
->
empty
()
&&
holds_alternative
<
dict_type
>
(
dst
))
{
auto
&
dst_dict
=
get
<
dict_type
>
(
dst
);
// We need to "merge" values into the destination, because it can already
// contain any number of unrelated entries.
if
(
current_key
!=
"global"
)
{
auto
&
dst
=
cfg_
.
emplace
(
current_key
,
dict_type
{}).
first
->
second
;
if
(
dict
!=
nullptr
&&
!
dict
->
empty
()
&&
holds_alternative
<
dict_type
>
(
dst
))
{
auto
&
dst_dict
=
get
<
dict_type
>
(
dst
);
// We need to "merge" values into the destination, because it can already
// contain any number of unrelated entries.
for
(
auto
&
entry
:
*
dict
)
dst_dict
.
insert_or_assign
(
entry
.
first
,
std
::
move
(
entry
.
second
));
}
}
else
{
for
(
auto
&
entry
:
*
dict
)
dst_dict
.
insert_or_assign
(
entry
.
first
,
std
::
move
(
entry
.
second
));
cfg_
.
insert_or_assign
(
entry
.
first
,
std
::
move
(
entry
.
second
));
}
}
...
...
libcaf_core/src/settings.cpp
View file @
a4d0e2ef
...
...
@@ -18,6 +18,8 @@
#include "caf/settings.hpp"
#include "caf/string_algorithms.hpp"
namespace
caf
{
std
::
string
get_or
(
const
settings
&
xs
,
string_view
name
,
...
...
@@ -32,6 +34,12 @@ config_value& put_impl(settings& dict, const std::vector<string_view>& path,
config_value
&
value
)
{
// Sanity check.
CAF_ASSERT
(
!
path
.
empty
());
// TODO: We implicitly swallow the `global.` suffix as a hotfix, but we
// actually should drop `global.` on the upper layers.
if
(
path
.
front
()
==
"global"
)
{
std
::
vector
<
string_view
>
new_path
{
path
.
begin
()
+
1
,
path
.
end
()};
return
put_impl
(
dict
,
new_path
,
value
);
}
// Navigate path.
auto
last
=
path
.
end
();
auto
back
=
last
-
1
;
...
...
libcaf_core/test/config_option_set.cpp
View file @
a4d0e2ef
...
...
@@ -101,18 +101,18 @@ CAF_TEST(parse with ref syncing) {
CAF_CHECK_EQUAL
(
get
<
int
>
(
cfg
,
"foo.i"
),
42
);
}
CAF_TEST
(
implicit
global
)
{
CAF_TEST
(
drop
global
)
{
opts
.
add
<
int
>
(
"value"
,
"some value"
).
add
<
bool
>
(
"help"
,
"print help text"
);
CAF_MESSAGE
(
"test long option with argument"
);
settings
cfg
;
auto
res
=
opts
.
parse
(
cfg
,
{
"--value=42"
});
CAF_CHECK_EQUAL
(
res
.
first
,
pec
::
success
);
CAF_CHECK_EQUAL
(
get_if
<
int
>
(
&
cfg
,
"
global.
value"
),
42
);
CAF_CHECK_EQUAL
(
get_if
<
int
>
(
&
cfg
,
"value"
),
42
);
CAF_MESSAGE
(
"test long option flag"
);
cfg
.
clear
();
res
=
opts
.
parse
(
cfg
,
{
"--help"
});
CAF_CHECK_EQUAL
(
res
.
first
,
pec
::
success
);
CAF_CHECK_EQUAL
(
get_or
(
cfg
,
"
global.
help"
,
false
),
true
);
CAF_CHECK_EQUAL
(
get_or
(
cfg
,
"help"
,
false
),
true
);
}
CAF_TEST
(
atom
parameters
)
{
...
...
@@ -123,7 +123,7 @@ CAF_TEST(atom parameters) {
auto
res
=
opts
.
parse
(
cfg
,
std
::
move
(
args
));
if
(
res
.
first
!=
pec
::
success
)
return
res
.
first
;
auto
atm
=
get_if
<
atom_value
>
(
&
cfg
,
"
global.
value"
);
auto
atm
=
get_if
<
atom_value
>
(
&
cfg
,
"value"
);
if
(
atm
==
none
)
return
sec
::
invalid_argument
;
return
*
atm
;
...
...
libcaf_core/test/ini_consumer.cpp
View file @
a4d0e2ef
...
...
@@ -82,9 +82,9 @@ CAF_TEST(ini_consumer) {
res
.
e
=
str
.
end
();
detail
::
parser
::
read_ini
(
res
,
consumer
);
CAF_CHECK_EQUAL
(
res
.
code
,
pec
::
success
);
CAF_CHECK_EQUAL
(
get
<
bool
>
(
config
,
"
global.
is_server"
),
true
);
CAF_CHECK_EQUAL
(
get
<
uint16_t
>
(
config
,
"
global.
port"
),
4242u
);
CAF_CHECK_EQUAL
(
get
<
ls
>
(
config
,
"
global.
nodes"
),
ls
({
"sun"
,
"venus"
}));
CAF_CHECK_EQUAL
(
get
<
bool
>
(
config
,
"is_server"
),
true
);
CAF_CHECK_EQUAL
(
get
<
uint16_t
>
(
config
,
"port"
),
4242u
);
CAF_CHECK_EQUAL
(
get
<
ls
>
(
config
,
"nodes"
),
ls
({
"sun"
,
"venus"
}));
CAF_CHECK_EQUAL
(
get
<
string
>
(
config
,
"logger.file-name"
),
"foobar.ini"
);
CAF_CHECK_EQUAL
(
get
<
timespan
>
(
config
,
"scheduler.timing"
),
timespan
(
2000
));
CAF_CHECK_EQUAL
(
get
<
atom_value
>
(
config
,
"scheduler.impl"
),
atom
(
"foo"
));
...
...
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