Commit 995c5bfc authored by Romain Feron's avatar Romain Feron
Browse files

Handle spaces in string type parameter values

parent 9fe76b5b
#include "parameters.h"
/* The function "get_value_from_name" requires template specialization.
* Strings are converted to the specified type using stringstreams, which are "cut" by spaces.
* The below function specializes the function for values of type "string" in order to handle strings containing spaces
*/
template<>
std::string Parameters::get_value_from_name<std::string>(const std::string& name) {
for (auto p: this->list) {
if (p.name == name) {
return p.value;
}
}
std::cout << " ** Error: looking for the value of parameter \"" << name <<"\" which does not exist." << std::endl;
exit(0);
}
......@@ -84,7 +84,7 @@ struct Parameters {
// Get the value of a parameter from its name
template<typename T>
T get_value_from_name(std::string& name) {
T get_value_from_name(const std::string& name) {
T output;
for (auto p: this->list) {
if (p.name == name) {
......@@ -180,3 +180,7 @@ struct Parameters {
std::cout << "\n";
}
};
// Template specialization for converting string in order to handle spaces in strings
template<>
std::string Parameters::get_value_from_name<std::string>(const std::string& name);
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