Commit 4066445f authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Configuration: allow setting keys with units

parent 0d54e082
......@@ -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
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment