Files
PorygonLang/src/Evaluator/EvalValues/StringEvalValue.hpp
Deukhoofd c022c91777
All checks were successful
continuous-integration/drone/push Build is passing
Implements complex tables
2019-06-12 15:19:28 +02:00

52 lines
1.3 KiB
C++

#ifndef PORYGONLANG_STRINGEVALVALUE_HPP
#define PORYGONLANG_STRINGEVALVALUE_HPP
#include <string>
#include "EvalValue.hpp"
#include "../../Utilities/HashedString.hpp"
using namespace std;
class StringEvalValue : public EvalValue{
string _value;
size_t _hash;
std::shared_ptr<ScriptType> _type;
public:
explicit StringEvalValue(string s){
_value = move(s);
_hash = HashedString::ConstHash (_value.c_str());
_type = std::make_shared<StringScriptType>(true, _hash);
}
std::shared_ptr<ScriptType> 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<EvalValue> Clone() final{
return make_shared<StringEvalValue>(_value);
}
shared_ptr<EvalValue> IndexValue(EvalValue* val) final{
// Porygon is 1-indexed, so we convert to that.
auto l = val->EvaluateInteger() - 1;
return make_shared<StringEvalValue>(string(1, _value[l]));
}
std::size_t GetHashCode() final{
return _hash;
}
};
#endif //PORYGONLANG_STRINGEVALVALUE_HPP