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