Commit 132e80c8 authored by Johnny Jazeix's avatar Johnny Jazeix

Correction de bugues?

parent 2de68443
......@@ -94,5 +94,6 @@ SOURCES += main.cpp \
trace/values/Hex.cpp \
trace/values/Integer.cpp \
trace/values/Name.cpp \
trace/values/Value.cpp \
trace/values/String.cpp
RESOURCES += interface/vite.qrc
......@@ -25,12 +25,12 @@ bool Color::instantiate(std::string &in, Color &out) {
// Dots instead of commas or the contrary
bool commas_first = false;
if(replace_in_string(in, ',', '.')){
if(Value::replace_in_string(in, ',', '.')){
commas_first = true;
}
if(!commas_first){ // We had dots initially, we need to change them in commas
replace_in_string(in, '.', ',');
Value::replace_in_string(in, '.', ',');
}
if(sscanf(in.c_str(), "%lf %lf %lf", &r, &g, &b) != 3){
......@@ -48,20 +48,6 @@ std::string Color::to_string() const {
return oss.str();
}
bool Color::replace_in_string(std::string &characters, char to_replace, char replace_by) {
bool has_change = false;
const int lenght = characters.size();
for(int i = 0 ; i < lenght ; i ++){
if(characters[i] == to_replace){
characters[i] = replace_by;
has_change = true;
}
}
return has_change;
}
double Color::get_red() const {
return _r;
}
......
......@@ -83,19 +83,6 @@ public:
*/
double get_blue() const;
private:
/*!
*
* \fn replace_in_string(std::string &characters, char to_replace, char replace_by)
* \brief Replace in the string the character to_replace by replace_by.
* \param characters string to be replaced.
* \param to_replace the character we want to replace.
* \param replace_by the character we use to replace the first one.
* \return true if there was a change.
*
*/
static bool replace_in_string(std::string &characters, char to_replace, char replace_by);
};
#endif // COLOR_HPP
......@@ -12,12 +12,30 @@ Date::Date(double value){
bool Date::instantiate(std::string &in, Date &out){
double value = 0.0;
if(sscanf(in.c_str(), "%lf", &value) == 1){
out = Date(value);
return true;
}
// The error could occur because this is not the good format for decimal.
// Dots instead of commas or the contrary
bool commas_first = false;
if(Value::replace_in_string(in, ',', '.')){
commas_first = true;
}
if(!commas_first){ // We had dots initially, we need to change them in commas
Value::replace_in_string(in, '.', ',');
}
if(sscanf(in.c_str(), "%lf", &value) != 1){
return false;
}
out = Date(value);
return true;
else{
out = Date(value);
return true;
}
}
std::string Date::to_string() const{
......
......@@ -9,13 +9,32 @@ Double::Double(double value){
_value = value;
}
bool Double::instantiate(const std::string &in, Double &out){
bool Double::instantiate(std::string &in, Double &out){
double value = 0.0;
if(sscanf(in.c_str(), "%lf", &value) == 1){
out = Double(value);
return true;
}
// The error could occur because this is not the good format for decimal.
// Dots instead of commas or the contrary
bool commas_first = false;
if(Value::replace_in_string(in, ',', '.')){
commas_first = true;
}
if(!commas_first){ // We had dots initially, we need to change them in commas
Value::replace_in_string(in, '.', ',');
}
if(sscanf(in.c_str(), "%lf", &value) != 1){
return false;
};
out = Double(value);
return true;
}
else{
out = Double(value);
return true;
}
}
std::string Double::to_string() const{
......
......@@ -44,7 +44,7 @@ public:
* \return true, if the conversion succeeded
*
*/
static bool instantiate(const std::string &in, Double &out);
static bool instantiate(std::string &in, Double &out);
/*!
*
......
#include "Value.hpp"
bool Value::replace_in_string(std::string &characters, char to_replace, char replace_by){
bool has_change = false;
const int lenght = characters.size();
for(int i = 0 ; i < lenght ; i ++){
if(characters[i] == to_replace){
characters[i] = replace_by;
has_change = true;
}
}
return has_change;
}
......@@ -25,6 +25,7 @@
class Value {
public:
virtual ~Value(){};
/*!
*
* \fn to_string() const = 0
......@@ -33,9 +34,22 @@ public:
*
*/
static const int _PRECISION = 15;
virtual std::string to_string() const = 0;
virtual ~Value(){};
static const int _PRECISION = 15;
/*!
*
* \fn replace_in_string(std::string &characters, char to_replace, char replace_by)
* \brief Replace in the string the character to_replace by replace_by.
* \param characters string to be replaced.
* \param to_replace the character we want to replace.
* \param replace_by the character we use to replace the first one.
* \return true if there was a change.
*
*/
static bool replace_in_string(std::string &characters, char to_replace, char replace_by);
};
#endif // VALUE_HPP
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