Reworked evaluation to use internal type instead of boost::any

This commit is contained in:
2019-05-24 19:14:30 +02:00
parent fed4c65bef
commit 4a034bc051
10 changed files with 197 additions and 132 deletions

View File

@@ -0,0 +1,50 @@
#include "NumericEvalValue.hpp"
NumericEvalValue *NumericEvalValue::operator+(NumericEvalValue *b) {
if (this->IsFloat() && b->IsFloat()){
return new FloatEvalValue(this->GetFloatValue() + b->GetFloatValue());
} else if (this->IsFloat()){
return new FloatEvalValue(this->GetFloatValue() + b->GetIntegerValue());
} else if (b->IsFloat()){
return new FloatEvalValue(this->GetIntegerValue() + b->GetFloatValue());
} else{
return new IntegerEvalValue(this->GetIntegerValue() + b->GetIntegerValue());
}
}
NumericEvalValue *NumericEvalValue::operator-(NumericEvalValue *b) {
if (this->IsFloat() && b->IsFloat()){
return new FloatEvalValue(this->GetFloatValue() - b->GetFloatValue());
} else if (this->IsFloat()){
return new FloatEvalValue(this->GetFloatValue() - b->GetIntegerValue());
} else if (b->IsFloat()){
return new FloatEvalValue(this->GetIntegerValue() - b->GetFloatValue());
} else{
return new IntegerEvalValue(this->GetIntegerValue() - b->GetIntegerValue());
}
}
NumericEvalValue *NumericEvalValue::operator*(NumericEvalValue *b) {
if (this->IsFloat() && b->IsFloat()){
return new FloatEvalValue(this->GetFloatValue() * b->GetFloatValue());
} else if (this->IsFloat()){
return new FloatEvalValue(this->GetFloatValue() * b->GetIntegerValue());
} else if (b->IsFloat()){
return new FloatEvalValue(this->GetIntegerValue() * b->GetFloatValue());
} else{
return new IntegerEvalValue(this->GetIntegerValue() * b->GetIntegerValue());
}
}
NumericEvalValue *NumericEvalValue::operator/(NumericEvalValue *b) {
if (this->IsFloat() && b->IsFloat()){
return new FloatEvalValue(this->GetFloatValue() / b->GetFloatValue());
} else if (this->IsFloat()){
return new FloatEvalValue(this->GetFloatValue() / b->GetIntegerValue());
} else if (b->IsFloat()){
return new FloatEvalValue(this->GetIntegerValue() / b->GetFloatValue());
} else{
return new IntegerEvalValue(this->GetIntegerValue() / b->GetIntegerValue());
}
}