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
0fbe9d15
Commit
0fbe9d15
authored
Jan 17, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix put overload resolution and return type
parent
ddbdc9c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
19 deletions
+21
-19
libcaf_core/caf/settings.hpp
libcaf_core/caf/settings.hpp
+8
-8
libcaf_core/src/settings.cpp
libcaf_core/src/settings.cpp
+13
-11
No files found.
libcaf_core/caf/settings.hpp
View file @
0fbe9d15
...
@@ -62,8 +62,9 @@ T get(const settings& xs, string_view name) {
...
@@ -62,8 +62,9 @@ T get(const settings& xs, string_view name) {
return
std
::
move
(
*
result
);
return
std
::
move
(
*
result
);
}
}
template
<
class
T
,
template
<
class
T
,
class
=
typename
std
::
enable_if
<
class
=
typename
std
::
enable_if
<!
std
::
is_pointer
<
T
>
::
value
>::
type
>
!
std
::
is_pointer
<
T
>
::
value
&&
!
std
::
is_convertible
<
T
,
string_view
>::
value
>::
type
>
T
get_or
(
const
settings
&
xs
,
string_view
name
,
T
default_value
)
{
T
get_or
(
const
settings
&
xs
,
string_view
name
,
T
default_value
)
{
auto
result
=
get_if
<
T
>
(
&
xs
,
name
);
auto
result
=
get_if
<
T
>
(
&
xs
,
name
);
if
(
result
)
if
(
result
)
...
@@ -75,21 +76,20 @@ std::string get_or(const settings& xs, string_view name,
...
@@ -75,21 +76,20 @@ std::string get_or(const settings& xs, string_view name,
string_view
default_value
);
string_view
default_value
);
/// @private
/// @private
void
put_impl
(
settings
&
dict
,
const
std
::
vector
<
string_view
>&
path
,
config_value
&
put_impl
(
settings
&
dict
,
const
std
::
vector
<
string_view
>&
path
,
config_value
&
value
);
config_value
&
value
);
/// @private
/// @private
void
put_impl
(
settings
&
dict
,
string_view
key
,
config_value
&
put_impl
(
settings
&
dict
,
string_view
key
,
config_value
&
value
);
config_value
&
value
);
/// Converts `value` to a `config_value` and assigns it to `key`.
/// Converts `value` to a `config_value` and assigns it to `key`.
/// @param dict Dictionary of key-value pairs.
/// @param dict Dictionary of key-value pairs.
/// @param key Human-readable nested keys in the form `category.key`.
/// @param key Human-readable nested keys in the form `category.key`.
/// @param value New value for given `key`.
/// @param value New value for given `key`.
template
<
class
T
>
template
<
class
T
>
void
put
(
settings
&
dict
,
string_view
key
,
T
&&
value
)
{
config_value
&
put
(
settings
&
dict
,
string_view
key
,
T
&&
value
)
{
config_value
tmp
{
std
::
forward
<
T
>
(
value
)};
config_value
tmp
{
std
::
forward
<
T
>
(
value
)};
put_impl
(
dict
,
key
,
tmp
);
return
put_impl
(
dict
,
key
,
tmp
);
}
}
/// Inserts a new list named `name` into the dictionary `xs` and returns
/// Inserts a new list named `name` into the dictionary `xs` and returns
...
...
libcaf_core/src/settings.cpp
View file @
0fbe9d15
...
@@ -28,11 +28,10 @@ std::string get_or(const settings& xs, string_view name,
...
@@ -28,11 +28,10 @@ std::string get_or(const settings& xs, string_view name,
return
std
::
string
{
default_value
.
begin
(),
default_value
.
end
()};
return
std
::
string
{
default_value
.
begin
(),
default_value
.
end
()};
}
}
void
put_impl
(
settings
&
dict
,
const
std
::
vector
<
string_view
>&
path
,
config_value
&
put_impl
(
settings
&
dict
,
const
std
::
vector
<
string_view
>&
path
,
config_value
&
value
)
{
config_value
&
value
)
{
// Sanity check.
// Sanity check.
if
(
path
.
empty
())
CAF_ASSERT
(
!
path
.
empty
());
return
;
// Navigate path.
// Navigate path.
auto
last
=
path
.
end
();
auto
last
=
path
.
end
();
auto
back
=
last
-
1
;
auto
back
=
last
-
1
;
...
@@ -49,23 +48,26 @@ void put_impl(settings& dict, const std::vector<string_view>& path,
...
@@ -49,23 +48,26 @@ void put_impl(settings& dict, const std::vector<string_view>& path,
}
}
}
}
// Set key-value pair on the leaf.
// Set key-value pair on the leaf.
current
->
insert_or_assign
(
*
back
,
std
::
move
(
value
));
auto
iter
=
current
->
insert_or_assign
(
*
back
,
std
::
move
(
value
)).
first
;
return
iter
->
second
;
}
}
void
put_impl
(
settings
&
dict
,
string_view
key
,
config_value
&
value
)
{
config_value
&
put_impl
(
settings
&
dict
,
string_view
key
,
config_value
&
value
)
{
std
::
vector
<
string_view
>
path
;
std
::
vector
<
string_view
>
path
;
split
(
path
,
key
,
"."
);
split
(
path
,
key
,
"."
);
put_impl
(
dict
,
path
,
value
);
return
put_impl
(
dict
,
path
,
value
);
}
}
config_value
::
list
&
put_list
(
settings
&
xs
,
std
::
string
name
)
{
config_value
::
list
&
put_list
(
settings
&
xs
,
std
::
string
name
)
{
auto
i
=
xs
.
insert_or_assign
(
std
::
move
(
name
),
config_value
::
list
{});
config_value
tmp
{
config_value
::
list
{}};
return
get
<
config_value
::
list
>
(
i
.
first
->
second
);
auto
&
result
=
put_impl
(
xs
,
name
,
tmp
);
return
get
<
config_value
::
list
>
(
result
);
}
}
config_value
::
dictionary
&
put_dictionary
(
settings
&
xs
,
std
::
string
name
)
{
config_value
::
dictionary
&
put_dictionary
(
settings
&
xs
,
std
::
string
name
)
{
auto
i
=
xs
.
insert_or_assign
(
std
::
move
(
name
),
settings
{});
config_value
tmp
{
settings
{}};
return
get
<
config_value
::
dictionary
>
(
i
.
first
->
second
);
auto
&
result
=
put_impl
(
xs
,
name
,
tmp
);
return
get
<
config_value
::
dictionary
>
(
result
);
}
}
}
// namespace caf
}
// namespace caf
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