Skip to content
Snippets Groups Projects

Resolve "int and unsigned int parameters warnings"

Merged Joan Vallvé Navarro requested to merge 392-int-and-unsigned-int-parameters-warnings into devel
5 files
+ 105
22
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -17,6 +17,7 @@
#include <vector>
#include <stack>
#include <list>
#include <math.h>
/**
@file
@@ -96,13 +97,21 @@ struct converter<utils::list<A>>{
template<>
struct converter<int>{
static int convert(std::string val){
return stod(val);
double res;
if (modf(stod(val),&res) > 0)
throw std::runtime_error("Invalid conversion to int: The number contains decimals: " + val);
return res;
}
};
template<>
struct converter<unsigned int>{
static unsigned int convert(std::string val){
return stod(val);
double res;
if (modf(stod(val),&res) > 0)
throw std::runtime_error("Invalid conversion to unsigned int: The number contains decimals: " + val);
if (res < 0)
throw std::runtime_error("Invalid conversion to unsigned int: The number is negative: " + val);
return res;
}
};
template<>
@@ -114,8 +123,8 @@ struct converter<double>{
template<>
struct converter<bool>{
static bool convert(std::string val){
if(val == "true") return true;
else if (val == "false") return false;
if(val == "true" or val=="True" or val=="TRUE") return true;
else if (val == "false" or val=="False" or val=="FALSE") return false;
else throw std::runtime_error("Invalid conversion to bool (Must be either \"true\" or \"false\"). String provided: " + val);
}
};
Loading