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"
|
2019-06-23 13:58:14 +00:00
|
|
|
#include "../../Utilities/StringUtils.hpp"
|
|
|
|
|
2019-06-17 16:35:12 +00:00
|
|
|
namespace Porygon::Evaluation {
|
|
|
|
class NumericEvalValue : public EvalValue {
|
2019-05-24 17:14:30 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
virtual long GetIntegerValue() const = 0;
|
2019-06-17 16:35:12 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
virtual double GetFloatValue() const = 0;
|
2019-06-17 16:35:12 +00:00
|
|
|
|
|
|
|
public:
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
virtual bool IsFloat() const = 0;
|
2019-06-17 16:35:12 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
inline TypeClass GetTypeClass() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return TypeClass::Number;
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
shared_ptr<const NumericEvalValue> operator+(const shared_ptr<const NumericEvalValue> &b) const;
|
2019-06-17 16:35:12 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
shared_ptr<const NumericEvalValue> operator-(const shared_ptr<const NumericEvalValue> &b) const;
|
2019-06-17 16:35:12 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
shared_ptr<const NumericEvalValue> operator*(const shared_ptr<const NumericEvalValue> &b) const;
|
2019-06-17 16:35:12 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
shared_ptr<const NumericEvalValue> operator/(const shared_ptr<const NumericEvalValue> &b) const;
|
2019-06-17 16:35:12 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
shared_ptr<const BooleanEvalValue> operator<(const shared_ptr<const NumericEvalValue> &b) const;
|
2019-06-17 16:35:12 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
shared_ptr<const BooleanEvalValue> operator<=(const shared_ptr<const NumericEvalValue> &b) const;
|
2019-06-17 16:35:12 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
shared_ptr<const BooleanEvalValue> operator>(const shared_ptr<const NumericEvalValue> &b) const;
|
2019-06-17 16:35:12 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
shared_ptr<const BooleanEvalValue> operator>=(const shared_ptr<const NumericEvalValue> &b) const;
|
2019-06-17 16:35:12 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
bool operator==(const EvalValue *b) const final;
|
2019-06-17 16:35:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IntegerEvalValue : public NumericEvalValue {
|
|
|
|
const long _value;
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
long GetIntegerValue() const final { return _value; }
|
2019-06-17 16:35:12 +00:00
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
double GetFloatValue() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
throw EvaluationException("Attempting to retrieve float from int eval value.");
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit IntegerEvalValue(long value) : _value(value) {
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
inline bool IsFloat() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
inline long EvaluateInteger() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
inline std::u16string EvaluateString() const final{
|
2019-06-23 13:58:14 +00:00
|
|
|
return Utilities::StringUtils::IntToString(_value);
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
inline shared_ptr<const EvalValue> Clone() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return make_shared<IntegerEvalValue>(_value);
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
inline std::size_t GetHashCode() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return std::hash<long>{}(_value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class FloatEvalValue : public NumericEvalValue {
|
|
|
|
const double _value;
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
inline long GetIntegerValue() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
throw EvaluationException("Attempting to retrieve float from int eval value.");
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
inline double GetFloatValue() const final {
|
2019-07-04 17:08:13 +00:00
|
|
|
return _value;
|
|
|
|
}
|
2019-06-17 16:35:12 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit FloatEvalValue(double value) : _value(value) {
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
inline bool IsFloat() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
inline double EvaluateFloat() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return _value;
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
inline shared_ptr<const EvalValue> Clone() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return make_shared<FloatEvalValue>(_value);
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:23:54 +00:00
|
|
|
[[nodiscard]]
|
|
|
|
inline std::size_t GetHashCode() const final {
|
2019-06-17 16:35:12 +00:00
|
|
|
return std::hash<double>{}(_value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2019-05-24 17:14:30 +00:00
|
|
|
|
|
|
|
#endif //PORYGONLANG_NUMERICEVALVALUE_HPP
|