2019-05-24 17:14:30 +00:00
|
|
|
|
|
|
|
#ifndef PORYGONLANG_NUMERICEVALVALUE_HPP
|
|
|
|
#define PORYGONLANG_NUMERICEVALVALUE_HPP
|
|
|
|
|
2019-05-25 14:15:20 +00:00
|
|
|
#include <sstream>
|
2019-05-24 17:14:30 +00:00
|
|
|
#include "EvalValue.hpp"
|
|
|
|
|
|
|
|
class NumericEvalValue : public EvalValue{
|
|
|
|
|
|
|
|
virtual long GetIntegerValue() = 0;
|
|
|
|
virtual double GetFloatValue() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ScriptType* _type;
|
|
|
|
public:
|
|
|
|
~NumericEvalValue() override{
|
|
|
|
delete _type;
|
|
|
|
};
|
|
|
|
virtual const bool IsFloat() = 0;
|
|
|
|
ScriptType* GetType() override {
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
|
|
|
|
NumericEvalValue* operator +(NumericEvalValue* b);
|
|
|
|
NumericEvalValue* operator -(NumericEvalValue* b);
|
|
|
|
NumericEvalValue* operator *(NumericEvalValue* b);
|
|
|
|
NumericEvalValue* operator /(NumericEvalValue* b);
|
2019-05-25 11:57:43 +00:00
|
|
|
bool operator ==(EvalValue* b) final;
|
2019-05-24 17:14:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IntegerEvalValue : public NumericEvalValue{
|
|
|
|
long _value;
|
|
|
|
long GetIntegerValue() final{return _value;}
|
|
|
|
double GetFloatValue() final{ throw EvaluationException("Attempting to retrieve float from int eval value."); }
|
|
|
|
public:
|
|
|
|
explicit IntegerEvalValue(long value){
|
|
|
|
_type = new NumericScriptType(true, false);
|
|
|
|
_value = value;
|
|
|
|
}
|
|
|
|
const bool IsFloat() final{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
long EvaluateInteger() final{
|
|
|
|
return _value;
|
|
|
|
}
|
2019-05-25 14:15:20 +00:00
|
|
|
|
|
|
|
std::string EvaluateString() final{
|
|
|
|
std::ostringstream strs;
|
|
|
|
strs << _value;
|
|
|
|
return strs.str();
|
|
|
|
}
|
2019-05-24 17:14:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FloatEvalValue : public NumericEvalValue{
|
|
|
|
double _value;
|
|
|
|
long GetIntegerValue() final{ throw EvaluationException("Attempting to retrieve float from int eval value."); }
|
|
|
|
double GetFloatValue() final{return _value;}
|
|
|
|
public:
|
|
|
|
explicit FloatEvalValue(double value){
|
|
|
|
_type = new NumericScriptType(true, true);
|
|
|
|
_value = value;
|
|
|
|
}
|
|
|
|
const bool IsFloat() final{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
double EvaluateFloat() final{
|
|
|
|
return _value;
|
|
|
|
}
|
2019-05-25 14:15:20 +00:00
|
|
|
|
|
|
|
std::string EvaluateString() final{
|
|
|
|
std::ostringstream strs;
|
|
|
|
strs << _value;
|
|
|
|
return strs.str();
|
|
|
|
}
|
2019-05-24 17:14:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //PORYGONLANG_NUMERICEVALVALUE_HPP
|