Commit 51f26230 authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Config: allow setting Matrices

parent 82b93bd4
......@@ -165,6 +165,13 @@ namespace corryvreckan {
// TODO [doc] Provide second template parameter to specify the vector type to return it in
template <typename T> void setArray(const std::string& key, const std::vector<T>& val);
/**
* @brief Set matrix of values for a key in a given type
* @param key Key to set values of
* @param val List of values to assign to the key
*/
template <typename T> void setMatrix(const std::string& key, const Matrix<T>& val);
/**
* @brief Set default value for a key only if it is not defined yet
* @param key Key to possible set value of
......
......@@ -154,6 +154,27 @@ namespace corryvreckan {
config_[key] = str;
}
template <typename T> void Configuration::setMatrix(const std::string& key, const Matrix<T>& val) {
// NOTE: not the most elegant way to support arrays
if(val.empty()) {
return;
}
std::string str = "[";
for(auto& col : val) {
str += "[";
for(auto& el : col) {
str += corryvreckan::to_string(el);
str += ",";
}
str.pop_back();
str += "],";
}
str.pop_back();
str += "]";
config_[key] = str;
}
template <typename T> void Configuration::setDefault(const std::string& key, const T& val) {
if(!has(key)) {
set<T>(key, val);
......
Markdown is supported
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