Commit a7294544 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

added optional brackets in config file for vectors

parent d8e8e0c6
......@@ -59,8 +59,9 @@ double Config::parse<double>(const std::string &value) const {
template<>
vector<int> Config::parse<vector<int>>(const std::string &value) const {
string new_value = removeBrackets(value);
vector<int> out;
for (const string &element : split(value, ",")) {
for (const string &element : split(new_value, ",")) {
if (!element.empty()) {
out.push_back(stoi(element));
}
......@@ -70,8 +71,9 @@ vector<int> Config::parse<vector<int>>(const std::string &value) const {
template<>
vector<double> Config::parse<vector<double>>(const std::string &value) const {
string new_value = removeBrackets(value);
vector<double> out;
for (const string &element : split(value, ",")) {
for (const string &element : split(new_value, ",")) {
if (!element.empty()) {
out.push_back(stod(element));
}
......@@ -79,6 +81,15 @@ vector<double> Config::parse<vector<double>>(const std::string &value) const {
return out;
}
string Config::removeBrackets(const string &value) const {
char brackets[] = "[](){}";
string new_value = value;
for (auto &bracket: brackets)
new_value.erase(remove(new_value.begin(), new_value.end(), bracket),
new_value.end());
return new_value;
}
void Config::setLogging(Logging *logging) {
Config::logging = logging;
}
......
......@@ -62,6 +62,8 @@ private:
static Config fromFile(int *argc, char **argv);
string removeBrackets(const string &value) const;
public:
......@@ -89,9 +91,9 @@ public:
bool get(const string &key, T &out) {
if (config.find(key) == config.end()) {
if(printedKeys.count(key) == 0 || (verbose > 4)){
if (printedKeys.count(key) == 0 || (verbose > 4)) {
confout(2) << "reading default: " << key
<< std::string(40 - key.length(), '.') << " " << out << "\n";
<< std::string(40 - key.length(), '.') << " " << out << "\n";
printedKeys.emplace(key);
}
return false;
......@@ -103,7 +105,7 @@ public:
template<typename T>
T get(const std::string &key) {
ConfigEntry ce = config.at(key);
if (printedKeys.count(key) == 0 || (verbose > 4)) {
if (printedKeys.count(key) == 0 || (verbose > 4)) {
confout(2) << "reading config: " << key
<< std::string(40 - key.length(), '.') << " " << ce.value << "\n";
printedKeys.emplace(key);
......@@ -129,7 +131,7 @@ public:
static string getConfigFilePath();
static void setDataPath(const std::string&);
static void setDataPath(const std::string &);
static string getDataPath();
};
......
......@@ -69,7 +69,8 @@ INSTANTIATE_TEST_SUITE_P(ConfigTest, ConfigTestVectorDouble, Values(
ConfigTestParam<vector<double>>{"myVector1", "1.05,-1.00003,1334.5", vector<double>{1.05, -1.00003, 1334.5}},
ConfigTestParam<vector<double>>{"myVector2", "1,2,3,4", vector<double>{1, 2, 3, 4}},
ConfigTestParam<vector<double>>{"myVector3", "-1,-2222", vector<double>{-1, -2222}},
ConfigTestParam<vector<double>>{"myVector4", "1.000043,456786.34534", vector<double>{1.000043, 456786.34534}}
ConfigTestParam<vector<double>>{"myVector4", "1.000043,456786.34534", vector<double>{1.000043, 456786.34534}},
ConfigTestParam<vector<double>>{"myVector5", "[1.000043, 456786.34534]", vector<double>{1.000043, 456786.34534}}
));
class ConfigTestVectorInt: public ConfigTest<vector<int>> {
......@@ -91,8 +92,10 @@ INSTANTIATE_TEST_SUITE_P(ConfigTest, ConfigTestVectorInt, Values(
ConfigTestParam<vector<int>>{"myVector5", ", ,1, ,,2, ,,3,4, , ,, ", vector<int>{1, 2, 3, 4}},
ConfigTestParam<vector<int>>{"myVector6", "-1,-2,-3,-4", vector<int>{-1, -2, -3, -4}},
ConfigTestParam<vector<int>>{"myVector7", "1,-1,2,-2,3,-3", vector<int>{1, -1, 2, -2, 3, -3}},
ConfigTestParam<vector<int>>{"myVector8", "34622457,42437257,-24652577", vector<int>{34622457, 42437257, -24652577}}
));
ConfigTestParam<vector<int>>{"myVector8", "34622457,42437257,-24652577", vector<int>{34622457, 42437257, -24652577}},
ConfigTestParam<vector<int>>{"myVector8", "[3,4,5]", vector<int>{3, 4, 5}}
));
class ConfigTestDouble: public ConfigTest<double> {
public:
......
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