#ifndef PORYGONLANG_NUMERICEVALVALUE_HPP #define PORYGONLANG_NUMERICEVALVALUE_HPP #include #include "EvalValue.hpp" #include "../../Utilities/StringUtils.hpp" namespace Porygon::Evaluation { class NumericEvalValue : public EvalValue { virtual const long GetIntegerValue() const = 0; virtual const double GetFloatValue() const = 0; public: virtual const bool IsFloat() const = 0; inline const TypeClass GetTypeClass() const final { return TypeClass::Number; } const shared_ptr operator+(const shared_ptr &b) const; const shared_ptr operator-(const shared_ptr &b) const; const shared_ptr operator*(const shared_ptr &b) const; const shared_ptr operator/(const shared_ptr &b) const; const shared_ptr operator<(const shared_ptr &b) const; const shared_ptr operator<=(const shared_ptr &b) const; const shared_ptr operator>(const shared_ptr &b) const; const shared_ptr operator>=(const shared_ptr &b) const; const bool operator==(EvalValue *b) const final; }; class IntegerEvalValue : public NumericEvalValue { 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."); } public: explicit IntegerEvalValue(long value) : _value(value) { } inline const bool IsFloat() const final { return false; } inline const long EvaluateInteger() const final { return _value; } inline const std::u16string EvaluateString() const final{ return Utilities::StringUtils::IntToString(_value); } inline const shared_ptr Clone() const final { return make_shared(_value); } inline const std::size_t GetHashCode() const final { return std::hash{}(_value); } }; class FloatEvalValue : public NumericEvalValue { const double _value; inline const long GetIntegerValue() const final { throw EvaluationException("Attempting to retrieve float from int eval value."); } inline const double GetFloatValue() const final { return _value; } public: explicit FloatEvalValue(double value) : _value(value) { } inline const bool IsFloat() const final { return true; } inline const double EvaluateFloat() const final { return _value; } inline const shared_ptr Clone() const final { return make_shared(_value); } inline const std::size_t GetHashCode() const final { return std::hash{}(_value); } }; } #endif //PORYGONLANG_NUMERICEVALVALUE_HPP