Better handling of creating EvalValues in UserData templates
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
70f2dea0ce
commit
eda15e501d
|
@ -0,0 +1,60 @@
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
#ifndef PORYGONLANG_EVALVALUEHELPER_HPP
|
||||||
|
#define PORYGONLANG_EVALVALUEHELPER_HPP
|
||||||
|
|
||||||
|
#include "EvalValue.hpp"
|
||||||
|
#include "NumericEvalValue.hpp"
|
||||||
|
#include "StringEvalValue.hpp"
|
||||||
|
|
||||||
|
namespace Porygon::Evaluation{
|
||||||
|
class EvalValueHelper{
|
||||||
|
public:
|
||||||
|
static EvalValue* Create(unsigned char i){
|
||||||
|
return new IntegerEvalValue((long)i);
|
||||||
|
}
|
||||||
|
static EvalValue* Create(signed char i){
|
||||||
|
return new IntegerEvalValue((long)i);
|
||||||
|
}
|
||||||
|
static EvalValue* Create(short int i){
|
||||||
|
return new IntegerEvalValue(i);
|
||||||
|
}
|
||||||
|
static EvalValue* Create(unsigned short int i){
|
||||||
|
return new IntegerEvalValue(i);
|
||||||
|
}
|
||||||
|
static EvalValue* Create(signed int i){
|
||||||
|
return new IntegerEvalValue(i);
|
||||||
|
}
|
||||||
|
static EvalValue* Create(unsigned int i){
|
||||||
|
return new IntegerEvalValue(i);
|
||||||
|
}
|
||||||
|
static EvalValue* Create(signed long l){
|
||||||
|
return new IntegerEvalValue(l);
|
||||||
|
}
|
||||||
|
static EvalValue* Create(unsigned long l){
|
||||||
|
return new IntegerEvalValue(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
static EvalValue* Create(float f){
|
||||||
|
return new FloatEvalValue(f);
|
||||||
|
}
|
||||||
|
static EvalValue* Create(double f){
|
||||||
|
return new FloatEvalValue(f);
|
||||||
|
}
|
||||||
|
static EvalValue* Create(long double f){
|
||||||
|
return new FloatEvalValue(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
static EvalValue* Create(bool b){
|
||||||
|
return new BooleanEvalValue(b);
|
||||||
|
}
|
||||||
|
static EvalValue* Create(const string& s){
|
||||||
|
return new StringEvalValue(Utilities::StringUtils::StringToU16String(s));
|
||||||
|
}
|
||||||
|
static EvalValue* Create(u16string s){
|
||||||
|
return new StringEvalValue(std::move(s));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //PORYGONLANG_EVALVALUEHELPER_HPP
|
|
@ -92,7 +92,7 @@
|
||||||
*/
|
*/
|
||||||
#define PORYGON_PREPARE_FUNCTION(userDataTypeName, fieldName, returnType, ...) \
|
#define PORYGON_PREPARE_FUNCTION(userDataTypeName, fieldName, returnType, ...) \
|
||||||
static Porygon::Evaluation::EvalValue* invoke__##fieldName(void* obj, Porygon::Evaluation::EvalValue* par[], int parameterCount){ \
|
static Porygon::Evaluation::EvalValue* invoke__##fieldName(void* obj, Porygon::Evaluation::EvalValue* par[], int parameterCount){ \
|
||||||
return new returnType(((userDataTypeName*)obj)->fieldName( \
|
return Porygon::Evaluation::EvalValueHelper::Create(((userDataTypeName*)obj)->fieldName( \
|
||||||
__VA_ARGS__ \
|
__VA_ARGS__ \
|
||||||
));}
|
));}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,10 @@ namespace Porygon::Utilities{
|
||||||
static std::u16string IntToString(long const &i) {
|
static std::u16string IntToString(long const &i) {
|
||||||
return conv.from_bytes(std::to_string(i));
|
return conv.from_bytes(std::to_string(i));
|
||||||
}
|
}
|
||||||
|
static std::u16string StringToU16String(const std::string& s) {
|
||||||
|
return conv.from_bytes(s);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "../../src/UserData/UserDataFunction.hpp"
|
#include "../../src/UserData/UserDataFunction.hpp"
|
||||||
#include "../../src/UserData/UserDataFunctionType.hpp"
|
#include "../../src/UserData/UserDataFunctionType.hpp"
|
||||||
#include "../../src/UserData/UserDataTemplates.hpp"
|
#include "../../src/UserData/UserDataTemplates.hpp"
|
||||||
|
#include "../../src/Evaluator/EvalValues/EvalValueHelper.hpp"
|
||||||
|
|
||||||
using namespace Porygon;
|
using namespace Porygon;
|
||||||
using namespace Porygon::UserData;
|
using namespace Porygon::UserData;
|
||||||
|
|
Loading…
Reference in New Issue