#include "tmvaluetype.h" #include "tmassert.h" #include "tmtrace.h" int tm_valuetype_parse_opstring(TMValueType vtype, const char *opstring) { struct op_table *pp; TMTRACE(TM_VALUE_TRACE,"enter [vtype=%s, op=%s]\n" _ vtype->name _ opstring); for(pp = vtype->optab; pp && (pp)->opstring; pp++) { struct op_table *ot = pp; if(strcmp(ot->opstring,opstring) == 0) { TMTRACE(TM_VALUE_TRACE," found operator (%s,%d), exit\n" _ ot->opstring _ ot->opcode); return (ot->opcode); } } TMTRACE(TM_VALUE_TRACE,"not found operator, exit\n"); return (0); } int tm_valuetype_values_contain_topics(TMValueType vtype) { return(vtype->values_contain_topics); } void *tm_valuetype_parse_argstring(TMPool pool,TMValueType vtype, int opcode, const char *argstring) { return( vtype->parse_argstring(pool,vtype,opcode,argstring) ); } int tm_value_equal(TMValueType vtype, const void *lhs, const void *rhs) { return( vtype->equal(vtype,lhs,rhs) ); } int tm_value_to_string(TMValueType vtype, const void *v, char* buf, size_t size ) { assert(buf); return( vtype->to_string(vtype,v,buf,size) ); } char *tm_value_as_string(TMValueType vtype, const void *v, char* buf, size_t size ) { static char loc_buf[1024]; TM_ENTER; assert(vtype); TMTRACE(TM_X_TRACE,"vtype: %s\n" _ vtype->name); if(!buf) buf=loc_buf, size = 1024; vtype->to_string(vtype,v,buf,size); /* FIXME: retval of call! and also more (4) static bufs */ TM_RETURN(buf); } int tm_value_to_xml(TMValueType vtype, const void *v,char* buf, size_t size ) { return( vtype->to_xml(vtype,v,buf,size) ); } void tm_value_delete(TMPool pool,TMValueType vtype, void **vp ) { void *v = *vp; vtype->delete(pool,vtype,v); *vp = NULL; } void *tm_value_new(TMPool pool,TMValueType vtype) { return (vtype->new(pool,vtype)); } void *tm_value_new_from_string(TMPool pool,TMValueType vtype, const char *s) { TMTRACE(TM_VALUE_TRACE,"enter for vtype %s with string _ %s _\n" _ vtype->name _ s); TM_RETURN(vtype->new_from_string(pool,vtype,s)); } TMList tm_value_get_tvals(TMValueType vtype,TMPool pool,void *value) { return (vtype->get_tvals(vtype,pool,value)); } /* typedef void*(*ValueCallFunction)(TMValueType,void*,const char*,va_list args); struct function_table { const char *name; ValueCallFunction function; }; */ void *tm_value_call(TMValueType vtype, void *v,const char *name,...) { va_list args; struct function_table *ftpp; void *rv; TMTRACE(TM_VALUE_TRACE,"enter [vtype=%s, function=%s]\n" _ vtype->name _ name); va_start(args,name); for(ftpp = vtype->ftab; ftpp && (ftpp)->name; ftpp++) { struct function_table *ftp = ftpp; if(strcmp(ftp->name,name) == 0) { TMTRACE(TM_VALUE_TRACE,"found function %s\n" _ ftp->name); rv = ftp->function(vtype,v,args); va_end(args); TMTRACE(TM_VALUE_TRACE,"exit\n"); return rv; } } TMTRACE(TM_VALUE_TRACE,"not found function %s\n" _ name); va_end(args); /* FIXME: trace */ assert(!"function not found"); TMTRACE(TM_VALUE_TRACE,"exit\n"); return NULL; }