#ifndef PORYGONLANG_STRINGEVALVALUE_HPP #define PORYGONLANG_STRINGEVALVALUE_HPP #include #include "EvalValue.hpp" #include "../../Utilities/HashedString.hpp" using namespace std; namespace Porygon::Evaluation { class StringEvalValue : public EvalValue { u16string _value; size_t _hash; public: explicit StringEvalValue(u16string s) { _value = move(s); _hash = Utilities::HashedString::ConstHash(_value.c_str()); } const TypeClass GetTypeClass() const final { return TypeClass::String; } const bool operator==(EvalValue *b) const final { if (b->GetTypeClass() != TypeClass::String) return false; return this->_hash == b->GetHashCode(); }; const u16string *EvaluateString() const final { return &_value; } const shared_ptr Clone() const final { return make_shared(_value); } const shared_ptr IndexValue(EvalValue *val) const final { // Porygon is 1-indexed, so we convert to that. auto l = val->EvaluateInteger() - 1; return make_shared(u16string(1, _value[l])); } const std::size_t GetHashCode() const final { return _hash; } }; } #endif //PORYGONLANG_STRINGEVALVALUE_HPP