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{
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
virtual const long GetIntegerValue() const = 0;
|
|
|
|
virtual const double GetFloatValue() const = 0;
|
2019-05-24 17:14:30 +00:00
|
|
|
|
|
|
|
public:
|
2019-06-17 15:43:54 +00:00
|
|
|
virtual const bool IsFloat() const = 0;
|
2019-06-13 14:26:10 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const TypeClass GetTypeClass() const final{
|
2019-06-13 14:26:10 +00:00
|
|
|
return TypeClass ::Number;
|
2019-05-24 17:14:30 +00:00
|
|
|
}
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const shared_ptr<NumericEvalValue> operator +(const shared_ptr<NumericEvalValue>& b) const;
|
|
|
|
const shared_ptr<NumericEvalValue> operator -(const shared_ptr<NumericEvalValue>& b) const ;
|
|
|
|
const shared_ptr<NumericEvalValue> operator *(const shared_ptr<NumericEvalValue>& b) const ;
|
|
|
|
const shared_ptr<NumericEvalValue> operator /(const shared_ptr<NumericEvalValue>& b) const ;
|
|
|
|
const shared_ptr<BooleanEvalValue> operator <(const shared_ptr<NumericEvalValue>& b) const ;
|
|
|
|
const shared_ptr<BooleanEvalValue> operator <=(const shared_ptr<NumericEvalValue>& b)const ;
|
|
|
|
const shared_ptr<BooleanEvalValue> operator >(const shared_ptr<NumericEvalValue>& b) const ;
|
|
|
|
const shared_ptr<BooleanEvalValue> operator >=(const shared_ptr<NumericEvalValue>& b) const ;
|
|
|
|
const bool operator ==(EvalValue* b) const final;
|
2019-05-24 17:14:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IntegerEvalValue : public NumericEvalValue{
|
2019-06-17 15:43:54 +00:00
|
|
|
const long _value;
|
|
|
|
const long GetIntegerValue() const final{return _value;}
|
|
|
|
const double GetFloatValue() const final{ throw EvaluationException("Attempting to retrieve float from int eval value."); }
|
2019-05-24 17:14:30 +00:00
|
|
|
public:
|
2019-06-17 15:43:54 +00:00
|
|
|
explicit IntegerEvalValue(long value) :_value(value){
|
2019-05-24 17:14:30 +00:00
|
|
|
}
|
2019-06-17 15:43:54 +00:00
|
|
|
const bool IsFloat() const final{
|
2019-05-24 17:14:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const long EvaluateInteger() const final{
|
2019-05-24 17:14:30 +00:00
|
|
|
return _value;
|
|
|
|
}
|
2019-05-25 14:15:20 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const shared_ptr<EvalValue> Clone() const final{
|
2019-06-01 19:38:39 +00:00
|
|
|
return make_shared<IntegerEvalValue>(_value);
|
2019-05-30 13:23:48 +00:00
|
|
|
}
|
2019-06-09 18:15:09 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const std::size_t GetHashCode() const final{
|
2019-06-09 18:15:09 +00:00
|
|
|
return std::hash<long>{}(_value);
|
|
|
|
}
|
2019-05-24 17:14:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FloatEvalValue : public NumericEvalValue{
|
2019-06-17 15:43:54 +00:00
|
|
|
const double _value;
|
|
|
|
const long GetIntegerValue() const final{ throw EvaluationException("Attempting to retrieve float from int eval value."); }
|
|
|
|
const double GetFloatValue() const final{return _value;}
|
2019-05-24 17:14:30 +00:00
|
|
|
public:
|
2019-06-17 15:43:54 +00:00
|
|
|
explicit FloatEvalValue(double value) :_value(value){
|
2019-05-24 17:14:30 +00:00
|
|
|
}
|
2019-06-17 15:43:54 +00:00
|
|
|
const bool IsFloat() const final{
|
2019-05-24 17:14:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const double EvaluateFloat() const final{
|
2019-05-24 17:14:30 +00:00
|
|
|
return _value;
|
|
|
|
}
|
2019-05-25 14:15:20 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const shared_ptr<EvalValue> Clone() const final{
|
2019-06-01 19:38:39 +00:00
|
|
|
return make_shared<FloatEvalValue>(_value);
|
2019-05-30 13:23:48 +00:00
|
|
|
}
|
2019-06-09 18:15:09 +00:00
|
|
|
|
2019-06-17 15:43:54 +00:00
|
|
|
const std::size_t GetHashCode() const final{
|
2019-06-09 18:15:09 +00:00
|
|
|
return std::hash<double >{}(_value);
|
|
|
|
}
|
2019-05-24 17:14:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //PORYGONLANG_NUMERICEVALVALUE_HPP
|