fx: implement value conversion interface
This commit is contained in:
+86
-1
@@ -1,17 +1,102 @@
|
||||
#include "convert.h"
|
||||
|
||||
#include <fx/int.h>
|
||||
#include <fx/value-type.h>
|
||||
|
||||
HASH(byte)
|
||||
TO_STRING(byte, "%u")
|
||||
|
||||
BOOL_CONVERT(byte)
|
||||
GENERIC_CONVERT(byte, i16, i16)
|
||||
GENERIC_CONVERT(byte, u16, u16)
|
||||
GENERIC_CONVERT(byte, i32, i32)
|
||||
GENERIC_CONVERT(byte, u32, u32)
|
||||
GENERIC_CONVERT(byte, i64, i64)
|
||||
GENERIC_CONVERT(byte, u64, u64)
|
||||
GENERIC_CONVERT(byte, iptr, iptr)
|
||||
GENERIC_CONVERT(byte, uptr, uptr)
|
||||
GENERIC_CONVERT(byte, sbyte, sbyte)
|
||||
GENERIC_CONVERT(byte, short, short)
|
||||
GENERIC_CONVERT(byte, ushort, unsigned short)
|
||||
GENERIC_CONVERT(byte, int, int)
|
||||
GENERIC_CONVERT(byte, uint, unsigned int)
|
||||
GENERIC_CONVERT(byte, long, long)
|
||||
GENERIC_CONVERT(byte, ulong, unsigned long)
|
||||
GENERIC_CONVERT(byte, longlong, long long)
|
||||
GENERIC_CONVERT(byte, ulonglong, unsigned long long)
|
||||
GENERIC_CONVERT(byte, size, size_t)
|
||||
GENERIC_CONVERT(byte, float, float)
|
||||
GENERIC_CONVERT(byte, double, double)
|
||||
|
||||
BINARY_OP(add, +, byte)
|
||||
BINARY_OP(subtract, -, byte)
|
||||
BINARY_OP(multiply, *, byte)
|
||||
BINARY_OP(divide, /, byte)
|
||||
PREFIX_OP(increment, ++, byte)
|
||||
PREFIX_OP(decrement, --, byte)
|
||||
IN_PLACE_OP(add_in_place, +=, byte)
|
||||
IN_PLACE_OP(subtract_in_place, -=, byte)
|
||||
IN_PLACE_OP(multiply_in_place, *=, byte)
|
||||
IN_PLACE_OP(divide_in_place, /=, byte)
|
||||
|
||||
COMPARE(byte, byte)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_BEGIN(fx_byte)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_INTERFACE_ENTRY(to_string) = to_string;
|
||||
FX_INTERFACE_ENTRY(hash) = hash;
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_comparable, FX_TYPE_COMPARABLE)
|
||||
FX_INTERFACE_ENTRY(c_compare) = compare;
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_comparable, FX_TYPE_COMPARABLE)
|
||||
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_operable, FX_TYPE_OPERABLE)
|
||||
FX_INTERFACE_ENTRY(op_add) = add;
|
||||
FX_INTERFACE_ENTRY(op_subtract) = subtract;
|
||||
FX_INTERFACE_ENTRY(op_multiply) = multiply;
|
||||
FX_INTERFACE_ENTRY(op_divide) = divide;
|
||||
FX_INTERFACE_ENTRY(op_increment) = increment;
|
||||
FX_INTERFACE_ENTRY(op_decrement) = decrement;
|
||||
FX_INTERFACE_ENTRY(op_add_in_place) = add_in_place;
|
||||
FX_INTERFACE_ENTRY(op_subtract_in_place) = subtract_in_place;
|
||||
FX_INTERFACE_ENTRY(op_multiply_in_place) = multiply_in_place;
|
||||
FX_INTERFACE_ENTRY(op_divide_in_place) = divide_in_place;
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_operable, FX_TYPE_OPERABLE)
|
||||
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_convertible, FX_TYPE_CONVERTIBLE)
|
||||
FX_INTERFACE_ENTRY(c_to_bool) = to_bool;
|
||||
FX_INTERFACE_ENTRY(c_to_i16) = to_i16;
|
||||
FX_INTERFACE_ENTRY(c_to_u16) = to_u16;
|
||||
FX_INTERFACE_ENTRY(c_to_i32) = to_i32;
|
||||
FX_INTERFACE_ENTRY(c_to_u32) = to_u32;
|
||||
FX_INTERFACE_ENTRY(c_to_i64) = to_i64;
|
||||
FX_INTERFACE_ENTRY(c_to_u64) = to_u64;
|
||||
FX_INTERFACE_ENTRY(c_to_iptr) = to_iptr;
|
||||
FX_INTERFACE_ENTRY(c_to_uptr) = to_uptr;
|
||||
FX_INTERFACE_ENTRY(c_to_sbyte) = to_sbyte;
|
||||
FX_INTERFACE_ENTRY(c_to_short) = to_short;
|
||||
FX_INTERFACE_ENTRY(c_to_ushort) = to_ushort;
|
||||
FX_INTERFACE_ENTRY(c_to_int) = to_int;
|
||||
FX_INTERFACE_ENTRY(c_to_uint) = to_uint;
|
||||
FX_INTERFACE_ENTRY(c_to_long) = to_long;
|
||||
FX_INTERFACE_ENTRY(c_to_ulong) = to_ulong;
|
||||
FX_INTERFACE_ENTRY(c_to_longlong) = to_longlong;
|
||||
FX_INTERFACE_ENTRY(c_to_ulonglong) = to_ulonglong;
|
||||
FX_INTERFACE_ENTRY(c_to_size) = to_size;
|
||||
FX_INTERFACE_ENTRY(c_to_float) = to_float;
|
||||
FX_INTERFACE_ENTRY(c_to_double) = to_double;
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_convertible, FX_TYPE_CONVERTIBLE)
|
||||
FX_TYPE_CLASS_END(fx_byte)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_byte)
|
||||
__FX_VALUE_TYPE_ID(BYTE);
|
||||
FX_TYPE_EXTENDS(FX_TYPE_VALUE_TYPE);
|
||||
FX_TYPE_IMPLEMENTS(FX_TYPE_CONVERTIBLE);
|
||||
FX_TYPE_IMPLEMENTS(FX_TYPE_OPERABLE);
|
||||
FX_TYPE_IMPLEMENTS(FX_TYPE_COMPARABLE);
|
||||
FX_TYPE_NAME("fx.byte");
|
||||
FX_TYPE_CLASS(fx_byte_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(byte);
|
||||
|
||||
Reference in New Issue
Block a user