#include "mlp_c.h" char mlp_c_type2cinvformat(mlp_type t){ switch (t){ case MLP_INT: return 'i' ; case MLP_LONG: return 'l' ; case MLP_DOUBLE: return 'd' ; case MLP_STRING: return 'p' ; case MLP_OBJECT: return 'p' ; } } void *mlp_c_allocate_cinv_type(mlp_type t){ switch (t){ case MLP_INT: return malloc(sizeof(int)) ; case MLP_LONG: return malloc(sizeof(long)) ; case MLP_DOUBLE: return malloc(sizeof(double)) ; case MLP_STRING: return malloc(sizeof(char *)) ; case MLP_OBJECT: return malloc(sizeof(mlp_object *)) ; } } void *mlp_c_allocate_cinv_value(mlp_type t, mlp_value *v){ void *ptr = mlp_c_allocate_cinv_type(t) ; switch (t){ case MLP_INT: ((int *)ptr)[0] = v->to_int() ; break ; case MLP_LONG: ((long *)ptr)[0] = v->to_long() ; break ; case MLP_DOUBLE: ((double *)ptr)[0] = v->to_double() ; break ; case MLP_STRING: ((const char **)ptr)[0] = v->to_string() ; break ; case MLP_OBJECT: ((const mlp_object **)ptr)[0] = v->to_object() ; break ; } return ptr ; } mlp_value *mlp_c_allocate_mlp_value(mlp_type t, void *ptr){ switch (t){ case MLP_INT: return new mlp_value(*((int *)ptr)) ; case MLP_LONG: return new mlp_value(*((long *)ptr)) ; case MLP_DOUBLE: return new mlp_value(*((double *)ptr)) ; case MLP_STRING: return new mlp_value(*((const char **)ptr)) ; case MLP_OBJECT: return new mlp_value(*((const mlp_object **)ptr)) ; } }