PorygonLang/src/UserData/UserDataField.hpp

45 lines
1.1 KiB
C++
Raw Normal View History

2019-06-14 12:59:38 +00:00
#ifndef PORYGONLANG_USERDATAFIELD_HPP
#define PORYGONLANG_USERDATAFIELD_HPP
#include "../Evaluator/EvalValues/EvalValue.hpp"
#include "../Evaluator/EvalValues/NumericEvalValue.hpp"
2019-06-14 12:59:38 +00:00
namespace Porygon::UserData{
class UserDataField {
shared_ptr<ScriptType> _type;
Evaluation::EvalValue* (*_get)(void* obj);
void (*_set)(void* obj, Evaluation::EvalValue* val);
public:
UserDataField(ScriptType* type, Evaluation::EvalValue* (*getter)(void* obj), void (*setter)(void* obj, Evaluation::EvalValue* val)){
_type = shared_ptr<ScriptType>(type);
_get = getter;
_set = setter;
}
shared_ptr<ScriptType> GetType(){
return _type;
}
bool HasGetter(){
return _get != nullptr;
}
Evaluation::EvalValue* Get(void* obj){
return this ->_get(obj);
}
bool HasSetter(){
return _set != nullptr;
}
void Set(void* obj, Evaluation::EvalValue* val){
this->_set(obj, val);
}
};
}
2019-06-14 12:59:38 +00:00
#endif //PORYGONLANG_USERDATAFIELD_HPP