/** Polymorphic value definitions **/ #define _ARISA_VALUE_H enum { VALUE_INT32 = 0x01, VALUE_INT64 = 0x02, VALUE_STRING = 0x04, VALUE_DOUBLE = 0x08, VALUE_ENUM = 0x10, VALUE_BOOL = 0x20, VALUE_UNSIGNED = 0x80, VALUE_USE_MIN = 0x100, VALUE_USE_MAX = 0x200, VALUE_USE_DEFAULT = 0x400, VALUE_ALLOW_NULL = 0x800, VALUE_FREE_DEFAULT = 0x1000, VALUE_BOOL_ONOFF = 0x2000, VALUE_BOOL_YESNO = 0x4000, VALUE_NICE_FLOATS = 0x8000, }; typedef struct value_t { int flags; char *name; union { int (*en)(const char *); const char *(*de)(int); } num; union { char *str; int32_t i32; uint32_t ui32; int64_t i64; uint64_t ui64; double d; } val; } value_t; value_t *value_int32(const char *name, int32_t i32); value_t *value_uint32(const char *name, uint32_t ui32); value_t *value_int64(const char *name, int64_t i64); value_t *value_uint64(const char *name, uint64_t ui64); value_t *value_string(const char *name, const char *string); value_t *value_float(const char *name, float f); value_t *value_double(const char *name, double d); value_t *value_bool(const char *name, int flags, int b); value_t *value_enum_str(const char *name, const char *str, int (*en)(const char *)); value_t *value_enum_val(const char *name, int val, const char *(*de)(int)); int value_set_enumeration(value_t *v, int (*en)(const char *), const char *(*de)(int)); int32_t value_as_int32(value_t *v, int flags, int32_t min, int32_t max, int32_t def); uint32_t value_as_uint32(value_t *v, int flags, uint32_t min, uint32_t max, uint32_t def); int64_t value_as_int64(value_t *v, int flags, int64_t min, int64_t max, int64_t def); uint64_t value_as_uint64(value_t *v, int flags, uint64_t min, uint64_t max, uint64_t def); float value_as_float(value_t *v, int flags, float min, float max, float def); double value_as_double(value_t *v, int flags, double min, double max, double def); char *value_as_string(value_t *v, int flags, char *buffer, size_t bufsize, char *def); int value_as_bool(value_t *v, int flags, int def); char *value_as_bool_str(value_t *v, int flags, char *buffer, size_t bufsize); int value_as_enum(value_t *v, int flags, int def); int str_to_bool(char *str); const char *interfacetype_to_str(int type); int str_to_interfacetype(const char *str); const char *interfacemode_to_str(int mode); int str_to_interfacemode(const char *str); const char *listtype_to_str(int type); int str_to_listtype(const char *str); const char *pformat_to_str(int pformat); int str_to_pformat(const char *str); const char *networkstate_to_str(int ns); const char *chattype_to_str(int ct); const char *colourtype_to_str(int ct); int str_to_colourtype(const char *str); const char *state_to_str(int s); int str_to_sorttype(const char *str); const char *sorttype_to_str(int st); int str_to_hashtype(const char *str); const char *hashtype_to_str(int ht); int str_to_responsetype(const char *str); const char *responsetype_to_str(int rt);