PorygonLang/src/Evaluator/EvalValues/NumericEvalValue.hpp

73 lines
1.9 KiB
C++
Raw Normal View History

#ifndef PORYGONLANG_NUMERICEVALVALUE_HPP
#define PORYGONLANG_NUMERICEVALVALUE_HPP
#include <sstream>
#include "EvalValue.hpp"
class NumericEvalValue : public EvalValue{
virtual long GetIntegerValue() = 0;
virtual double GetFloatValue() = 0;
protected:
std::shared_ptr<ScriptType> _type;
public:
virtual const bool IsFloat() = 0;
std::shared_ptr<ScriptType> GetType() override {
return _type;
}
NumericEvalValue* operator +(NumericEvalValue* b);
NumericEvalValue* operator -(NumericEvalValue* b);
NumericEvalValue* operator *(NumericEvalValue* b);
NumericEvalValue* operator /(NumericEvalValue* b);
bool operator ==(EvalValue* b) final;
};
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 = std::make_shared<NumericScriptType>(true, false);
_value = value;
}
const bool IsFloat() final{
return false;
}
long EvaluateInteger() final{
return _value;
}
shared_ptr<EvalValue> Clone() final{
return make_shared<IntegerEvalValue>(_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 = std::make_shared<NumericScriptType>(true, true);
_value = value;
}
const bool IsFloat() final{
return true;
}
double EvaluateFloat() final{
return _value;
}
shared_ptr<EvalValue> Clone() final{
return make_shared<FloatEvalValue>(_value);
}
};
#endif //PORYGONLANG_NUMERICEVALVALUE_HPP