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