Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Corryvreckan
Corryvreckan
Commits
4066445f
Commit
4066445f
authored
Jun 28, 2018
by
Simon Spannagel
Browse files
Configuration: allow setting keys with units
parent
0d54e082
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/core/config/Configuration.hpp
View file @
4066445f
...
...
@@ -142,12 +142,21 @@ namespace corryvreckan {
// TODO [doc] Provide second template parameter to specify the vector type to return it in
std
::
vector
<
std
::
string
>
getPathArray
(
const
std
::
string
&
key
,
bool
check_exists
=
false
)
const
;
/**
* @brief Set value for a key in a given type with units
* @param key Key to set value of
* @param val Value to assign to the key
* @param units List of possible output units
*/
template
<
typename
T
>
void
set
(
const
std
::
string
&
key
,
const
T
&
val
,
std
::
initializer_list
<
std
::
string
>
units
);
/**
* @brief Set value for a key in a given type
* @param key Key to set value of
* @param val Value to assign to the key
*/
template
<
typename
T
>
void
set
(
const
std
::
string
&
key
,
const
T
&
val
);
/**
* @brief Set list of values for a key in a given type
* @param key Key to set values of
...
...
src/core/config/Configuration.tpp
View file @
4066445f
...
...
@@ -129,6 +129,20 @@ namespace corryvreckan {
template
<
typename
T
>
void
Configuration
::
set
(
const
std
::
string
&
key
,
const
T
&
val
)
{
config_
[
key
]
=
corryvreckan
::
to_string
(
val
);
}
template
<
typename
T
>
void
Configuration
::
set
(
const
std
::
string
&
key
,
const
T
&
val
,
std
::
initializer_list
<
std
::
string
>
units
)
{
auto
split
=
corryvreckan
::
split
<
Units
::
UnitType
>
(
corryvreckan
::
to_string
(
val
));
std
::
string
ret_str
;
for
(
auto
&
element
:
split
)
{
ret_str
+=
Units
::
display
(
element
,
units
);
ret_str
+=
","
;
}
ret_str
.
pop_back
();
config_
[
key
]
=
ret_str
;
}
template
<
typename
T
>
void
Configuration
::
setArray
(
const
std
::
string
&
key
,
const
std
::
vector
<
T
>&
val
)
{
// NOTE: not the most elegant way to support arrays
std
::
string
str
;
...
...
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