Reworked evaluation to use internal type instead of boost::any
This commit is contained in:
65
src/Evaluator/EvalValues/NumericEvalValue.hpp
Normal file
65
src/Evaluator/EvalValues/NumericEvalValue.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
|
||||
#ifndef PORYGONLANG_NUMERICEVALVALUE_HPP
|
||||
#define PORYGONLANG_NUMERICEVALVALUE_HPP
|
||||
|
||||
#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);
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //PORYGONLANG_NUMERICEVALVALUE_HPP
|
||||
Reference in New Issue
Block a user