#ifndef PORYGONLANG_USERDATAVALUE_HPP #define PORYGONLANG_USERDATAVALUE_HPP #include #include "../Evaluator/EvalValues/EvalValue.hpp" #include "UserData.hpp" #include "UserDataStorage.hpp" class UserDataValue : public EvalValue{ shared_ptr _userData; void* _obj; public: UserDataValue(shared_ptr userData, void* obj){ _userData = std::move(userData); _obj = obj; } UserDataValue(uint32_t userDataId, void* obj){ _userData = UserDataStorage::GetUserDataType(userDataId); _obj = obj; } const TypeClass GetTypeClass() final{ return TypeClass ::UserData; } bool operator ==(EvalValue* b) final { if (b->GetTypeClass() != TypeClass::UserData) return false; return _obj == ((UserDataValue*)b)->_obj; } shared_ptr Clone() final{ return make_shared(_userData, _obj); } std::size_t GetHashCode() final{ return reinterpret_cast(_obj); } shared_ptr IndexValue(EvalValue* val) final { auto fieldId = val->GetHashCode(); auto field = _userData->GetField(fieldId); return shared_ptr(field->Get(_obj)); } shared_ptr IndexValue(uint32_t hash) final{ auto field = _userData->GetField(hash); return shared_ptr(field->Get(_obj)); } void SetIndexValue(EvalValue *key, shared_ptr value) final{ auto fieldId = key->GetHashCode(); auto field = _userData->GetField(fieldId); field -> Set(_obj, value.get()); } }; #endif //PORYGONLANG_USERDATAVALUE_HPP