#include "tmvtinteger.h" #include static void* integer_new(TMPool,TMValueType vtype); static void* integer_new_from_string(TMPool,TMValueType vtype, const char *s); static int integer_equal(TMValueType, const void *, const void*); static void integer_free(TMPool,TMValueType vtype, void *s); static int integer_to_string(TMValueType, const void *topic, char* buf, size_t size); static int integer_to_xml(TMValueType, const void *topic, char* buf, size_t size); static void *integer_parse_argstring(TMPool,TMValueType vtype, int opcode, const char *argstring); static struct op_table ops[] = { { "EQU" , TM_OP_Integer_EQUAL }, { "LT" , TM_OP_Integer_LT }, { "GT" , TM_OP_Integer_GT }, { "LTEQ" , TM_OP_Integer_LT_OR_EQUAL }, { "GTEQ" , TM_OP_Integer_GT_OR_EQUAL }, { NULL, 0 } }; struct TMValueType Integer = { "Integer", 0, /* values do not contain topics */ integer_new, integer_new_from_string, integer_to_string, integer_to_xml, integer_equal, integer_free, NULL, ops, integer_parse_argstring }; void* integer_new(TMPool pool,TMValueType vtype) { assert(0); /* FIXME does not make sense, but if NULLs allowd...?! */ return NULL; } void* integer_new_from_string(TMPool pool,TMValueType vtype, const char *s) { int i; i = atoi(s); /* FIXME: other func */ return (void*)i; } void integer_free(TMPool pool,TMValueType vtype, void *t) { ; /* do nothing */ } int integer_to_string(TMValueType vtype, const void *v, char* buf, size_t size) { return ( snprintf(buf,size,"%d",(int)v) ); } int integer_to_xml(TMValueType vtype,const void *v, char* buf, size_t size) { int n; n = snprintf(buf,size," %d",(int)v); assert(n < size); return n; } int integer_equal(TMValueType vtype, const void *lhs, const void *rhs) { assert(lhs); assert(rhs); return ( (int)lhs == (int)rhs); } void *integer_parse_argstring(TMPool pool,TMValueType vtype, int opcode, const char *argstring) { switch(opcode) { case TM_OP_Integer_EQUAL: case TM_OP_Integer_LT: case TM_OP_Integer_GT: case TM_OP_Integer_LT_OR_EQUAL: case TM_OP_Integer_GT_OR_EQUAL: return (void*)atoi(argstring); default: assert(0); } return NULL; }