#include "mlp.h" #include #define MLP_MAX_ERROR_MSG_LENGTH 1024 mlp_context::mlp_context() : err(MLP_OK), err_msg(NULL){ } MLP_EXTERN_C mlp_context *mlp_context_new(){ return new mlp_context() ; } mlp_context::~mlp_context(){ clear_error() ; } MLP_EXTERN_C void mlp_context_delete(mlp_context *ctx){ delete ctx ; } int mlp_context::has_error(){ return (err == MLP_OK ? 0 : 1) ; } MLP_EXTERN_C int mlp_context_has_error(mlp_context *ctx){ return ctx->has_error() ; } mlp_error mlp_context::get_error(){ return err ; } MLP_EXTERN_C mlp_error mlp_context_get_error(mlp_context *ctx){ return ctx->get_error() ; } const char *mlp_context::get_error_msg(){ return err_msg ; } MLP_EXTERN_C const char *mlp_context_get_error_msg(mlp_context *ctx){ return ctx->get_error_msg() ; } void mlp_context::set_verror(mlp_error e, const char *fmt, va_list va){ clear_error() ; err = e ; if (fmt != NULL){ char *msg = (char *)malloc(MLP_MAX_ERROR_MSG_LENGTH * sizeof(char)) ; vsnprintf(msg, MLP_MAX_ERROR_MSG_LENGTH - 1, fmt, va) ; err_msg = msg ; } } MLP_EXTERN_C void mlp_context_set_verror(mlp_context *ctx, mlp_error e, const char *fmt, va_list va){ ctx->set_verror(e, fmt, va) ; } void mlp_context::set_error(mlp_error e, const char *fmt, ...){ va_list va ; va_start(va, fmt) ; set_verror(e, fmt, va) ; va_end(va) ; } MLP_EXTERN_C void mlp_context_set_error(mlp_context *ctx, mlp_error e, const char *fmt, ...){ va_list va ; va_start(va, fmt) ; ctx->set_verror(e, fmt, va) ; va_end(va) ; } void mlp_context::clear_error(){ err = MLP_OK ; if (err_msg != NULL){ free(err_msg) ; err_msg = NULL ; } } MLP_EXTERN_C void mlp_context_clear_error(mlp_context *ctx){ ctx->clear_error() ; } void mlp_context::set_runtime_data(mlp_runtime *rt, const void *data){ runtime_data[rt] = data ; } MLP_EXTERN_C void mlp_context_set_runtime_data(mlp_context *ctx, mlp_runtime *rt, const void *data){ ctx->set_runtime_data(rt, data) ; } const void *mlp_context::get_runtime_data(mlp_runtime *rt){ return runtime_data[rt] ; } MLP_EXTERN_C void mlp_context_get_runtime_data(mlp_context *ctx, mlp_runtime *rt){ ctx->get_runtime_data(rt) ; }