fx: re-arrange type system to allow for reflection
This commit is contained in:
+12
-12
@@ -486,16 +486,16 @@ static enum fx_status iterator_is_valid(const fx_iterator *obj)
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_array DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_array)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_array)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = array_to_string;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_INTERFACE_ENTRY(it_begin) = iterable_begin;
|
||||
FX_INTERFACE_ENTRY(it_cbegin) = iterable_cbegin;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_array)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_END(fx_array)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_array)
|
||||
FX_TYPE_ID(0xe3c46da1, 0x5f37, 0x4e44, 0xb53b, 0xff5a6200191b);
|
||||
@@ -507,18 +507,18 @@ FX_TYPE_DEFINITION_BEGIN(fx_array)
|
||||
FX_TYPE_DEFINITION_END(fx_array)
|
||||
|
||||
// ---- fx_array_iterator DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_array_iterator)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_array_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
|
||||
FX_INTERFACE_ENTRY(it_erase) = iterator_erase;
|
||||
FX_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
|
||||
FX_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_array_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_END(fx_array_iterator)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_array_iterator)
|
||||
FX_TYPE_ID(0xe5e9e8b8, 0x14cb, 0x4192, 0x8138, 0xf45238a2ae73);
|
||||
|
||||
@@ -23,11 +23,11 @@ static void bitbuffer_fini(fx_object *obj, void *priv)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_bitbuffer)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_bitbuffer)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_bitbuffer)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_bitbuffer)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_bitbuffer)
|
||||
FX_TYPE_ID(0x628e33da, 0x3109, 0x4a5d, 0x98d5, 0xb0e4cb3ccb65);
|
||||
|
||||
@@ -343,11 +343,11 @@ static void bitmap_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_bitmap)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_bitmap)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = bitmap_to_string;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_bitmap)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_bitmap)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_bitmap)
|
||||
FX_TYPE_ID(0xea115cef, 0x8a63, 0x445f, 0x9474, 0xba9309d5dde8);
|
||||
|
||||
@@ -465,11 +465,11 @@ void buffer_fini(fx_object *obj, void *priv)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_buffer)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_buffer)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_buffer)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_buffer)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_buffer)
|
||||
FX_TYPE_ID(0x323e6858, 0x7a43, 0x4484, 0xa6fb, 0xe3d1e47ae637);
|
||||
|
||||
@@ -611,11 +611,11 @@ static void _datetime_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_datetime)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_datetime)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = _datetime_to_string;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_datetime)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_datetime)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_datetime)
|
||||
FX_TYPE_ID(0x06a6030b, 0x1e3c, 0x4be2, 0xbd23, 0xf34f4a8e68be);
|
||||
|
||||
+12
-12
@@ -690,16 +690,16 @@ static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_dict DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_dict)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_dict)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = dict_to_string;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_INTERFACE_ENTRY(it_begin) = iterable_begin;
|
||||
FX_INTERFACE_ENTRY(it_cbegin) = iterable_cbegin;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_dict)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_END(fx_dict)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_dict)
|
||||
FX_TYPE_ID(0xd2af61d9, 0xd0be, 0x4960, 0xbe3f, 0x509749814c10);
|
||||
@@ -711,18 +711,18 @@ FX_TYPE_DEFINITION_BEGIN(fx_dict)
|
||||
FX_TYPE_DEFINITION_END(fx_dict)
|
||||
|
||||
// ---- fx_dict_iterator DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_dict_iterator)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_dict_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
|
||||
FX_INTERFACE_ENTRY(it_erase) = iterator_erase;
|
||||
FX_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
|
||||
FX_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_dict_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_END(fx_dict_iterator)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_dict_iterator)
|
||||
FX_TYPE_ID(0x9ea96701, 0x1713, 0x4a3e, 0xbf63, 0xdc856b456f3b);
|
||||
|
||||
+12
-12
@@ -607,16 +607,16 @@ static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_hashmap DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_hashmap)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_hashmap)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_INTERFACE_ENTRY(it_begin) = fx_hashmap_begin;
|
||||
FX_INTERFACE_ENTRY(it_cbegin) = fx_hashmap_cbegin;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_hashmap)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_END(fx_hashmap)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_hashmap)
|
||||
FX_TYPE_ID(0x7bf5bcd1, 0x1ff3, 0x4e43, 0xbed8, 0x7c74f28348bf);
|
||||
@@ -628,18 +628,18 @@ FX_TYPE_DEFINITION_BEGIN(fx_hashmap)
|
||||
FX_TYPE_DEFINITION_END(fx_hashmap)
|
||||
|
||||
// ---- fx_hashmap_iterator DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_hashmap_iterator)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_hashmap_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
|
||||
FX_INTERFACE_ENTRY(it_erase) = iterator_erase;
|
||||
FX_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
|
||||
FX_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_hashmap_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_END(fx_hashmap_iterator)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_hashmap_iterator)
|
||||
FX_TYPE_ID(0xd9658456, 0xdd80, 0x419a, 0xb23a, 0xb513013e6431);
|
||||
|
||||
@@ -30,8 +30,8 @@ FX_TYPE_CLASS_DECLARATION_END(fx_array)
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_array_iterator)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_array_iterator)
|
||||
|
||||
FX_API fx_type fx_array_get_type(void);
|
||||
FX_API fx_type fx_array_iterator_get_type(void);
|
||||
FX_API fx_type_id fx_array_get_type(void);
|
||||
FX_API fx_type_id fx_array_iterator_get_type(void);
|
||||
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_array, FX_TYPE_ARRAY);
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ FX_DECLARE_TYPE(fx_bitmap);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_bitmap)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_bitmap)
|
||||
|
||||
FX_API fx_type fx_bitmap_get_type(void);
|
||||
FX_API fx_type_id fx_bitmap_get_type(void);
|
||||
|
||||
FX_API fx_bitmap *fx_bitmap_create(size_t nr_bits);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ FX_DECLARE_TYPE(fx_buffer);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_buffer)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_buffer)
|
||||
|
||||
FX_API fx_type fx_buffer_get_type(void);
|
||||
FX_API fx_type_id fx_buffer_get_type(void);
|
||||
|
||||
FX_API fx_buffer *fx_buffer_create(size_t item_sz);
|
||||
FX_API fx_buffer *fx_buffer_create_from_bytes(const void *p, size_t len);
|
||||
|
||||
@@ -18,7 +18,7 @@ typedef enum fx_datetime_format {
|
||||
FX_DATETIME_FORMAT_RFC3339 = 1,
|
||||
} fx_datetime_format;
|
||||
|
||||
FX_API fx_type fx_datetime_get_type(void);
|
||||
FX_API fx_type_id fx_datetime_get_type(void);
|
||||
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_datetime, FX_TYPE_DATETIME);
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ typedef struct fx_dict_item {
|
||||
fx_object *value;
|
||||
} fx_dict_item;
|
||||
|
||||
FX_API fx_type fx_dict_get_type(void);
|
||||
FX_API fx_type fx_dict_iterator_get_type(void);
|
||||
FX_API fx_type_id fx_dict_get_type(void);
|
||||
FX_API fx_type_id fx_dict_iterator_get_type(void);
|
||||
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_dict, FX_TYPE_DICT);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define FX_DS_HASHMAP_H_
|
||||
|
||||
#include <fx/bst.h>
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/queue.h>
|
||||
@@ -60,8 +61,8 @@ typedef struct fx_hashmap_item {
|
||||
fx_hashmap_value value;
|
||||
} fx_hashmap_item;
|
||||
|
||||
FX_API fx_type fx_hashmap_get_type(void);
|
||||
FX_API fx_type fx_hashmap_iterator_get_type(void);
|
||||
FX_API fx_type_id fx_hashmap_get_type(void);
|
||||
FX_API fx_type_id fx_hashmap_iterator_get_type(void);
|
||||
|
||||
FX_API fx_hashmap *fx_hashmap_create(
|
||||
fx_hashmap_key_destructor key_dtor,
|
||||
|
||||
@@ -23,8 +23,8 @@ FX_TYPE_CLASS_DECLARATION_END(fx_list_iterator)
|
||||
|
||||
typedef struct fx_list_entry fx_list_entry;
|
||||
|
||||
FX_API fx_type fx_list_get_type(void);
|
||||
FX_API fx_type fx_list_iterator_get_type(void);
|
||||
FX_API fx_type_id fx_list_get_type(void);
|
||||
FX_API fx_type_id fx_list_iterator_get_type(void);
|
||||
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_list, FX_TYPE_LIST);
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ typedef struct fx_tree_node {
|
||||
struct fx_queue_entry __q01;
|
||||
} fx_tree_node;
|
||||
|
||||
FX_API fx_type fx_tree_get_type(void);
|
||||
FX_API fx_type fx_tree_iterator_get_type(void);
|
||||
FX_API fx_type_id fx_tree_get_type(void);
|
||||
FX_API fx_type_id fx_tree_iterator_get_type(void);
|
||||
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_tree, FX_TYPE_TREE);
|
||||
|
||||
|
||||
+12
-12
@@ -507,16 +507,16 @@ static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_list DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_list)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_list)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_INTERFACE_ENTRY(it_begin) = fx_list_begin;
|
||||
FX_INTERFACE_ENTRY(it_cbegin) = fx_list_cbegin;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_list)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_END(fx_list)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_list)
|
||||
FX_TYPE_ID(0x8730e66f, 0x0fd9, 0x4773, 0x9bbd, 0x6428f6e495eb);
|
||||
@@ -528,18 +528,18 @@ FX_TYPE_DEFINITION_BEGIN(fx_list)
|
||||
FX_TYPE_DEFINITION_END(fx_list)
|
||||
|
||||
// ---- fx_list_iterator DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_list_iterator)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_list_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
|
||||
FX_INTERFACE_ENTRY(it_erase) = iterator_erase;
|
||||
FX_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
|
||||
FX_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_list_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_END(fx_list_iterator)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_list_iterator)
|
||||
FX_TYPE_ID(0xd9658456, 0xdd80, 0x419a, 0xb23a, 0xb513013e6431);
|
||||
|
||||
+12
-12
@@ -348,16 +348,16 @@ static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_tree DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_tree)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_tree)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_INTERFACE_ENTRY(it_begin) = fx_tree_begin;
|
||||
FX_INTERFACE_ENTRY(it_cbegin) = fx_tree_cbegin;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_tree)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_END(fx_tree)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_tree)
|
||||
FX_TYPE_ID(0x8d8fa36b, 0xc515, 0x4803, 0x8124, 0xfd704f01b8ae);
|
||||
@@ -369,18 +369,18 @@ FX_TYPE_DEFINITION_BEGIN(fx_tree)
|
||||
FX_TYPE_DEFINITION_END(fx_tree)
|
||||
|
||||
// ---- fx_tree_iterator DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_tree_iterator)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_tree_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
|
||||
FX_INTERFACE_ENTRY(it_erase) = iterator_erase;
|
||||
FX_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
|
||||
FX_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_tree_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_END(fx_tree_iterator)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_tree_iterator)
|
||||
FX_TYPE_ID(0xb896e671, 0x84b2, 0x4892, 0xaf09, 0x407f305f4bf8);
|
||||
|
||||
@@ -162,7 +162,7 @@ static bool compressor_eof(const struct compressor_data *p)
|
||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||
|
||||
enum fx_status fx_compressor_get_buffer_size(
|
||||
fx_type type,
|
||||
fx_type_id type,
|
||||
fx_compressor_mode mode,
|
||||
size_t *inbuf_size,
|
||||
size_t *outbuf_size)
|
||||
@@ -248,11 +248,11 @@ static void compressor_fini(fx_object *obj, void *priv)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_compressor)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_compressor)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_compressor)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_compressor)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_compressor)
|
||||
FX_TYPE_ID(0x452ee0f9, 0xfe12, 0x48a1, 0xb596, 0xad5b7a3940e7);
|
||||
|
||||
@@ -782,7 +782,7 @@ static enum fx_status cstream_restore_cursor_position(
|
||||
|
||||
enum fx_status fx_cstream_open(
|
||||
fx_stream *endpoint,
|
||||
fx_type compressor_type,
|
||||
fx_type_id compressor_type,
|
||||
fx_compressor_mode mode,
|
||||
fx_cstream **out)
|
||||
{
|
||||
@@ -989,12 +989,12 @@ static void cstream_fini(fx_object *obj, void *priv)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_cstream)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_cstream)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_stream, FX_TYPE_STREAM)
|
||||
FX_INTERFACE_ENTRY(s_close) = NULL;
|
||||
FX_INTERFACE_ENTRY(s_seek) = NULL;
|
||||
FX_INTERFACE_ENTRY(s_tell) = NULL;
|
||||
@@ -1002,8 +1002,8 @@ FX_TYPE_CLASS_DEFINITION_BEGIN(fx_cstream)
|
||||
FX_INTERFACE_ENTRY(s_read) = fx_cstream_read;
|
||||
FX_INTERFACE_ENTRY(s_write) = fx_cstream_write;
|
||||
FX_INTERFACE_ENTRY(s_reserve) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_cstream)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_CLASS_END(fx_cstream)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_cstream)
|
||||
FX_TYPE_ID(0xe1e899b5, 0x6a3c, 0x4f9c, 0xafd0, 0xaab3f156615c);
|
||||
|
||||
@@ -361,12 +361,12 @@ static enum fx_status set_mode(
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_zstd_compressor)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_zstd_compressor)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_compressor, FX_TYPE_COMPRESSOR)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_compressor, FX_TYPE_COMPRESSOR)
|
||||
FX_INTERFACE_ENTRY(c_buffer_size)
|
||||
= fx_zstd_compressor_get_buffer_size;
|
||||
FX_INTERFACE_ENTRY(c_compress) = compress;
|
||||
@@ -374,8 +374,8 @@ FX_TYPE_CLASS_DEFINITION_BEGIN(fx_zstd_compressor)
|
||||
FX_INTERFACE_ENTRY(c_decompress) = decompress;
|
||||
FX_INTERFACE_ENTRY(c_reset) = reset;
|
||||
FX_INTERFACE_ENTRY(c_set_mode) = set_mode;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_compressor, FX_TYPE_COMPRESSOR)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_zstd_compressor)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_compressor, FX_TYPE_COMPRESSOR)
|
||||
FX_TYPE_CLASS_END(fx_zstd_compressor)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_zstd_compressor)
|
||||
FX_TYPE_ID(0x51d437fc, 0xe789, 0x4105, 0xbac7, 0xe6b3f45df198);
|
||||
|
||||
@@ -38,7 +38,7 @@ typedef struct fx_compressor_data {
|
||||
fx_ringbuffer *c_in, *c_out;
|
||||
} fx_compressor_data;
|
||||
|
||||
FX_API fx_type fx_compressor_get_type(void);
|
||||
FX_API fx_type_id fx_compressor_get_type(void);
|
||||
|
||||
#if 0
|
||||
FX_API fx_status fx_compressor_create(
|
||||
@@ -48,7 +48,7 @@ FX_API fx_status fx_compressor_create(
|
||||
#endif
|
||||
|
||||
FX_API fx_status fx_compressor_get_buffer_size(
|
||||
fx_type type,
|
||||
fx_type_id type,
|
||||
fx_compressor_mode mode,
|
||||
size_t *inbuf_size,
|
||||
size_t *outbuf_size);
|
||||
|
||||
@@ -16,11 +16,11 @@ FX_DECLARE_TYPE(fx_cstream);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_cstream)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_cstream)
|
||||
|
||||
FX_API fx_type fx_cstream_get_type(void);
|
||||
FX_API fx_type_id fx_cstream_get_type(void);
|
||||
|
||||
FX_API fx_status fx_cstream_open(
|
||||
fx_stream *endpoint,
|
||||
fx_type compressor_type,
|
||||
fx_type_id compressor_type,
|
||||
enum fx_compressor_mode mode,
|
||||
fx_cstream **out);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ FX_DECLARE_TYPE(fx_zstd_compressor);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_zstd_compressor)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_compressor)
|
||||
|
||||
FX_API fx_type fx_zstd_compressor_get_type(void);
|
||||
FX_API fx_type_id fx_zstd_compressor_get_type(void);
|
||||
|
||||
FX_API fx_status fx_zstd_compressor_get_buffer_size(
|
||||
fx_compressor_mode mode,
|
||||
|
||||
@@ -96,7 +96,7 @@ int main(int argc, const char **argv)
|
||||
}
|
||||
|
||||
fx_status status = FX_SUCCESS;
|
||||
fx_type compressor_type = FX_TYPE_ZSTD_COMPRESSOR;
|
||||
fx_type_id compressor_type = FX_TYPE_ZSTD_COMPRESSOR;
|
||||
fx_compressor *compressor = fx_object_create(compressor_type);
|
||||
|
||||
size_t inbuf_size, outbuf_size;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#define BUF_SIZE 32
|
||||
|
||||
static int compress(fx_type compressor_type, FILE *in, FILE *out)
|
||||
static int compress(fx_type_id compressor_type, FILE *in, FILE *out)
|
||||
{
|
||||
fx_stream *out_stream = fx_stream_open_fp(out);
|
||||
|
||||
@@ -48,7 +48,7 @@ static int compress(fx_type compressor_type, FILE *in, FILE *out)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int decompress(fx_type compressor_type, FILE *in, FILE *out)
|
||||
static int decompress(fx_type_id compressor_type, FILE *in, FILE *out)
|
||||
{
|
||||
fx_stream *in_stream = fx_stream_open_fp(in);
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ typedef struct fx_directory_entry {
|
||||
fx_file_info info;
|
||||
} fx_directory_entry;
|
||||
|
||||
FX_API fx_type fx_directory_get_type(void);
|
||||
FX_API fx_type fx_directory_iterator_get_type(void);
|
||||
FX_API fx_type_id fx_directory_get_type(void);
|
||||
FX_API fx_type_id fx_directory_iterator_get_type(void);
|
||||
|
||||
FX_API fx_result fx_directory_open(
|
||||
fx_directory *root,
|
||||
|
||||
@@ -51,7 +51,7 @@ typedef struct fx_file_info {
|
||||
size_t length;
|
||||
} fx_file_info;
|
||||
|
||||
FX_API fx_type fx_file_get_type(void);
|
||||
FX_API fx_type_id fx_file_get_type(void);
|
||||
|
||||
FX_API fx_result fx_file_open(
|
||||
FX_TYPE_FWDREF(fx_directory) * root,
|
||||
|
||||
@@ -20,7 +20,7 @@ FX_TYPE_CLASS_DECLARATION_END(fx_path)
|
||||
|
||||
struct fx_file_info;
|
||||
|
||||
FX_API fx_type fx_path_get_type(void);
|
||||
FX_API fx_type_id fx_path_get_type(void);
|
||||
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_path, FX_TYPE_PATH);
|
||||
|
||||
|
||||
@@ -709,16 +709,16 @@ static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_directory DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_directory)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_directory)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_INTERFACE_ENTRY(it_begin) = iterator_begin;
|
||||
FX_INTERFACE_ENTRY(it_cbegin) = iterator_cbegin;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_directory)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_END(fx_directory)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_directory)
|
||||
FX_TYPE_ID(0x10d36546, 0x7f96, 0x464b, 0xbc4d, 0xe504b283fa45);
|
||||
@@ -730,18 +730,18 @@ FX_TYPE_DEFINITION_BEGIN(fx_directory)
|
||||
FX_TYPE_DEFINITION_END(fx_directory)
|
||||
|
||||
// ---- fx_directory_iterator DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_directory_iterator)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_directory_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
|
||||
FX_INTERFACE_ENTRY(it_erase) = iterator_erase;
|
||||
FX_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
|
||||
FX_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_directory_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_END(fx_directory_iterator)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_directory_iterator)
|
||||
FX_TYPE_ID(0xc707fce6, 0xc895, 0x4925, 0x8700, 0xa60641dee0cc);
|
||||
|
||||
@@ -618,20 +618,20 @@ static void file_fini(fx_object *obj, void *priv)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_file)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_file)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_stream, FX_TYPE_STREAM)
|
||||
FX_INTERFACE_ENTRY(s_close) = stream_close;
|
||||
FX_INTERFACE_ENTRY(s_getc) = stream_getc;
|
||||
FX_INTERFACE_ENTRY(s_read) = stream_read;
|
||||
FX_INTERFACE_ENTRY(s_write) = stream_write;
|
||||
FX_INTERFACE_ENTRY(s_seek) = stream_seek;
|
||||
FX_INTERFACE_ENTRY(s_tell) = stream_tell;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_file)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_CLASS_END(fx_file)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_file)
|
||||
FX_TYPE_ID(0x495a73f6, 0xb8c3, 0x4e17, 0xb5f4, 0x6fc321f67c7b);
|
||||
|
||||
@@ -401,11 +401,11 @@ void path_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_path)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_path)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = path_to_string;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_path)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_path)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_path)
|
||||
FX_TYPE_ID(0x56dc32eb, 0xea96, 0x46ed, 0x85d3, 0x760fa4ad61f4);
|
||||
|
||||
+12
-12
@@ -711,16 +711,16 @@ static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_directory DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_directory)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_directory)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_INTERFACE_ENTRY(it_begin) = iterator_begin;
|
||||
FX_INTERFACE_ENTRY(it_cbegin) = iterator_cbegin;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_directory)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_END(fx_directory)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_directory)
|
||||
FX_TYPE_ID(0x10d36546, 0x7f96, 0x464b, 0xbc4d, 0xe504b283fa45);
|
||||
@@ -732,18 +732,18 @@ FX_TYPE_DEFINITION_BEGIN(fx_directory)
|
||||
FX_TYPE_DEFINITION_END(fx_directory)
|
||||
|
||||
// ---- fx_directory_iterator DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_directory_iterator)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_directory_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
|
||||
FX_INTERFACE_ENTRY(it_erase) = iterator_erase;
|
||||
FX_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
|
||||
FX_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_directory_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_END(fx_directory_iterator)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_directory_iterator)
|
||||
FX_TYPE_ID(0xc707fce6, 0xc895, 0x4925, 0x8700, 0xa60641dee0cc);
|
||||
|
||||
@@ -620,20 +620,20 @@ static void file_fini(fx_object *obj, void *priv)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_file)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_file)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_stream, FX_TYPE_STREAM)
|
||||
FX_INTERFACE_ENTRY(s_close) = stream_close;
|
||||
FX_INTERFACE_ENTRY(s_getc) = stream_getc;
|
||||
FX_INTERFACE_ENTRY(s_read) = stream_read;
|
||||
FX_INTERFACE_ENTRY(s_write) = stream_write;
|
||||
FX_INTERFACE_ENTRY(s_seek) = stream_seek;
|
||||
FX_INTERFACE_ENTRY(s_tell) = stream_tell;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_file)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_CLASS_END(fx_file)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_file)
|
||||
FX_TYPE_ID(0x495a73f6, 0xb8c3, 0x4e17, 0xb5f4, 0x6fc321f67c7b);
|
||||
|
||||
@@ -401,11 +401,11 @@ void path_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_path)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_path)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = path_to_string;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_path)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_path)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_path)
|
||||
FX_TYPE_ID(0x56dc32eb, 0xea96, 0x46ed, 0x85d3, 0x760fa4ad61f4);
|
||||
|
||||
@@ -35,7 +35,7 @@ struct map {
|
||||
|
||||
struct type {
|
||||
struct map_item e_map_item;
|
||||
fx_type e_type;
|
||||
fx_type_id e_type;
|
||||
};
|
||||
|
||||
struct fx_assembly_p {
|
||||
@@ -131,7 +131,7 @@ static void assembly_set_version(
|
||||
static void assembly_add_type(
|
||||
struct fx_assembly_p *asm,
|
||||
const char *full_name,
|
||||
fx_type type_id)
|
||||
fx_type_id type_id)
|
||||
{
|
||||
struct type *type = malloc(sizeof *type);
|
||||
memset(type, 0x0, sizeof *type);
|
||||
@@ -218,7 +218,7 @@ void fx_assembly_set_version(
|
||||
void fx_assembly_add_type(
|
||||
fx_assembly *asm,
|
||||
const char *full_name,
|
||||
fx_type type_id)
|
||||
fx_type_id type_id)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_V(
|
||||
FX_REFLECTION_TYPE_ASSEMBLY,
|
||||
@@ -249,11 +249,11 @@ static void assembly_fini(fx_object *obj, void *priv)
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_string DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_assembly)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_assembly)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_assembly)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_assembly)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_assembly)
|
||||
FX_TYPE_ID(0xf6690c30, 0x6642, 0x42f0, 0xb79f, 0xe2baf3684b1b);
|
||||
|
||||
@@ -178,14 +178,15 @@ static void function_fini(fx_object *obj, void *priv)
|
||||
/*** CLASS DEFINITION
|
||||
* *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_function)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_function)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_function)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_function)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_function)
|
||||
FX_TYPE_ID(0x09e40174, 0x7443, 0x486e, 0xad21, 0xcc9374762e7e);
|
||||
FX_TYPE_NAME("fx.reflection.function");
|
||||
FX_TYPE_CLASS(fx_function_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_function_p);
|
||||
FX_TYPE_INSTANCE_INIT(function_init);
|
||||
|
||||
@@ -12,7 +12,7 @@ FX_DECLARE_TYPE(fx_assembly);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_assembly)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_assembly)
|
||||
|
||||
FX_API fx_type fx_assembly_get_type();
|
||||
FX_API fx_type_id fx_assembly_get_type();
|
||||
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_assembly, FX_REFLECTION_TYPE_ASSEMBLY);
|
||||
|
||||
@@ -27,11 +27,10 @@ FX_API void fx_assembly_set_version(
|
||||
FX_API void fx_assembly_add_type(
|
||||
fx_assembly *asm,
|
||||
const char *full_name,
|
||||
fx_type type_id);
|
||||
fx_type_id type_id);
|
||||
|
||||
FX_API void fx_assembly_dump(const fx_assembly *asm);
|
||||
|
||||
FX_DECLS_END
|
||||
;
|
||||
FX_DECLS_END;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,7 +23,7 @@ FX_DECLARE_TYPE(fx_function);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_function)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_function)
|
||||
|
||||
FX_API fx_type fx_function_get_type();
|
||||
FX_API fx_type_id fx_function_get_type();
|
||||
|
||||
FX_API fx_function *fx_function_create(
|
||||
const char *name,
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef FX_REFLECTION_TYPE_H_
|
||||
#define FX_REFLECTION_TYPE_H_
|
||||
|
||||
#include <fx/macros.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
struct fx_type_info;
|
||||
|
||||
#define FX_REFLECTION_TYPE_TYPE (fx_type_get_type())
|
||||
|
||||
FX_DECLARE_TYPE(fx_type);
|
||||
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_type)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_type)
|
||||
|
||||
FX_API fx_type_id fx_type_get_type();
|
||||
|
||||
FX_API const char *fx_type_get_name(const fx_type *ty);
|
||||
|
||||
FX_API const fx_type *fx_type_get_by_id(fx_type_id id);
|
||||
FX_API const fx_type *fx_type_get_by_name(const char *name);
|
||||
|
||||
FX_API fx_type *__fx_type_create(struct fx_type_info *opaque);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
#include <fx/macros.h>
|
||||
#include <fx/reflection/type.h>
|
||||
#include <fx/type.h>
|
||||
|
||||
struct fx_type_registration;
|
||||
|
||||
struct fx_type_p {
|
||||
struct fx_type_info *ty_info;
|
||||
};
|
||||
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
|
||||
extern struct fx_type_info *fx_type_info_get_by_id(const union fx_type_id *key);
|
||||
extern struct fx_type_info *fx_type_info_get_by_name(const char *name);
|
||||
|
||||
static const char *type_get_name(const struct fx_type_p *ty)
|
||||
{
|
||||
return ty->ty_info->ty_name;
|
||||
}
|
||||
|
||||
/*** PUBLIC FUNCTIONS *********************************************************/
|
||||
|
||||
fx_type *__fx_type_create(struct fx_type_info *type_info)
|
||||
{
|
||||
fx_type *out = fx_object_create(FX_REFLECTION_TYPE_TYPE);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_type_p *p = fx_object_get_private(
|
||||
out,
|
||||
FX_REFLECTION_TYPE_TYPE);
|
||||
p->ty_info = type_info;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
const char *fx_type_get_name(const fx_type *ty)
|
||||
{
|
||||
FX_CLASS_DISPATCH_STATIC_0(FX_REFLECTION_TYPE_TYPE, type_get_name, ty);
|
||||
}
|
||||
|
||||
const fx_type *fx_type_get_by_id(fx_type_id id)
|
||||
{
|
||||
struct fx_type_info *ty = fx_type_info_get_by_id(id);
|
||||
return ty ? ty->ty_metatype : NULL;
|
||||
}
|
||||
|
||||
const fx_type *fx_type_get_by_name(const char *name)
|
||||
{
|
||||
struct fx_type_info *ty = fx_type_info_get_by_name(name);
|
||||
return ty ? ty->ty_metatype : NULL;
|
||||
}
|
||||
|
||||
/*** VIRTUAL FUNCTIONS ********************************************************/
|
||||
|
||||
static void type_init(fx_object *obj, void *priv)
|
||||
{
|
||||
}
|
||||
|
||||
static void type_fini(fx_object *obj, void *priv)
|
||||
{
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_BEGIN(fx_type)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_type)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_type)
|
||||
FX_TYPE_ID(0xec8b2679, 0x5c73, 0x4ec9, 0xa04e, 0x3f72881b5b5a);
|
||||
FX_TYPE_NAME("fx.reflection.type");
|
||||
FX_TYPE_CLASS(fx_type_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_type_p);
|
||||
FX_TYPE_INSTANCE_INIT(type_init);
|
||||
FX_TYPE_INSTANCE_FINI(type_fini);
|
||||
FX_TYPE_DEFINITION_END(fx_type)
|
||||
+6
-6
@@ -31,16 +31,16 @@ static void bitcode_serial_ctx_fini(fx_object *obj, void *priv)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_bitcode_serial_ctx)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_bitcode_serial_ctx)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_serial_ctx, FX_TYPE_SERIAL_CTX)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_serial_ctx, FX_TYPE_SERIAL_CTX)
|
||||
FX_INTERFACE_ENTRY(s_serialise) = bitcode_serialise;
|
||||
FX_INTERFACE_ENTRY(s_deserialise) = bitcode_deserialise;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_serial_ctx, FX_TYPE_SERIAL_CTX)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_bitcode_serial_ctx)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_serial_ctx, FX_TYPE_SERIAL_CTX)
|
||||
FX_TYPE_CLASS_END(fx_bitcode_serial_ctx)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_bitcode_serial_ctx)
|
||||
FX_TYPE_ID(0xcdc8c462, 0xf2b3, 0x4193, 0x8cae, 0xc1e5ad9afcb8);
|
||||
|
||||
+4
-4
@@ -26,11 +26,11 @@ static void serial_ctx_fini(fx_object *obj, void *priv)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_serial_ctx)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_serial_ctx)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_serial_ctx)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_serial_ctx)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_serial_ctx)
|
||||
FX_TYPE_ID(0xc7c1039a, 0xf397, 0x4fda, 0xb473, 0x4d86fec85384);
|
||||
|
||||
@@ -12,7 +12,7 @@ FX_DECLARE_TYPE(fx_bitcode_serial_ctx);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_bitcode_serial_ctx)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_bitcode_serial_ctx)
|
||||
|
||||
FX_API fx_type fx_bitcode_serial_ctx_get_type(void);
|
||||
FX_API fx_type_id fx_bitcode_serial_ctx_get_type(void);
|
||||
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_bitcode_serial_ctx, FX_TYPE_BITCODE_SERIAL_CTX);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ typedef struct fx_serial_ctx_data {
|
||||
fx_stream_buffer *ctx_streambuf;
|
||||
} fx_serial_ctx_data;
|
||||
|
||||
FX_API fx_type fx_serial_ctx_get_type(void);
|
||||
FX_API fx_type_id fx_serial_ctx_get_type(void);
|
||||
|
||||
FX_API fx_result fx_serial_ctx_serialise(
|
||||
fx_serial_ctx *ctx,
|
||||
|
||||
@@ -12,7 +12,7 @@ FX_DECLARE_TYPE(fx_toml_serial_ctx);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_toml_serial_ctx)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_toml_serial_ctx)
|
||||
|
||||
FX_API fx_type fx_toml_serial_ctx_get_type(void);
|
||||
FX_API fx_type_id fx_toml_serial_ctx_get_type(void);
|
||||
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_toml_serial_ctx, FX_TYPE_TOML_SERIAL_CTX);
|
||||
|
||||
|
||||
+6
-6
@@ -2322,16 +2322,16 @@ static void toml_serial_ctx_fini(fx_object *obj, void *priv)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_toml_serial_ctx)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_toml_serial_ctx)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_serial_ctx, FX_TYPE_SERIAL_CTX)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_serial_ctx, FX_TYPE_SERIAL_CTX)
|
||||
FX_INTERFACE_ENTRY(s_serialise) = toml_serialise;
|
||||
FX_INTERFACE_ENTRY(s_deserialise) = toml_deserialise;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_serial_ctx, FX_TYPE_SERIAL_CTX)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_toml_serial_ctx)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_serial_ctx, FX_TYPE_SERIAL_CTX)
|
||||
FX_TYPE_CLASS_END(fx_toml_serial_ctx)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_toml_serial_ctx)
|
||||
FX_TYPE_ID(0xaec8dca0, 0x131a, 0x4217, 0x916b, 0xaed15756601c);
|
||||
|
||||
@@ -69,11 +69,11 @@ static void bool_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_bool)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_bool)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = bool_to_string;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_bool)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_bool)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_bool)
|
||||
FX_TYPE_ID(0x9c8453bf, 0xfc92, 0x4b0a, 0xbcaf, 0xd0c6cdba9310);
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
|
||||
#include <fx/bst.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
@@ -766,131 +767,3 @@ void fx_bst_move(
|
||||
|
||||
memmove(dest, src, sizeof *src);
|
||||
}
|
||||
|
||||
fx_iterator *fx_bst_begin(struct fx_bst *tree)
|
||||
{
|
||||
fx_iterator *it_obj = fx_object_create(FX_TYPE_BST_ITERATOR);
|
||||
if (!it_obj) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_bst_iterator_p *it
|
||||
= fx_object_get_private(it_obj, FX_TYPE_BST_ITERATOR);
|
||||
int depth = 0;
|
||||
|
||||
it->_b = (struct fx_bst *)tree;
|
||||
it->i = 0;
|
||||
it->node = first_node(tree, &depth);
|
||||
it->depth = depth;
|
||||
|
||||
return it_obj;
|
||||
}
|
||||
|
||||
const fx_iterator *fx_bst_cbegin(const struct fx_bst *tree)
|
||||
{
|
||||
fx_iterator *it_obj = fx_object_create(FX_TYPE_BST_ITERATOR);
|
||||
if (!it_obj) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_bst_iterator_p *it
|
||||
= fx_object_get_private(it_obj, FX_TYPE_BST_ITERATOR);
|
||||
int depth = 0;
|
||||
|
||||
it->_b = (struct fx_bst *)tree;
|
||||
it->i = 0;
|
||||
it->node = first_node(tree, &depth);
|
||||
it->depth = depth;
|
||||
|
||||
return it_obj;
|
||||
}
|
||||
|
||||
static enum fx_status iterator_move_next(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_bst_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_BST_ITERATOR);
|
||||
|
||||
int depth_diff = 0;
|
||||
struct fx_bst_node *next = next_node(it->node, &depth_diff);
|
||||
|
||||
if (!next) {
|
||||
it->node = NULL;
|
||||
it->depth = 0;
|
||||
it->i++;
|
||||
return false;
|
||||
}
|
||||
|
||||
it->node = next;
|
||||
it->i++;
|
||||
it->depth += depth_diff;
|
||||
return true;
|
||||
}
|
||||
|
||||
static enum fx_status iterator_erase(fx_iterator *obj)
|
||||
{
|
||||
struct fx_bst_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_BST_ITERATOR);
|
||||
|
||||
if (!it->node) {
|
||||
return FX_ERR_OUT_OF_BOUNDS;
|
||||
}
|
||||
|
||||
int depth_diff = 0;
|
||||
struct fx_bst_node *next = next_node(it->node, &depth_diff);
|
||||
|
||||
fx_bst_delete(it->_b, it->node);
|
||||
if (!next) {
|
||||
it->node = NULL;
|
||||
it->depth = 0;
|
||||
} else {
|
||||
it->node = next;
|
||||
it->depth = 0;
|
||||
|
||||
struct fx_bst_node *cur = next->n_parent;
|
||||
while (cur) {
|
||||
it->depth++;
|
||||
cur = cur->n_parent;
|
||||
}
|
||||
}
|
||||
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_iterator_value iterator_get_value(fx_iterator *obj)
|
||||
{
|
||||
struct fx_bst_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_BST_ITERATOR);
|
||||
|
||||
return FX_ITERATOR_VALUE_PTR(it->node);
|
||||
}
|
||||
|
||||
static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_bst_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_BST_ITERATOR);
|
||||
|
||||
return FX_ITERATOR_VALUE_CPTR(it->node);
|
||||
}
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_bst_iterator DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_bst_iterator)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
|
||||
FX_INTERFACE_ENTRY(it_erase) = iterator_erase;
|
||||
FX_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
|
||||
FX_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_bst_iterator)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_bst_iterator)
|
||||
FX_TYPE_ID(0x432779d7, 0xc03a, 0x48ea, 0xae8f, 0x12c666c767ae);
|
||||
FX_TYPE_EXTENDS(FX_TYPE_ITERATOR);
|
||||
FX_TYPE_CLASS(fx_bst_iterator_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_bst_iterator_p);
|
||||
FX_TYPE_DEFINITION_END(fx_bst_iterator)
|
||||
|
||||
+24
-18
@@ -7,14 +7,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void *fx_class_get(fx_type id)
|
||||
void *fx_class_get(fx_type_id id)
|
||||
{
|
||||
struct fx_type_registration *r = fx_type_get_registration(id);
|
||||
if (!r) {
|
||||
struct fx_type_info *ty = fx_type_info_get_by_id(id);
|
||||
if (!ty) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return r->r_class;
|
||||
return ty->ty_class;
|
||||
}
|
||||
|
||||
const char *fx_class_get_name(const struct _fx_class *c)
|
||||
@@ -25,10 +25,12 @@ const char *fx_class_get_name(const struct _fx_class *c)
|
||||
|
||||
assert(c->c_magic == FX_CLASS_MAGIC);
|
||||
|
||||
return c->c_type->r_info->t_name;
|
||||
return c->c_type->ty_name;
|
||||
}
|
||||
|
||||
void *fx_class_get_interface(const struct _fx_class *c, const union fx_type *id)
|
||||
void *fx_class_get_interface(
|
||||
const struct _fx_class *c,
|
||||
const union fx_type_id *id)
|
||||
{
|
||||
if (!c) {
|
||||
return NULL;
|
||||
@@ -36,9 +38,10 @@ void *fx_class_get_interface(const struct _fx_class *c, const union fx_type *id)
|
||||
|
||||
assert(c->c_magic == FX_CLASS_MAGIC);
|
||||
|
||||
const struct fx_type_registration *type_reg = c->c_type;
|
||||
struct fx_type_component *comp
|
||||
= fx_type_get_component(&type_reg->r_components, id);
|
||||
const struct fx_type_info *type_reg = c->c_type;
|
||||
struct fx_type_component *comp = fx_type_get_component(
|
||||
&type_reg->ty_components,
|
||||
id);
|
||||
|
||||
if (!comp) {
|
||||
return NULL;
|
||||
@@ -48,28 +51,31 @@ void *fx_class_get_interface(const struct _fx_class *c, const union fx_type *id)
|
||||
}
|
||||
|
||||
fx_result fx_class_instantiate(
|
||||
struct fx_type_registration *type,
|
||||
struct fx_type_info *type,
|
||||
struct _fx_class **out_class)
|
||||
{
|
||||
struct _fx_class *out = malloc(type->r_class_size);
|
||||
struct _fx_class *out = malloc(type->ty_class_size);
|
||||
if (!out) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
memset(out, 0x0, type->r_class_size);
|
||||
memset(out, 0x0, type->ty_class_size);
|
||||
|
||||
out->c_magic = FX_CLASS_MAGIC;
|
||||
out->c_type = type;
|
||||
|
||||
struct fx_queue_entry *entry = fx_queue_first(&type->r_class_hierarchy);
|
||||
struct fx_queue_entry *entry = fx_queue_first(
|
||||
&type->ty_class_hierarchy);
|
||||
while (entry) {
|
||||
struct fx_type_component *comp
|
||||
= fx_unbox(struct fx_type_component, entry, c_entry);
|
||||
const struct fx_type_info *class_info = comp->c_type->r_info;
|
||||
struct fx_type_component *comp = fx_unbox(
|
||||
struct fx_type_component,
|
||||
entry,
|
||||
c_entry);
|
||||
const struct fx_type_info *class_info = comp->c_type;
|
||||
void *class_data = (char *)out + comp->c_class_data_offset;
|
||||
|
||||
if (class_info->t_class_init) {
|
||||
class_info->t_class_init(out, class_data);
|
||||
if (class_info->ty_class_init) {
|
||||
class_info->ty_class_init(out, class_data);
|
||||
}
|
||||
|
||||
entry = fx_queue_next(entry);
|
||||
|
||||
+4
-3
@@ -5,14 +5,15 @@
|
||||
#include <fx/misc.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct fx_type_registration;
|
||||
struct fx_type_info;
|
||||
|
||||
struct _fx_class {
|
||||
uint64_t c_magic;
|
||||
const struct fx_type_registration *c_type;
|
||||
const struct fx_type_info *c_type;
|
||||
};
|
||||
|
||||
extern fx_result fx_class_instantiate(
|
||||
struct fx_type_registration *type, struct _fx_class **out);
|
||||
struct fx_type_info *type,
|
||||
struct _fx_class **out);
|
||||
|
||||
#endif
|
||||
|
||||
+4
-4
@@ -265,11 +265,11 @@ static void double_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_double)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_double)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = double_to_string;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_double)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_double)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_double)
|
||||
FX_TYPE_ID(0x3b20f57a, 0x2ddf, 0x4682, 0x81c4, 0x4fe404a6524e);
|
||||
|
||||
@@ -12,7 +12,7 @@ FX_DECLARE_TYPE(fx_bool);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_bool)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_bool)
|
||||
|
||||
FX_API fx_type fx_bool_get_type(void);
|
||||
FX_API fx_type_id fx_bool_get_type(void);
|
||||
|
||||
FX_API fx_bool *fx_bool_create(bool value);
|
||||
|
||||
|
||||
+3
-14
@@ -1,22 +1,16 @@
|
||||
#ifndef FX_CORE_BST_H_
|
||||
#define FX_CORE_BST_H_
|
||||
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/misc.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
#ifdef __cplusplus
|
||||
#define FX_DECLS_BEGIN extern "C" {
|
||||
#endif
|
||||
|
||||
#define FX_BST_INIT {0}
|
||||
#define FX_TYPE_BST_ITERATOR (fx_bst_iterator_get_type())
|
||||
|
||||
FX_DECLARE_TYPE(fx_bst_iterator);
|
||||
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_bst_iterator)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_bst_iterator)
|
||||
|
||||
/* defines a simple node insertion function.
|
||||
this function assumes that your nodes have simple integer keys that can be
|
||||
@@ -279,8 +273,6 @@ typedef struct fx_bst {
|
||||
fx_bst_node *bst_root;
|
||||
} fx_bst;
|
||||
|
||||
FX_API fx_type fx_bst_iterator_get_type(void);
|
||||
|
||||
/* re-balance a binary tree after an insertion operation.
|
||||
|
||||
NOTE that, if you define an insertion function using BST_DEFINE_INSERT or
|
||||
@@ -369,9 +361,6 @@ static inline unsigned short fx_bst_height(fx_bst_node *node)
|
||||
return node->n_height;
|
||||
}
|
||||
|
||||
FX_API fx_iterator *fx_bst_begin(fx_bst *tree);
|
||||
FX_API const fx_iterator *fx_bst_cbegin(const fx_bst *tree);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
typedef struct _fx_class fx_class;
|
||||
|
||||
FX_API void *fx_class_get(fx_type id);
|
||||
FX_API void *fx_class_get(fx_type_id id);
|
||||
FX_API const char *fx_class_get_name(const fx_class *c);
|
||||
FX_API void *fx_class_get_interface(const fx_class *c, fx_type id);
|
||||
FX_API void *fx_class_get_interface(const fx_class *c, fx_type_id id);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,7 +12,7 @@ FX_DECLARE_TYPE(fx_double);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_double)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_double)
|
||||
|
||||
FX_API fx_type fx_double_get_type(void);
|
||||
FX_API fx_type_id fx_double_get_type(void);
|
||||
|
||||
FX_API fx_double *fx_double_create(double value);
|
||||
FX_API fx_double *fx_double_create_nan(void);
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ FX_DECLARE_TYPE(fx_int);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_int)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_int)
|
||||
|
||||
FX_API fx_type fx_int_get_type(void);
|
||||
FX_API fx_type_id fx_int_get_type(void);
|
||||
|
||||
FX_API fx_int *fx_int_create(intptr_t value);
|
||||
FX_API fx_int *fx_int_create_nan(void);
|
||||
|
||||
@@ -61,8 +61,8 @@ FX_TYPE_CLASS_DECLARATION_BEGIN(fx_iterable)
|
||||
const fx_iterator *(*it_cbegin)(const fx_iterable *);
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_iterable)
|
||||
|
||||
FX_API fx_type fx_iterator_get_type(void);
|
||||
FX_API fx_type fx_iterable_get_type(void);
|
||||
FX_API fx_type_id fx_iterator_get_type(void);
|
||||
FX_API fx_type_id fx_iterable_get_type(void);
|
||||
|
||||
static inline const fx_iterator *fx_iterator_ref(const fx_iterator *p)
|
||||
{
|
||||
|
||||
+47
-42
@@ -12,12 +12,20 @@
|
||||
|
||||
/* Type definitions macros (for use in .c source file) */
|
||||
|
||||
#define FX_TYPE_CLASS_DEFINITION_BEGIN(type_name) \
|
||||
#define FX_TYPE_CLASS_BEGIN(type_name) \
|
||||
static void type_name##_class_init(fx_class *p, void *d) \
|
||||
{
|
||||
#define FX_TYPE_CLASS_DEFINITION_END(type_name) }
|
||||
#define FX_TYPE_CLASS_END(type_name) }
|
||||
|
||||
#define FX_TYPE_CLASS_INTERFACE_BEGIN(interface_name, interface_id) \
|
||||
#define FX_TYPE_FUNCTIONALITY_BEGIN(type_name) \
|
||||
static void type_name##_type_functionality_init(void *opaque) \
|
||||
{
|
||||
#define FX_TYPE_FUNCTIONALITY_END(type_name) }
|
||||
#define FX_TYPE_CONSTRUCTOR(name, impl, ...)
|
||||
#define FX_TYPE_METHOD(return_type, name, impl, ...)
|
||||
#define FX_TYPE_FUNCTION(return_type, name, impl, ...)
|
||||
|
||||
#define FX_TYPE_VTABLE_INTERFACE_BEGIN(interface_name, interface_id) \
|
||||
interface_name##_class *__FX_IFACE_I1(iface, __LINE__) \
|
||||
= fx_class_get_interface(p, interface_id); \
|
||||
if (!__FX_IFACE_I1(iface, __LINE__)) { \
|
||||
@@ -30,7 +38,7 @@
|
||||
exit(-1); \
|
||||
} else { \
|
||||
interface_name##_class *iface = __FX_IFACE_I1(iface, __LINE__);
|
||||
#define FX_TYPE_CLASS_INTERFACE_END(interface_name, interface_id) }
|
||||
#define FX_TYPE_VTABLE_INTERFACE_END(interface_name, interface_id) }
|
||||
#define FX_INTERFACE_ENTRY(slot) iface->slot
|
||||
|
||||
#define FX_TYPE_DEFINITION_BEGIN(name) \
|
||||
@@ -40,8 +48,8 @@
|
||||
{ \
|
||||
fx_type_info *type_info = &name##_type_info; \
|
||||
unsigned int nr_vtables = 0; \
|
||||
type_info->t_name = #name; \
|
||||
type_info->t_class_init = name##_class_init;
|
||||
type_info->ty_name = #name; \
|
||||
type_info->ty_class_init = name##_class_init;
|
||||
#define FX_TYPE_DEFINITION_END(name) \
|
||||
fx_result result = fx_type_register(type_info); \
|
||||
if (fx_result_is_error(result)) { \
|
||||
@@ -52,7 +60,7 @@
|
||||
abort(); \
|
||||
} \
|
||||
} \
|
||||
fx_type name##_get_type(void) \
|
||||
fx_type_id name##_get_type(void) \
|
||||
{ \
|
||||
static fx_once static_type_init = FX_ONCE_INIT; \
|
||||
\
|
||||
@@ -60,39 +68,28 @@
|
||||
name##_type_init(); \
|
||||
} \
|
||||
\
|
||||
return &name##_type_info.t_id; \
|
||||
return &name##_type_info.ty_id; \
|
||||
}
|
||||
|
||||
#define FX_TYPE_ID(a, b, c, d, e) \
|
||||
fx_type_id_init(&type_info->t_id, a, b, c, d, e)
|
||||
fx_type_id_init(&type_info->ty_id, a, b, c, d, e)
|
||||
#define FX_TYPE_NAME(n) type_info->ty_name = (n)
|
||||
#define FX_TYPE_EXTENDS(parent_id) \
|
||||
fx_type_id_copy(parent_id, &type_info->t_parent_id)
|
||||
fx_type_id_copy(parent_id, &type_info->ty_parent_id)
|
||||
#define FX_TYPE_IMPLEMENTS(interface_id) \
|
||||
fx_type_id_copy( \
|
||||
interface_id, \
|
||||
&type_info->t_interfaces[type_info->t_nr_interfaces++])
|
||||
&type_info->ty_interfaces[type_info->ty_nr_interfaces++])
|
||||
#define FX_TYPE_CLASS(class_struct) \
|
||||
type_info->t_class_size = sizeof(class_struct)
|
||||
#define FX_TYPE_FLAGS(flags) type_info->t_flags = (flags)
|
||||
#define FX_TYPE_INSTANCE_INIT(func) type_info->t_instance_init = (func)
|
||||
#define FX_TYPE_INSTANCE_FINI(func) type_info->t_instance_fini = (func)
|
||||
|
||||
#if 0
|
||||
#define FX_TYPE_VTABLE_BEGIN(vtable_struct, interface_id) \
|
||||
vtable_struct __FX_IFACE_I1(iface, __LINE__) = {0}; \
|
||||
{ \
|
||||
vtable_struct *iface = &__FX_IFACE_I1(iface, __LINE__); \
|
||||
type_info->t_vtables[nr_vtables].v_vtable = iface; \
|
||||
type_info->t_vtables[nr_vtables].v_interface_id \
|
||||
= interface_id; \
|
||||
nr_vtables++;
|
||||
#define FX_TYPE_VTABLE_END(vtable_struct, interface_id) }
|
||||
#endif
|
||||
type_info->ty_class_private_size = sizeof(class_struct)
|
||||
#define FX_TYPE_FLAGS(flags) type_info->ty_flags = (flags)
|
||||
#define FX_TYPE_INSTANCE_INIT(func) type_info->ty_instance_init = (func)
|
||||
#define FX_TYPE_INSTANCE_FINI(func) type_info->ty_instance_fini = (func)
|
||||
|
||||
#define FX_TYPE_INSTANCE_PRIVATE(instance_struct) \
|
||||
type_info->t_instance_private_size = sizeof(instance_struct)
|
||||
type_info->ty_instance_private_size = sizeof(instance_struct)
|
||||
#define FX_TYPE_INSTANCE_PROTECTED(instance_struct) \
|
||||
type_info->t_instance_protected_size = sizeof(instance_struct)
|
||||
type_info->ty_instance_protected_size = sizeof(instance_struct)
|
||||
|
||||
/* Type declaration macros (for use in .h header file) */
|
||||
|
||||
@@ -135,8 +132,9 @@
|
||||
object, \
|
||||
...) \
|
||||
do { \
|
||||
type_name##_class *iface \
|
||||
= fx_object_get_interface(object, type_id); \
|
||||
type_name##_class *iface = fx_object_get_interface( \
|
||||
object, \
|
||||
type_id); \
|
||||
if (iface && iface->func) { \
|
||||
return iface->func(object, __VA_ARGS__); \
|
||||
} else { \
|
||||
@@ -150,8 +148,9 @@
|
||||
func, \
|
||||
object) \
|
||||
do { \
|
||||
type_name##_class *iface \
|
||||
= fx_object_get_interface(object, type_id); \
|
||||
type_name##_class *iface = fx_object_get_interface( \
|
||||
object, \
|
||||
type_id); \
|
||||
if (iface && iface->func) { \
|
||||
return iface->func(object); \
|
||||
} else { \
|
||||
@@ -160,8 +159,9 @@
|
||||
} while (0)
|
||||
#define FX_CLASS_DISPATCH_VIRTUAL_V(type_name, type_id, func, object, ...) \
|
||||
do { \
|
||||
type_name##_class *iface \
|
||||
= fx_object_get_interface(object, type_id); \
|
||||
type_name##_class *iface = fx_object_get_interface( \
|
||||
object, \
|
||||
type_id); \
|
||||
if (iface && iface->func) { \
|
||||
iface->func(object, __VA_ARGS__); \
|
||||
return; \
|
||||
@@ -169,8 +169,9 @@
|
||||
} while (0)
|
||||
#define FX_CLASS_DISPATCH_VIRTUAL_V0(type_name, type_id, func, object) \
|
||||
do { \
|
||||
type_name##_class *iface \
|
||||
= fx_object_get_interface(object, type_id); \
|
||||
type_name##_class *iface = fx_object_get_interface( \
|
||||
object, \
|
||||
type_id); \
|
||||
if (iface && iface->func) { \
|
||||
iface->func(object); \
|
||||
return; \
|
||||
@@ -200,23 +201,27 @@
|
||||
func_name(priv); \
|
||||
} while (0)
|
||||
|
||||
#define FX_ASSEMBLY_BEGIN() \
|
||||
const fx_assembly *__fx_assembly_get(void) \
|
||||
#define FX_ASSEMBLY_BEGIN(id) \
|
||||
const fx_assembly *id##_assembly_get(void) \
|
||||
{ \
|
||||
static fx_assembly *self = NULL; \
|
||||
if (self) { \
|
||||
return self; \
|
||||
} \
|
||||
self = fx_assembly_create();
|
||||
#define FX_ASSEMBLY_END() \
|
||||
fx_assembly_dump(self); \
|
||||
#define FX_ASSEMBLY_END(id) \
|
||||
return self; \
|
||||
} \
|
||||
const fx_assembly *__fx_assembly_get(void) \
|
||||
{ \
|
||||
return id##_assembly_get(); \
|
||||
}
|
||||
|
||||
#define FX_ASSEMBLY_NAME(name) fx_assembly_set_name(self, name)
|
||||
#define FX_ASSEMBLY_VERSION(major, minor, build, revision) \
|
||||
fx_assembly_set_version(self, major, minor, build, revision)
|
||||
#define FX_ASSEMBLY_EXPORT_TYPE(namespace_name, type_name, type_id) \
|
||||
extern fx_type type_id##_get_type(void); \
|
||||
extern fx_type_id type_id##_get_type(void); \
|
||||
fx_assembly_add_type( \
|
||||
self, \
|
||||
namespace_name "." type_name, \
|
||||
|
||||
@@ -19,14 +19,14 @@ typedef struct _fx_object_class {
|
||||
void (*to_string)(const fx_object *, FX_TYPE_FWDREF(fx_stream) *);
|
||||
} fx_object_class;
|
||||
|
||||
FX_API fx_type fx_object_get_type(void);
|
||||
FX_API fx_type_id fx_object_get_type(void);
|
||||
|
||||
FX_API void *fx_object_get_private(const fx_object *object, fx_type type);
|
||||
FX_API void *fx_object_get_protected(const fx_object *object, fx_type type);
|
||||
FX_API void *fx_object_get_interface(const fx_object *object, fx_type type);
|
||||
FX_API void *fx_object_get_private(const fx_object *object, fx_type_id type);
|
||||
FX_API void *fx_object_get_protected(const fx_object *object, fx_type_id type);
|
||||
FX_API void *fx_object_get_interface(const fx_object *object, fx_type_id type);
|
||||
FX_API fx_status fx_object_get_data(
|
||||
const fx_object *object,
|
||||
fx_type type,
|
||||
fx_type_id type,
|
||||
void **priv,
|
||||
void **prot,
|
||||
void **iface);
|
||||
@@ -35,10 +35,10 @@ FX_API fx_object *fx_object_ref(fx_object *p);
|
||||
FX_API void fx_object_unref(fx_object *p);
|
||||
FX_API fx_object *fx_object_make_rvalue(fx_object *p);
|
||||
|
||||
FX_API fx_object *fx_object_create(fx_type type);
|
||||
FX_API fx_object *fx_object_create(fx_type_id type);
|
||||
FX_API void fx_object_to_string(
|
||||
const fx_object *p,
|
||||
FX_TYPE_FWDREF(fx_stream) * out);
|
||||
FX_API bool fx_object_is_type(const fx_object *p, fx_type type);
|
||||
FX_API bool fx_object_is_type(const fx_object *p, fx_type_id type);
|
||||
|
||||
#endif
|
||||
|
||||
+6
-16
@@ -1,20 +1,13 @@
|
||||
#ifndef FX_CORE_QUEUE_H_
|
||||
#define FX_CORE_QUEUE_H_
|
||||
|
||||
#include <fx/iterator.h>
|
||||
#include <fx/macros.h>
|
||||
#include <fx/status.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
FX_DECLS_BEGIN;
|
||||
|
||||
#define FX_TYPE_QUEUE_ITERATOR (fx_queue_iterator_get_type())
|
||||
|
||||
FX_DECLARE_TYPE(fx_queue_iterator);
|
||||
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_queue_iterator)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_queue_iterator)
|
||||
#ifdef __cplusplus
|
||||
#define FX_DECLS_BEGIN extern "C" {
|
||||
#endif
|
||||
|
||||
#define FX_QUEUE_INIT ((fx_queue) {.q_first = NULL, .q_last = NULL})
|
||||
#define FX_QUEUE_ENTRY_INIT \
|
||||
@@ -56,8 +49,6 @@ static inline fx_queue_entry *fx_queue_prev(const fx_queue_entry *entry)
|
||||
return entry ? entry->qe_prev : NULL;
|
||||
}
|
||||
|
||||
FX_API fx_type fx_queue_iterator_get_type(void);
|
||||
|
||||
FX_API size_t fx_queue_length(const fx_queue *q);
|
||||
|
||||
FX_API void fx_queue_insert_before(
|
||||
@@ -82,9 +73,8 @@ FX_API void fx_queue_move(
|
||||
FX_API void fx_queue_delete(fx_queue *q, fx_queue_entry *entry);
|
||||
FX_API void fx_queue_delete_all(fx_queue *q);
|
||||
|
||||
FX_API fx_iterator *fx_queue_begin(fx_queue *q);
|
||||
FX_API fx_iterator *fx_queue_cbegin(const fx_queue *q);
|
||||
|
||||
FX_DECLS_END;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,7 +14,7 @@ FX_DECLARE_TYPE(fx_ringbuffer);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_ringbuffer)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_ringbuffer)
|
||||
|
||||
FX_API fx_type fx_ringbuffer_get_type(void);
|
||||
FX_API fx_type_id fx_ringbuffer_get_type(void);
|
||||
|
||||
FX_API fx_ringbuffer *fx_ringbuffer_create(size_t capacity);
|
||||
FX_API fx_ringbuffer *fx_ringbuffer_create_with_buffer(
|
||||
|
||||
@@ -50,8 +50,8 @@ FX_TYPE_CLASS_DECLARATION_END(fx_stream)
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_stream_buffer)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_stream_buffer)
|
||||
|
||||
FX_API fx_type fx_stream_get_type();
|
||||
FX_API fx_type fx_stream_buffer_get_type();
|
||||
FX_API fx_type_id fx_stream_get_type();
|
||||
FX_API fx_type_id fx_stream_buffer_get_type();
|
||||
|
||||
FX_API fx_stream *z__fx_stream_get_stdin(void);
|
||||
FX_API fx_stream *z__fx_stream_get_stdout(void);
|
||||
|
||||
@@ -40,8 +40,8 @@ typedef enum fx_string_tokenise_flags {
|
||||
FX_STRING_TOK_F_INCLUDE_EMPTY_TOKENS = 0x01u,
|
||||
} fx_string_tokenise_flags;
|
||||
|
||||
FX_API fx_type fx_string_get_type(void);
|
||||
FX_API fx_type fx_string_iterator_get_type(void);
|
||||
FX_API fx_type_id fx_string_get_type(void);
|
||||
FX_API fx_type_id fx_string_iterator_get_type(void);
|
||||
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_string, FX_TYPE_STRING);
|
||||
FX_API fx_string *fx_string_create_from_cstr(const char *s);
|
||||
|
||||
@@ -16,7 +16,7 @@ FX_DECLARE_TYPE(fx_stringstream);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_stringstream)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_stringstream)
|
||||
|
||||
FX_API fx_type fx_stringstream_get_type(void);
|
||||
FX_API fx_type_id fx_stringstream_get_type(void);
|
||||
|
||||
FX_API fx_stringstream *fx_stringstream_create(void);
|
||||
FX_API fx_stringstream *fx_stringstream_create_with_buffer(
|
||||
|
||||
+38
-18
@@ -1,8 +1,11 @@
|
||||
#ifndef FX_CORE_TYPE_H_
|
||||
#define FX_CORE_TYPE_H_
|
||||
|
||||
#include <fx/bst.h>
|
||||
#include <fx/error.h>
|
||||
#include <fx/misc.h>
|
||||
#include <fx/namemap.h>
|
||||
#include <fx/queue.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
@@ -16,53 +19,70 @@ typedef void (*fx_class_init_function)(struct _fx_class *, void *);
|
||||
typedef void (*fx_instance_init_function)(struct _fx_object *, void *);
|
||||
typedef void (*fx_instance_fini_function)(struct _fx_object *, void *);
|
||||
|
||||
typedef const union fx_type {
|
||||
typedef const union fx_type_id {
|
||||
struct {
|
||||
uint64_t p00, p01;
|
||||
} a;
|
||||
|
||||
unsigned char b[16];
|
||||
} *fx_type;
|
||||
} *fx_type_id;
|
||||
|
||||
typedef enum fx_type_category {
|
||||
FX_TYPE_NONE = 0,
|
||||
FX_TYPE_CLASS,
|
||||
FX_TYPE_INTERFACE,
|
||||
} fx_type_category;
|
||||
|
||||
typedef enum fx_type_flags {
|
||||
FX_TYPE_F_ABSTRACT = 0x01u,
|
||||
} fx_type_flags;
|
||||
|
||||
typedef struct fx_type_info {
|
||||
union fx_type t_id;
|
||||
union fx_type t_parent_id;
|
||||
const char *t_name;
|
||||
fx_type_flags t_flags;
|
||||
union fx_type t_interfaces[FX_TYPE_MAX_INTERFACES];
|
||||
size_t t_nr_interfaces;
|
||||
size_t t_class_size;
|
||||
fx_class_init_function t_class_init;
|
||||
size_t t_instance_private_size;
|
||||
size_t t_instance_protected_size;
|
||||
fx_instance_init_function t_instance_init;
|
||||
fx_instance_fini_function t_instance_fini;
|
||||
union fx_type_id ty_id;
|
||||
union fx_type_id ty_parent_id;
|
||||
fx_type_category ty_category;
|
||||
const char *ty_name;
|
||||
fx_type_flags ty_flags;
|
||||
union fx_type_id ty_interfaces[FX_TYPE_MAX_INTERFACES];
|
||||
size_t ty_nr_interfaces;
|
||||
fx_class_init_function ty_class_init;
|
||||
size_t ty_instance_private_size;
|
||||
size_t ty_instance_protected_size;
|
||||
size_t ty_class_private_size;
|
||||
fx_instance_init_function ty_instance_init;
|
||||
fx_instance_fini_function ty_instance_fini;
|
||||
|
||||
struct fx_bst_node ty_idmap_node;
|
||||
struct fx_namemap_entry ty_namemap_entry;
|
||||
struct _fx_object *ty_metatype;
|
||||
struct _fx_class *ty_class;
|
||||
struct fx_bst ty_components;
|
||||
struct fx_queue ty_class_hierarchy;
|
||||
struct fx_namemap ty_functions;
|
||||
|
||||
size_t ty_instance_size, ty_class_size;
|
||||
} fx_type_info;
|
||||
|
||||
FX_API void fx_type_id_init(
|
||||
union fx_type *out,
|
||||
union fx_type_id *out,
|
||||
uint32_t a,
|
||||
uint16_t b,
|
||||
uint16_t c,
|
||||
uint16_t d,
|
||||
uint64_t e);
|
||||
static inline void fx_type_id_copy(fx_type src, union fx_type *dest)
|
||||
static inline void fx_type_id_copy(fx_type_id src, union fx_type_id *dest)
|
||||
{
|
||||
dest->a.p00 = src->a.p00;
|
||||
dest->a.p01 = src->a.p01;
|
||||
}
|
||||
|
||||
static inline int fx_type_id_compare(fx_type a, fx_type b)
|
||||
static inline int fx_type_id_compare(fx_type_id a, fx_type_id b)
|
||||
{
|
||||
if (a == b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return memcmp(a, b, sizeof(union fx_type));
|
||||
return memcmp(a, b, sizeof(union fx_type_id));
|
||||
}
|
||||
|
||||
FX_API fx_result fx_type_register(fx_type_info *info);
|
||||
|
||||
@@ -12,7 +12,7 @@ FX_DECLARE_TYPE(fx_uint);
|
||||
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_uint)
|
||||
FX_TYPE_CLASS_DECLARATION_END(fx_uint)
|
||||
|
||||
FX_API fx_type fx_uint_get_type(void);
|
||||
FX_API fx_type_id fx_uint_get_type(void);
|
||||
|
||||
FX_API fx_uint *fx_uint_create(uintptr_t value);
|
||||
FX_API fx_uint *fx_uint_create_nan(void);
|
||||
|
||||
@@ -24,7 +24,7 @@ typedef union fx_uuid_bytes {
|
||||
uint64_t uuid_qwords[FX_UUID_NBYTES / 8];
|
||||
} fx_uuid_bytes;
|
||||
|
||||
FX_API fx_type fx_uuid_get_type(void);
|
||||
FX_API fx_type_id fx_uuid_get_type(void);
|
||||
|
||||
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_uuid, FX_TYPE_UUID);
|
||||
|
||||
|
||||
@@ -46,14 +46,14 @@ typedef enum fx_value_type {
|
||||
FX_VALUE_TYPE_CSTR,
|
||||
FX_VALUE_TYPE_POINTER,
|
||||
|
||||
/* any value greater than this represents an object fx_type */
|
||||
/* any value greater than this represents an object fx_type_id */
|
||||
__FX_VALUE_TYPE_OBJECT_BOUNDARY = 1024,
|
||||
} fx_value_type;
|
||||
|
||||
typedef struct fx_value {
|
||||
union {
|
||||
fx_value_type t_primitive;
|
||||
fx_type t_object;
|
||||
fx_type_id t_object;
|
||||
} v_type;
|
||||
|
||||
union {
|
||||
@@ -67,7 +67,7 @@ typedef struct fx_value {
|
||||
};
|
||||
} fx_value;
|
||||
|
||||
FX_API void fx_value_init(fx_value *v, fx_type type);
|
||||
FX_API void fx_value_init(fx_value *v, fx_type_id type);
|
||||
FX_API void fx_value_init_primitive(fx_value *v, fx_value_type type);
|
||||
|
||||
FX_API void fx_value_copy(fx_value *dst, fx_value *src);
|
||||
@@ -90,7 +90,7 @@ FX_API bool fx_value_is_uint(const fx_value *v);
|
||||
FX_API bool fx_value_is_double(const fx_value *v);
|
||||
FX_API bool fx_value_is_string(const fx_value *v);
|
||||
FX_API bool fx_value_is_pointer(const fx_value *v);
|
||||
FX_API bool fx_value_is_object(const fx_value *v, fx_type type);
|
||||
FX_API bool fx_value_is_object(const fx_value *v, fx_type_id type);
|
||||
|
||||
FX_API bool fx_value_get_bool(const fx_value *v);
|
||||
FX_API intptr_t fx_value_get_int(const fx_value *v);
|
||||
|
||||
@@ -257,11 +257,11 @@ static void int_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_int)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_int)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = int_to_string;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_int)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_int)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_int)
|
||||
FX_TYPE_ID(0x3b20f57a, 0x2ddf, 0x4682, 0x81c4, 0x4fe404a6524e);
|
||||
|
||||
+16
-12
@@ -61,8 +61,9 @@ enum fx_status fx_iterator_move_next(const fx_iterator *it)
|
||||
{
|
||||
enum fx_status status = FX_ERR_NOT_SUPPORTED;
|
||||
|
||||
fx_iterator_class *iface
|
||||
= fx_object_get_interface(it, FX_TYPE_ITERATOR);
|
||||
fx_iterator_class *iface = fx_object_get_interface(
|
||||
it,
|
||||
FX_TYPE_ITERATOR);
|
||||
if (iface && iface->it_move_next) {
|
||||
status = iface->it_move_next(it);
|
||||
}
|
||||
@@ -97,8 +98,9 @@ fx_status fx_iterator_erase(fx_iterator *it)
|
||||
{
|
||||
enum fx_status status = FX_ERR_NOT_SUPPORTED;
|
||||
|
||||
fx_iterator_class *iface
|
||||
= fx_object_get_interface(it, FX_TYPE_ITERATOR);
|
||||
fx_iterator_class *iface = fx_object_get_interface(
|
||||
it,
|
||||
FX_TYPE_ITERATOR);
|
||||
if (iface && iface->it_erase) {
|
||||
status = iface->it_erase(it);
|
||||
}
|
||||
@@ -112,28 +114,30 @@ fx_status fx_iterator_erase(fx_iterator *it)
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_iterator DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_iterator)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_iterator)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_iterator)
|
||||
FX_TYPE_FLAGS(FX_TYPE_F_ABSTRACT);
|
||||
FX_TYPE_ID(0xfd40b67f, 0x7087, 0x40a9, 0x8fd8, 0x8ae27bd58c9e);
|
||||
FX_TYPE_NAME("fx.iterator");
|
||||
FX_TYPE_CLASS(fx_iterator_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_iterator_p);
|
||||
FX_TYPE_DEFINITION_END(fx_iterator)
|
||||
|
||||
// ---- fx_iterable DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_iterable)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_iterable)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_iterable)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_iterable)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_iterable)
|
||||
FX_TYPE_FLAGS(FX_TYPE_F_ABSTRACT);
|
||||
FX_TYPE_ID(0x4bbabf2d, 0xfc5d, 0x40cc, 0x89fc, 0x164085e47f73);
|
||||
FX_TYPE_NAME("fx.iterable");
|
||||
FX_TYPE_CLASS(fx_iterable_class);
|
||||
FX_TYPE_DEFINITION_END(fx_iterable)
|
||||
|
||||
+4
-2
@@ -1,5 +1,7 @@
|
||||
#include <fx/hash.h>
|
||||
#include <fx/namemap.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
enum map_entry_type {
|
||||
MAP_ENTRY_NONE = 0,
|
||||
@@ -7,13 +9,13 @@ enum map_entry_type {
|
||||
MAP_ENTRY_BUCKET,
|
||||
};
|
||||
|
||||
FX_BST_DEFINE_SIMPLE_GET(
|
||||
static FX_BST_DEFINE_SIMPLE_GET(
|
||||
struct __fx_namemap_entry,
|
||||
uint64_t,
|
||||
e_node,
|
||||
e_hash,
|
||||
map_get_entry);
|
||||
FX_BST_DEFINE_SIMPLE_INSERT(
|
||||
static FX_BST_DEFINE_SIMPLE_INSERT(
|
||||
struct __fx_namemap_entry,
|
||||
e_node,
|
||||
e_hash,
|
||||
|
||||
+54
-49
@@ -9,42 +9,46 @@
|
||||
#include <fx/stream.h>
|
||||
#include <fx/thread.h>
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_object)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_object)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_object)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_object)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_object)
|
||||
FX_TYPE_ID(0x45f15a2c, 0x6831, 0x4bef, 0xb350, 0x15c650679211);
|
||||
FX_TYPE_NAME("fx.object");
|
||||
FX_TYPE_CLASS(fx_object_class);
|
||||
FX_TYPE_DEFINITION_END(fx_object)
|
||||
|
||||
fx_result fx_object_instantiate(
|
||||
struct fx_type_registration *type,
|
||||
struct fx_type_info *type,
|
||||
struct _fx_object **out_object)
|
||||
{
|
||||
struct _fx_object *out = malloc(type->r_instance_size);
|
||||
struct _fx_object *out = malloc(type->ty_instance_size);
|
||||
if (!out) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
memset(out, 0x0, type->r_instance_size);
|
||||
memset(out, 0x0, type->ty_instance_size);
|
||||
|
||||
out->obj_magic = FX_OBJECT_MAGIC;
|
||||
out->obj_type = type;
|
||||
out->obj_ref = 1;
|
||||
|
||||
struct fx_queue_entry *entry = fx_queue_first(&type->r_class_hierarchy);
|
||||
struct fx_queue_entry *entry = fx_queue_first(
|
||||
&type->ty_class_hierarchy);
|
||||
while (entry) {
|
||||
struct fx_type_component *comp
|
||||
= fx_unbox(struct fx_type_component, entry, c_entry);
|
||||
const struct fx_type_info *class_info = comp->c_type->r_info;
|
||||
void *private_data
|
||||
= (char *)out + comp->c_instance_private_data_offset;
|
||||
struct fx_type_component *comp = fx_unbox(
|
||||
struct fx_type_component,
|
||||
entry,
|
||||
c_entry);
|
||||
const struct fx_type_info *class_info = comp->c_type;
|
||||
void *private_data = (char *)out
|
||||
+ comp->c_instance_private_data_offset;
|
||||
|
||||
if (class_info->t_instance_init) {
|
||||
class_info->t_instance_init(out, private_data);
|
||||
if (class_info->ty_instance_init) {
|
||||
class_info->ty_instance_init(out, private_data);
|
||||
}
|
||||
|
||||
if (comp->c_type == type) {
|
||||
@@ -59,9 +63,9 @@ fx_result fx_object_instantiate(
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
struct _fx_object *fx_object_create(fx_type type)
|
||||
struct _fx_object *fx_object_create(fx_type_id type)
|
||||
{
|
||||
struct fx_type_registration *type_reg = fx_type_get_registration(type);
|
||||
struct fx_type_info *type_reg = fx_type_info_get_by_id(type);
|
||||
if (!type_reg) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -84,27 +88,23 @@ void fx_object_to_string(const struct _fx_object *p, fx_stream *out)
|
||||
to_string,
|
||||
p,
|
||||
out);
|
||||
fx_stream_write_fmt(
|
||||
out,
|
||||
NULL,
|
||||
"<%s@%p>",
|
||||
p->obj_type->r_info->t_name,
|
||||
p);
|
||||
fx_stream_write_fmt(out, NULL, "<%s@%p>", p->obj_type->ty_name, p);
|
||||
}
|
||||
|
||||
bool fx_object_is_type(const struct _fx_object *p, fx_type type)
|
||||
bool fx_object_is_type(const struct _fx_object *p, fx_type_id type)
|
||||
{
|
||||
if (fx_type_id_compare(&p->obj_type->r_info->t_id, type) == 0) {
|
||||
if (fx_type_id_compare(&p->obj_type->ty_id, type) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
struct fx_type_component *comp
|
||||
= fx_type_get_component(&p->obj_type->r_components, type);
|
||||
struct fx_type_component *comp = fx_type_get_component(
|
||||
&p->obj_type->ty_components,
|
||||
type);
|
||||
|
||||
return comp != NULL;
|
||||
}
|
||||
|
||||
void *fx_object_get_private(const struct _fx_object *object, fx_type type)
|
||||
void *fx_object_get_private(const struct _fx_object *object, fx_type_id type)
|
||||
{
|
||||
if (!object) {
|
||||
return NULL;
|
||||
@@ -112,12 +112,13 @@ void *fx_object_get_private(const struct _fx_object *object, fx_type type)
|
||||
|
||||
assert(object->obj_magic == FX_OBJECT_MAGIC);
|
||||
|
||||
if (fx_type_id_compare(&object->obj_type->r_info->t_id, type) == 0) {
|
||||
if (fx_type_id_compare(&object->obj_type->ty_id, type) == 0) {
|
||||
return (char *)object + object->obj_main_priv_offset;
|
||||
}
|
||||
|
||||
struct fx_type_component *comp
|
||||
= fx_type_get_component(&object->obj_type->r_components, type);
|
||||
struct fx_type_component *comp = fx_type_get_component(
|
||||
&object->obj_type->ty_components,
|
||||
type);
|
||||
if (!comp) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -125,7 +126,7 @@ void *fx_object_get_private(const struct _fx_object *object, fx_type type)
|
||||
return (char *)object + comp->c_instance_private_data_offset;
|
||||
}
|
||||
|
||||
void *fx_object_get_protected(const struct _fx_object *object, fx_type type)
|
||||
void *fx_object_get_protected(const struct _fx_object *object, fx_type_id type)
|
||||
{
|
||||
if (!object) {
|
||||
return NULL;
|
||||
@@ -133,8 +134,9 @@ void *fx_object_get_protected(const struct _fx_object *object, fx_type type)
|
||||
|
||||
assert(object->obj_magic == FX_OBJECT_MAGIC);
|
||||
|
||||
struct fx_type_component *comp
|
||||
= fx_type_get_component(&object->obj_type->r_components, type);
|
||||
struct fx_type_component *comp = fx_type_get_component(
|
||||
&object->obj_type->ty_components,
|
||||
type);
|
||||
if (!comp) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -142,7 +144,7 @@ void *fx_object_get_protected(const struct _fx_object *object, fx_type type)
|
||||
return (char *)object + comp->c_instance_protected_data_offset;
|
||||
}
|
||||
|
||||
void *fx_object_get_interface(const struct _fx_object *object, fx_type type)
|
||||
void *fx_object_get_interface(const struct _fx_object *object, fx_type_id type)
|
||||
{
|
||||
if (!object) {
|
||||
return NULL;
|
||||
@@ -150,12 +152,12 @@ void *fx_object_get_interface(const struct _fx_object *object, fx_type type)
|
||||
|
||||
assert(object->obj_magic == FX_OBJECT_MAGIC);
|
||||
|
||||
return fx_class_get_interface(object->obj_type->r_class, type);
|
||||
return fx_class_get_interface(object->obj_type->ty_class, type);
|
||||
}
|
||||
|
||||
enum fx_status fx_object_get_data(
|
||||
const struct _fx_object *object,
|
||||
fx_type type,
|
||||
fx_type_id type,
|
||||
void **priv,
|
||||
void **prot,
|
||||
void **iface)
|
||||
@@ -166,8 +168,9 @@ enum fx_status fx_object_get_data(
|
||||
|
||||
assert(object->obj_magic == FX_OBJECT_MAGIC);
|
||||
|
||||
struct fx_type_component *comp
|
||||
= fx_type_get_component(&object->obj_type->r_components, type);
|
||||
struct fx_type_component *comp = fx_type_get_component(
|
||||
&object->obj_type->ty_components,
|
||||
type);
|
||||
if (!comp) {
|
||||
return FX_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
@@ -181,7 +184,7 @@ enum fx_status fx_object_get_data(
|
||||
}
|
||||
|
||||
if (iface) {
|
||||
*iface = (char *)object->obj_type->r_class
|
||||
*iface = (char *)object->obj_type->ty_class
|
||||
+ comp->c_class_data_offset;
|
||||
}
|
||||
|
||||
@@ -202,19 +205,21 @@ void fx_object_unref(struct _fx_object *p)
|
||||
}
|
||||
|
||||
p->obj_ref = 0;
|
||||
const struct fx_type_registration *type = p->obj_type;
|
||||
const struct fx_type_info *type = p->obj_type;
|
||||
|
||||
struct fx_queue_entry *cur = fx_queue_last(&type->r_class_hierarchy);
|
||||
struct fx_queue_entry *cur = fx_queue_last(&type->ty_class_hierarchy);
|
||||
while (cur) {
|
||||
struct fx_type_component *comp
|
||||
= fx_unbox(struct fx_type_component, cur, c_entry);
|
||||
struct fx_type_component *comp = fx_unbox(
|
||||
struct fx_type_component,
|
||||
cur,
|
||||
c_entry);
|
||||
|
||||
const struct fx_type_info *class_info = comp->c_type->r_info;
|
||||
void *private_data
|
||||
= (char *)p + comp->c_instance_private_data_offset;
|
||||
const struct fx_type_info *class_info = comp->c_type;
|
||||
void *private_data = (char *)p
|
||||
+ comp->c_instance_private_data_offset;
|
||||
|
||||
if (class_info->t_instance_fini) {
|
||||
class_info->t_instance_fini(p, private_data);
|
||||
if (class_info->ty_instance_fini) {
|
||||
class_info->ty_instance_fini(p, private_data);
|
||||
}
|
||||
|
||||
cur = fx_queue_prev(cur);
|
||||
|
||||
+4
-3
@@ -5,15 +5,16 @@
|
||||
#include <fx/misc.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct fx_type_registration;
|
||||
struct fx_type_info;
|
||||
|
||||
struct _fx_object {
|
||||
uint64_t obj_magic;
|
||||
const struct fx_type_registration *obj_type;
|
||||
const struct fx_type_info *obj_type;
|
||||
unsigned int obj_ref, obj_main_priv_offset;
|
||||
};
|
||||
|
||||
extern fx_result fx_object_instantiate(
|
||||
struct fx_type_registration *type, struct _fx_object **out);
|
||||
struct fx_type_info *type,
|
||||
struct _fx_object **out);
|
||||
|
||||
#endif
|
||||
|
||||
-90
@@ -1,11 +1,5 @@
|
||||
#include <fx/queue.h>
|
||||
|
||||
struct fx_queue_iterator_p {
|
||||
size_t i;
|
||||
fx_queue_entry *entry;
|
||||
fx_queue *_q;
|
||||
};
|
||||
|
||||
size_t fx_queue_length(const struct fx_queue *q)
|
||||
{
|
||||
size_t i = 0;
|
||||
@@ -163,87 +157,3 @@ void fx_queue_delete_all(struct fx_queue *q)
|
||||
|
||||
q->q_first = q->q_last = NULL;
|
||||
}
|
||||
|
||||
fx_iterator *fx_queue_begin(struct fx_queue *q)
|
||||
{
|
||||
fx_queue_iterator *it_obj = fx_object_create(FX_TYPE_QUEUE_ITERATOR);
|
||||
struct fx_queue_iterator_p *it
|
||||
= fx_object_get_private(it_obj, FX_TYPE_QUEUE_ITERATOR);
|
||||
|
||||
it->_q = (struct fx_queue *)q;
|
||||
it->entry = q->q_first;
|
||||
it->i = 0;
|
||||
|
||||
if (!it->entry) {
|
||||
fx_iterator_set_status(it_obj, FX_ERR_NO_DATA);
|
||||
}
|
||||
|
||||
return it_obj;
|
||||
}
|
||||
|
||||
static enum fx_status iterator_move_next(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_queue_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_QUEUE_ITERATOR);
|
||||
|
||||
if (!it->entry) {
|
||||
return FX_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
it->entry = it->entry->qe_next;
|
||||
it->i++;
|
||||
|
||||
return (it->entry != NULL) ? FX_SUCCESS : FX_ERR_NO_DATA;
|
||||
}
|
||||
|
||||
static enum fx_status iterator_erase(fx_iterator *obj)
|
||||
{
|
||||
struct fx_queue_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_QUEUE_ITERATOR);
|
||||
|
||||
if (!it->entry) {
|
||||
return FX_ERR_OUT_OF_BOUNDS;
|
||||
}
|
||||
|
||||
struct fx_queue_entry *next = it->entry->qe_next;
|
||||
fx_queue_delete(it->_q, it->entry);
|
||||
it->entry = next;
|
||||
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_iterator_value iterator_get_value(fx_iterator *obj)
|
||||
{
|
||||
struct fx_queue_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_QUEUE_ITERATOR);
|
||||
|
||||
return FX_ITERATOR_VALUE_PTR(it->entry);
|
||||
}
|
||||
|
||||
static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_queue_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_QUEUE_ITERATOR);
|
||||
|
||||
return FX_ITERATOR_VALUE_CPTR(it->entry);
|
||||
}
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_queue_iterator)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
|
||||
FX_INTERFACE_ENTRY(it_erase) = iterator_erase;
|
||||
FX_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
|
||||
FX_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_queue_iterator)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_queue_iterator)
|
||||
FX_TYPE_ID(0x560dc263, 0xff98, 0x4812, 0x9b29, 0xa1218bd70881);
|
||||
FX_TYPE_EXTENDS(FX_TYPE_ITERATOR);
|
||||
FX_TYPE_CLASS(fx_queue_iterator_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_queue_iterator_p);
|
||||
FX_TYPE_DEFINITION_END(fx_queue_iterator)
|
||||
|
||||
+4
-4
@@ -485,11 +485,11 @@ static void ringbuffer_fini(fx_object *obj, void *priv)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_ringbuffer)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_ringbuffer)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_ringbuffer)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_ringbuffer)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_ringbuffer)
|
||||
FX_TYPE_ID(0xb0493774, 0xef13, 0x4905, 0xa865, 0x1595607ccad9);
|
||||
|
||||
+15
-15
@@ -78,7 +78,7 @@ static fx_stream *stdio[] = {
|
||||
|
||||
/*** PRIVATE FUNCTIONS ********************************************************/
|
||||
|
||||
fx_type fx_stdio_stream_get_type(void);
|
||||
fx_type_id fx_stdio_stream_get_type(void);
|
||||
static enum fx_status stdio_read(fx_stream *, void *, size_t, size_t *);
|
||||
static enum fx_status stdio_write(fx_stream *, const void *, size_t, size_t *);
|
||||
static enum fx_status stdio_seek(fx_stream *, long long, fx_stream_seek_origin);
|
||||
@@ -1175,11 +1175,11 @@ static enum fx_status stdio_tell(const fx_stream *stream, size_t *cursor)
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_stream DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_stream)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_stream)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_stream)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_stream)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_stream)
|
||||
FX_TYPE_ID(0xa2c98988, 0x30e5, 0x47c7, 0x88cd, 0x6c8ea79f69cd);
|
||||
@@ -1191,11 +1191,11 @@ FX_TYPE_DEFINITION_BEGIN(fx_stream)
|
||||
FX_TYPE_DEFINITION_END(fx_stream)
|
||||
|
||||
// ---- fx_stream_buffer DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_stream_buffer)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_stream_buffer)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_stream_buffer)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_stream_buffer)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_stream_buffer)
|
||||
FX_TYPE_ID(0x575c7be1, 0x665f, 0x41f8, 0xbfed, 0x6269a2985be0);
|
||||
@@ -1206,12 +1206,12 @@ FX_TYPE_DEFINITION_BEGIN(fx_stream_buffer)
|
||||
FX_TYPE_DEFINITION_END(fx_stream_buffer)
|
||||
|
||||
// ---- fx_stdio_stream DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_stdio_stream)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_stdio_stream)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_stream, FX_TYPE_STREAM)
|
||||
FX_INTERFACE_ENTRY(s_close) = NULL;
|
||||
FX_INTERFACE_ENTRY(s_seek) = stdio_seek;
|
||||
FX_INTERFACE_ENTRY(s_tell) = stdio_tell;
|
||||
@@ -1219,8 +1219,8 @@ FX_TYPE_CLASS_DEFINITION_BEGIN(fx_stdio_stream)
|
||||
FX_INTERFACE_ENTRY(s_read) = stdio_read;
|
||||
FX_INTERFACE_ENTRY(s_write) = stdio_write;
|
||||
FX_INTERFACE_ENTRY(s_reserve) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_stdio_stream)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_CLASS_END(fx_stdio_stream)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_stdio_stream)
|
||||
FX_TYPE_ID(0x67678926, 0xd0b7, 0x4f99, 0xb83c, 0x790927597645);
|
||||
|
||||
+70
-50
@@ -282,8 +282,9 @@ static fx_string *string_duplicate(const struct fx_string_p *str)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_string_p *new_str_p
|
||||
= fx_object_get_private(new_str, FX_TYPE_STRING);
|
||||
struct fx_string_p *new_str_p = fx_object_get_private(
|
||||
new_str,
|
||||
FX_TYPE_STRING);
|
||||
|
||||
string_change_capacity(new_str_p, str->s_len);
|
||||
const char *src = string_ptr(str);
|
||||
@@ -385,8 +386,9 @@ static enum fx_status replace_utf8(
|
||||
}
|
||||
|
||||
size_t new_data_nr_bytes = strlen(new_data);
|
||||
size_t new_data_nr_codepoints
|
||||
= fx_wchar_utf8_codepoint_count(new_data, new_data_nr_bytes);
|
||||
size_t new_data_nr_codepoints = fx_wchar_utf8_codepoint_count(
|
||||
new_data,
|
||||
new_data_nr_bytes);
|
||||
if (new_data_nr_codepoints == 0) {
|
||||
/* new_data is not a valid utf-8 string */
|
||||
return FX_ERR_INVALID_ARGUMENT;
|
||||
@@ -404,8 +406,8 @@ static enum fx_status replace_utf8(
|
||||
return status;
|
||||
}
|
||||
|
||||
size_t new_total_bytes
|
||||
= str->s_len - old_data_nr_bytes + new_data_nr_bytes;
|
||||
size_t new_total_bytes = str->s_len - old_data_nr_bytes
|
||||
+ new_data_nr_bytes;
|
||||
if (new_total_bytes > str->s_max) {
|
||||
status = string_reserve(str, new_total_bytes);
|
||||
}
|
||||
@@ -734,8 +736,9 @@ static enum fx_status string_insert_wstr_ansi(
|
||||
at = dest->s_len;
|
||||
}
|
||||
|
||||
size_t utf8_encoded_size
|
||||
= fx_wchar_utf8_string_encoded_size(src, nr_codepoints);
|
||||
size_t utf8_encoded_size = fx_wchar_utf8_string_encoded_size(
|
||||
src,
|
||||
nr_codepoints);
|
||||
if (utf8_encoded_size == 0) {
|
||||
return FX_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
@@ -782,8 +785,9 @@ static enum fx_status string_insert_wstr_utf8(
|
||||
codepoint_offset = dest->s_codepoints;
|
||||
}
|
||||
|
||||
size_t utf8_encoded_size
|
||||
= fx_wchar_utf8_string_encoded_size(src, nr_codepoints);
|
||||
size_t utf8_encoded_size = fx_wchar_utf8_string_encoded_size(
|
||||
src,
|
||||
nr_codepoints);
|
||||
if (utf8_encoded_size == 0) {
|
||||
return FX_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
@@ -1026,8 +1030,9 @@ static fx_iterator *string_tokenise(
|
||||
}
|
||||
|
||||
fx_string_iterator *it_obj = fx_object_create(FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it
|
||||
= fx_object_get_private(it_obj, FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it = fx_object_get_private(
|
||||
it_obj,
|
||||
FX_TYPE_STRING_ITERATOR);
|
||||
|
||||
it->_m = ITERATOR_MODE_TOKENS;
|
||||
it->_d = delims;
|
||||
@@ -1136,8 +1141,9 @@ static fx_string *string_substr(
|
||||
}
|
||||
|
||||
fx_string *newstr = fx_string_create();
|
||||
struct fx_string_p *newstr_p
|
||||
= fx_object_get_private(newstr, FX_TYPE_STRING);
|
||||
struct fx_string_p *newstr_p = fx_object_get_private(
|
||||
newstr,
|
||||
FX_TYPE_STRING);
|
||||
string_reserve(newstr_p, len);
|
||||
|
||||
const char *src = string_ptr(str) + start;
|
||||
@@ -1304,10 +1310,12 @@ enum fx_status fx_string_insert_s(
|
||||
const fx_string *src,
|
||||
size_t at)
|
||||
{
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
const struct fx_string_p *src_p
|
||||
= fx_object_get_private(src, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p = fx_object_get_private(
|
||||
dest,
|
||||
FX_TYPE_STRING);
|
||||
const struct fx_string_p *src_p = fx_object_get_private(
|
||||
src,
|
||||
FX_TYPE_STRING);
|
||||
return string_insert_s(dest_p, src_p, at);
|
||||
}
|
||||
|
||||
@@ -1316,8 +1324,9 @@ enum fx_status fx_string_insert_cstr(
|
||||
const char *src,
|
||||
size_t at)
|
||||
{
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p = fx_object_get_private(
|
||||
dest,
|
||||
FX_TYPE_STRING);
|
||||
return string_insert_cstr(dest_p, src, strlen(src), at);
|
||||
}
|
||||
|
||||
@@ -1326,8 +1335,9 @@ enum fx_status fx_string_insert_wstr(
|
||||
const fx_wchar *src,
|
||||
size_t at)
|
||||
{
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p = fx_object_get_private(
|
||||
dest,
|
||||
FX_TYPE_STRING);
|
||||
return string_insert_wstr(dest_p, src, fx_wstrlen(src), at);
|
||||
}
|
||||
|
||||
@@ -1337,8 +1347,9 @@ enum fx_status fx_string_insert_cstrf(
|
||||
const char *format,
|
||||
...)
|
||||
{
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p = fx_object_get_private(
|
||||
dest,
|
||||
FX_TYPE_STRING);
|
||||
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
@@ -1365,8 +1376,9 @@ enum fx_status fx_string_insert_cstrn(
|
||||
|
||||
enum fx_status fx_string_append_cstrf(fx_string *dest, const char *format, ...)
|
||||
{
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p = fx_object_get_private(
|
||||
dest,
|
||||
FX_TYPE_STRING);
|
||||
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
@@ -1378,8 +1390,9 @@ enum fx_status fx_string_append_cstrf(fx_string *dest, const char *format, ...)
|
||||
|
||||
enum fx_status fx_string_prepend_cstrf(fx_string *dest, const char *format, ...)
|
||||
{
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p = fx_object_get_private(
|
||||
dest,
|
||||
FX_TYPE_STRING);
|
||||
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
@@ -1545,8 +1558,9 @@ static void string_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
static void iterator_fini(fx_iterator *obj)
|
||||
{
|
||||
struct fx_string_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_TYPE_STRING_ITERATOR);
|
||||
if (it->_tmp) {
|
||||
fx_string_unref(it->_tmp);
|
||||
}
|
||||
@@ -1557,8 +1571,9 @@ static void iterator_fini(fx_iterator *obj)
|
||||
static fx_iterator *iterator_begin(fx_object *obj)
|
||||
{
|
||||
fx_string_iterator *it_obj = fx_object_create(FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it
|
||||
= fx_object_get_private(it_obj, FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it = fx_object_get_private(
|
||||
it_obj,
|
||||
FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_p *p = fx_object_get_private(obj, FX_TYPE_STRING);
|
||||
|
||||
if (!p->s_len) {
|
||||
@@ -1631,8 +1646,9 @@ static enum fx_status tokens_iterator_move_next(struct fx_string_iterator_p *it)
|
||||
|
||||
static enum fx_status iterator_move_next(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_string_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_TYPE_STRING_ITERATOR);
|
||||
|
||||
switch (it->_m) {
|
||||
case ITERATOR_MODE_CHARS:
|
||||
@@ -1658,8 +1674,9 @@ static fx_iterator_value tokens_iterator_get_value(
|
||||
|
||||
static fx_iterator_value iterator_get_value(fx_iterator *obj)
|
||||
{
|
||||
struct fx_string_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_TYPE_STRING_ITERATOR);
|
||||
|
||||
switch (it->_m) {
|
||||
case ITERATOR_MODE_CHARS:
|
||||
@@ -1673,8 +1690,9 @@ static fx_iterator_value iterator_get_value(fx_iterator *obj)
|
||||
|
||||
static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_string_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_TYPE_STRING_ITERATOR);
|
||||
|
||||
switch (it->_m) {
|
||||
case ITERATOR_MODE_CHARS:
|
||||
@@ -1689,19 +1707,20 @@ static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_string DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_string)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_string)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = string_to_string;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_INTERFACE_ENTRY(it_begin) = iterator_begin;
|
||||
FX_INTERFACE_ENTRY(it_cbegin) = iterator_cbegin;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_string)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_END(fx_string)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_string)
|
||||
FX_TYPE_ID(0x200194f6, 0x0327, 0x4a82, 0xb9c9, 0xb62ddd038c33);
|
||||
FX_TYPE_NAME("fx.string");
|
||||
FX_TYPE_IMPLEMENTS(FX_TYPE_ITERABLE);
|
||||
FX_TYPE_CLASS(fx_string_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_string_p);
|
||||
@@ -1710,21 +1729,22 @@ FX_TYPE_DEFINITION_BEGIN(fx_string)
|
||||
FX_TYPE_DEFINITION_END(fx_string)
|
||||
|
||||
// ---- fx_string_iterator DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_string_iterator)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_string_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
|
||||
FX_INTERFACE_ENTRY(it_erase) = NULL;
|
||||
FX_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
|
||||
FX_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_string_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_END(fx_string_iterator)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_string_iterator)
|
||||
FX_TYPE_ID(0xfc06cee1, 0xb63a, 0x4718, 0x9b8e, 0x3bd2eb7a8608);
|
||||
FX_TYPE_NAME("fx.string.iterator");
|
||||
FX_TYPE_EXTENDS(FX_TYPE_ITERATOR);
|
||||
FX_TYPE_CLASS(fx_string_iterator_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_string_iterator_p);
|
||||
|
||||
+6
-6
@@ -302,12 +302,12 @@ enum fx_status stream_write(
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_stringstream)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_stringstream)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_stream, FX_TYPE_STREAM)
|
||||
FX_INTERFACE_ENTRY(s_close) = NULL;
|
||||
FX_INTERFACE_ENTRY(s_seek) = NULL;
|
||||
FX_INTERFACE_ENTRY(s_tell) = NULL;
|
||||
@@ -315,8 +315,8 @@ FX_TYPE_CLASS_DEFINITION_BEGIN(fx_stringstream)
|
||||
FX_INTERFACE_ENTRY(s_read) = stream_read;
|
||||
FX_INTERFACE_ENTRY(s_write) = stream_write;
|
||||
FX_INTERFACE_ENTRY(s_reserve) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_stringstream)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_stream, FX_TYPE_STREAM)
|
||||
FX_TYPE_CLASS_END(fx_stringstream)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_stringstream)
|
||||
FX_TYPE_ID(0x508a609a, 0xfac5, 0x4d31, 0x843a, 0x44b68ad329f3);
|
||||
|
||||
@@ -11,36 +11,35 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static struct fx_bst type_list = FX_BST_INIT;
|
||||
static union fx_type zero_id = {0};
|
||||
static struct fx_bst type_idmap = FX_BST_INIT;
|
||||
static struct fx_namemap type_namemap = FX_NAMEMAP_INIT;
|
||||
static union fx_type_id zero_id = {0};
|
||||
|
||||
struct type_init_ctx {
|
||||
size_t ctx_class_offset;
|
||||
size_t ctx_instance_offset;
|
||||
};
|
||||
|
||||
static inline int registration_compare(
|
||||
const struct fx_type_registration *a,
|
||||
const struct fx_type_registration *b)
|
||||
static inline int type_info_compare(
|
||||
const struct fx_type_info *a,
|
||||
const struct fx_type_info *b)
|
||||
{
|
||||
return fx_type_id_compare(&a->r_info->t_id, &b->r_info->t_id);
|
||||
return fx_type_id_compare(&a->ty_id, &b->ty_id);
|
||||
}
|
||||
|
||||
static inline int component_compare(
|
||||
const struct fx_type_component *a,
|
||||
const struct fx_type_component *b)
|
||||
{
|
||||
return fx_type_id_compare(
|
||||
&a->c_type->r_info->t_id,
|
||||
&b->c_type->r_info->t_id);
|
||||
return fx_type_id_compare(&a->c_type->ty_id, &b->c_type->ty_id);
|
||||
}
|
||||
|
||||
FX_BST_DEFINE_INSERT(
|
||||
struct fx_type_registration,
|
||||
r_node,
|
||||
r_info->r_id,
|
||||
struct fx_type_info,
|
||||
ty_idmap_node,
|
||||
ty_id,
|
||||
put_type,
|
||||
registration_compare)
|
||||
type_info_compare)
|
||||
FX_BST_DEFINE_INSERT(
|
||||
struct fx_type_component,
|
||||
c_node,
|
||||
@@ -48,15 +47,17 @@ FX_BST_DEFINE_INSERT(
|
||||
put_type_component,
|
||||
component_compare)
|
||||
|
||||
static struct fx_type_registration *get_type(
|
||||
static struct fx_type_info *get_type(
|
||||
const fx_bst *tree,
|
||||
const union fx_type *key)
|
||||
const union fx_type_id *key)
|
||||
{
|
||||
fx_bst_node *cur = tree->bst_root;
|
||||
while (cur) {
|
||||
struct fx_type_registration *cur_node
|
||||
= fx_unbox(struct fx_type_registration, cur, r_node);
|
||||
int cmp = fx_type_id_compare(key, &cur_node->r_info->t_id);
|
||||
struct fx_type_info *cur_node = fx_unbox(
|
||||
struct fx_type_info,
|
||||
cur,
|
||||
ty_idmap_node);
|
||||
int cmp = fx_type_id_compare(key, &cur_node->ty_id);
|
||||
|
||||
if (cmp > 0) {
|
||||
cur = fx_bst_right(cur);
|
||||
@@ -72,15 +73,15 @@ static struct fx_type_registration *get_type(
|
||||
|
||||
struct fx_type_component *fx_type_get_component(
|
||||
const fx_bst *tree,
|
||||
const union fx_type *key)
|
||||
const union fx_type_id *key)
|
||||
{
|
||||
fx_bst_node *cur = tree->bst_root;
|
||||
while (cur) {
|
||||
struct fx_type_component *cur_node
|
||||
= fx_unbox(struct fx_type_component, cur, c_node);
|
||||
int cmp = fx_type_id_compare(
|
||||
key,
|
||||
&cur_node->c_type->r_info->t_id);
|
||||
struct fx_type_component *cur_node = fx_unbox(
|
||||
struct fx_type_component,
|
||||
cur,
|
||||
c_node);
|
||||
int cmp = fx_type_id_compare(key, &cur_node->c_type->ty_id);
|
||||
|
||||
if (cmp > 0) {
|
||||
cur = fx_bst_right(cur);
|
||||
@@ -95,7 +96,7 @@ struct fx_type_component *fx_type_get_component(
|
||||
}
|
||||
|
||||
static struct fx_type_component *create_type_component(
|
||||
const struct fx_type_registration *type_reg)
|
||||
const struct fx_type_info *type_reg)
|
||||
{
|
||||
struct fx_type_component *c = malloc(sizeof *c);
|
||||
if (!c) {
|
||||
@@ -110,7 +111,7 @@ static struct fx_type_component *create_type_component(
|
||||
}
|
||||
|
||||
void fx_type_id_init(
|
||||
union fx_type *out,
|
||||
union fx_type_id *out,
|
||||
uint32_t a,
|
||||
uint16_t b,
|
||||
uint16_t c,
|
||||
@@ -136,31 +137,33 @@ static void initialise_type_component(
|
||||
struct type_init_ctx *init_ctx)
|
||||
{
|
||||
comp->c_class_data_offset = init_ctx->ctx_class_offset;
|
||||
comp->c_class_data_size = info->t_class_size;
|
||||
comp->c_class_data_size = info->ty_class_private_size;
|
||||
init_ctx->ctx_class_offset += comp->c_class_data_size;
|
||||
|
||||
comp->c_instance_private_data_offset = init_ctx->ctx_instance_offset;
|
||||
comp->c_instance_private_data_size = info->t_instance_private_size;
|
||||
comp->c_instance_private_data_size = info->ty_instance_private_size;
|
||||
init_ctx->ctx_instance_offset += comp->c_instance_private_data_size;
|
||||
|
||||
comp->c_instance_protected_data_offset = init_ctx->ctx_instance_offset;
|
||||
comp->c_instance_protected_data_size = info->t_instance_protected_size;
|
||||
comp->c_instance_protected_data_size = info->ty_instance_protected_size;
|
||||
init_ctx->ctx_instance_offset += comp->c_instance_protected_data_size;
|
||||
}
|
||||
|
||||
static fx_result locate_interface(
|
||||
fx_type interface_id,
|
||||
struct fx_type_registration *dest,
|
||||
fx_type_id interface_id,
|
||||
struct fx_type_info *dest,
|
||||
struct type_init_ctx *init_ctx)
|
||||
{
|
||||
struct fx_type_component *interface_comp
|
||||
= fx_type_get_component(&dest->r_components, interface_id);
|
||||
struct fx_type_component *interface_comp = fx_type_get_component(
|
||||
&dest->ty_components,
|
||||
interface_id);
|
||||
if (interface_comp) {
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
struct fx_type_registration *interface_reg
|
||||
= get_type(&type_list, interface_id);
|
||||
struct fx_type_info *interface_reg = get_type(
|
||||
&type_idmap,
|
||||
interface_id);
|
||||
if (!interface_reg) {
|
||||
return FX_RESULT_ERR(NO_ENTRY);
|
||||
}
|
||||
@@ -170,24 +173,21 @@ static fx_result locate_interface(
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
|
||||
initialise_type_component(
|
||||
interface_comp,
|
||||
interface_reg->r_info,
|
||||
init_ctx);
|
||||
initialise_type_component(interface_comp, interface_reg, init_ctx);
|
||||
|
||||
put_type_component(&dest->r_components, interface_comp);
|
||||
put_type_component(&dest->ty_components, interface_comp);
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
static fx_result locate_interfaces(
|
||||
const union fx_type *interfaces,
|
||||
const union fx_type_id *interfaces,
|
||||
size_t nr_interfaces,
|
||||
struct fx_type_registration *dest,
|
||||
struct fx_type_info *dest,
|
||||
struct type_init_ctx *init_ctx)
|
||||
{
|
||||
fx_result result = FX_RESULT_SUCCESS;
|
||||
for (size_t i = 0; i < nr_interfaces; i++) {
|
||||
fx_type interface_id = &interfaces[i];
|
||||
fx_type_id interface_id = &interfaces[i];
|
||||
result = locate_interface(interface_id, dest, init_ctx);
|
||||
|
||||
if (fx_result_is_error(result)) {
|
||||
@@ -198,10 +198,10 @@ static fx_result locate_interfaces(
|
||||
return result;
|
||||
}
|
||||
|
||||
static fx_result find_type_components(struct fx_type_registration *reg)
|
||||
static fx_result find_type_components(struct fx_type_info *type)
|
||||
{
|
||||
const struct fx_type_info *current = reg->r_info;
|
||||
struct fx_type_component *comp = create_type_component(reg);
|
||||
const struct fx_type_info *current = type;
|
||||
struct fx_type_component *comp = create_type_component(current);
|
||||
if (!comp) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
}
|
||||
@@ -211,147 +211,149 @@ static fx_result find_type_components(struct fx_type_registration *reg)
|
||||
.ctx_class_offset = sizeof(struct _fx_class),
|
||||
};
|
||||
|
||||
put_type_component(®->r_components, comp);
|
||||
fx_queue_push_front(®->r_class_hierarchy, &comp->c_entry);
|
||||
put_type_component(&type->ty_components, comp);
|
||||
fx_queue_push_front(&type->ty_class_hierarchy, &comp->c_entry);
|
||||
|
||||
fx_result result = locate_interfaces(
|
||||
current->t_interfaces,
|
||||
current->t_nr_interfaces,
|
||||
reg,
|
||||
current->ty_interfaces,
|
||||
current->ty_nr_interfaces,
|
||||
type,
|
||||
&init_ctx);
|
||||
|
||||
if (fx_result_is_error(result)) {
|
||||
return result;
|
||||
}
|
||||
|
||||
fx_type current_id = ¤t->t_parent_id;
|
||||
fx_type_id current_id = ¤t->ty_parent_id;
|
||||
if (!current_id || fx_type_id_compare(current_id, &zero_id) == 0) {
|
||||
goto skip_class_hierarchy;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
struct fx_type_registration *dep_class
|
||||
= get_type(&type_list, current_id);
|
||||
struct fx_type_info *dep_class = get_type(
|
||||
&type_idmap,
|
||||
current_id);
|
||||
if (!dep_class) {
|
||||
return FX_RESULT_ERR(NO_ENTRY);
|
||||
}
|
||||
|
||||
comp = fx_type_get_component(®->r_components, current_id);
|
||||
comp = fx_type_get_component(&type->ty_components, current_id);
|
||||
if (comp) {
|
||||
/* circular class dependency */
|
||||
// result = FX_RESULT_ERR(INVALID_ARGUMENT);
|
||||
// break;
|
||||
current_id = &dep_class->r_info->t_parent_id;
|
||||
current_id = &dep_class->ty_parent_id;
|
||||
continue;
|
||||
}
|
||||
|
||||
comp = create_type_component(dep_class);
|
||||
|
||||
result = locate_interfaces(
|
||||
dep_class->r_info->t_interfaces,
|
||||
dep_class->r_info->t_nr_interfaces,
|
||||
reg,
|
||||
dep_class->ty_interfaces,
|
||||
dep_class->ty_nr_interfaces,
|
||||
type,
|
||||
&init_ctx);
|
||||
if (fx_result_is_error(result)) {
|
||||
break;
|
||||
}
|
||||
|
||||
put_type_component(®->r_components, comp);
|
||||
fx_queue_push_front(®->r_class_hierarchy, &comp->c_entry);
|
||||
put_type_component(&type->ty_components, comp);
|
||||
fx_queue_push_front(&type->ty_class_hierarchy, &comp->c_entry);
|
||||
|
||||
if (fx_type_id_compare(current_id, FX_TYPE_OBJECT) == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
current_id = &dep_class->r_info->t_parent_id;
|
||||
current_id = &dep_class->ty_parent_id;
|
||||
}
|
||||
|
||||
fx_queue_entry *entry = fx_queue_first(®->r_class_hierarchy);
|
||||
fx_queue_entry *entry = fx_queue_first(&type->ty_class_hierarchy);
|
||||
while (entry) {
|
||||
comp = fx_unbox(struct fx_type_component, entry, c_entry);
|
||||
initialise_type_component(
|
||||
comp,
|
||||
comp->c_type->r_info,
|
||||
&init_ctx);
|
||||
initialise_type_component(comp, comp->c_type, &init_ctx);
|
||||
entry = fx_queue_next(entry);
|
||||
}
|
||||
|
||||
fx_bst_node *node = fx_bst_first(®->r_components);
|
||||
fx_bst_node *node = fx_bst_first(&type->ty_components);
|
||||
while (node) {
|
||||
comp = fx_unbox(struct fx_type_component, node, c_node);
|
||||
if (comp->c_type->r_category == FX_TYPE_CLASS) {
|
||||
if (comp->c_type->ty_category == FX_TYPE_CLASS) {
|
||||
/* this component was already initialised above */
|
||||
node = fx_bst_next(node);
|
||||
continue;
|
||||
}
|
||||
|
||||
initialise_type_component(
|
||||
comp,
|
||||
comp->c_type->r_info,
|
||||
&init_ctx);
|
||||
initialise_type_component(comp, comp->c_type, &init_ctx);
|
||||
node = fx_bst_next(node);
|
||||
}
|
||||
|
||||
skip_class_hierarchy:
|
||||
reg->r_instance_size = init_ctx.ctx_instance_offset;
|
||||
reg->r_class_size = init_ctx.ctx_class_offset;
|
||||
type->ty_instance_size = init_ctx.ctx_instance_offset;
|
||||
type->ty_class_size = init_ctx.ctx_class_offset;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool type_has_base_class(struct fx_type_info *info)
|
||||
{
|
||||
if (fx_type_id_compare(&info->t_id, FX_TYPE_OBJECT) == 0) {
|
||||
if (fx_type_id_compare(&info->ty_id, FX_TYPE_OBJECT) == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return fx_type_id_compare(&info->t_parent_id, &zero_id) != 0;
|
||||
return fx_type_id_compare(&info->ty_parent_id, &zero_id) != 0;
|
||||
}
|
||||
|
||||
fx_result fx_type_register(struct fx_type_info *info)
|
||||
{
|
||||
if (!type_has_base_class(info)) {
|
||||
fx_type_id_copy(FX_TYPE_OBJECT, &info->t_parent_id);
|
||||
fx_type_id_copy(FX_TYPE_OBJECT, &info->ty_parent_id);
|
||||
}
|
||||
|
||||
struct fx_type_registration *r = get_type(&type_list, &info->t_id);
|
||||
if (r) {
|
||||
if (get_type(&type_idmap, &info->ty_id)) {
|
||||
return FX_RESULT_ERR(NAME_EXISTS);
|
||||
}
|
||||
|
||||
r = malloc(sizeof *r);
|
||||
if (!r) {
|
||||
return FX_RESULT_ERR(NO_MEMORY);
|
||||
if (fx_namemap_get(&type_namemap, info->ty_name)) {
|
||||
return FX_RESULT_ERR(NAME_EXISTS);
|
||||
}
|
||||
|
||||
memset(r, 0x0, sizeof *r);
|
||||
info->ty_category = FX_TYPE_CLASS;
|
||||
|
||||
r->r_category = FX_TYPE_CLASS;
|
||||
r->r_info = info;
|
||||
union fx_type_id metatype = {0};
|
||||
|
||||
fx_result result = find_type_components(r);
|
||||
fx_result result = find_type_components(info);
|
||||
if (fx_result_is_error(result)) {
|
||||
free(r);
|
||||
return fx_result_propagate(result);
|
||||
}
|
||||
|
||||
result = fx_class_instantiate(r, &r->r_class);
|
||||
if (!r->r_class) {
|
||||
free(r);
|
||||
result = fx_class_instantiate(info, &info->ty_class);
|
||||
if (!info->ty_class) {
|
||||
return fx_error_with_msg_template_caused_by_error(
|
||||
FX_ERRORS_BUILTIN,
|
||||
FX_ERR_TYPE_REGISTRATION_FAILURE,
|
||||
result,
|
||||
FX_MSG_TYPE_REGISTRATION_FAILURE,
|
||||
FX_ERROR_PARAM("typename", info->t_name));
|
||||
FX_ERROR_PARAM("typename", info->ty_name));
|
||||
}
|
||||
|
||||
put_type(&type_list, r);
|
||||
put_type(&type_idmap, info);
|
||||
fx_namemap_put(&type_namemap, info->ty_name, &info->ty_namemap_entry);
|
||||
info->ty_metatype = __fx_type_create(info);
|
||||
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
struct fx_type_registration *fx_type_get_registration(fx_type id)
|
||||
struct fx_type_info *fx_type_info_get_by_id(const union fx_type_id *key)
|
||||
{
|
||||
return get_type(&type_list, id);
|
||||
return get_type(&type_idmap, key);
|
||||
}
|
||||
|
||||
struct fx_type_info *fx_type_info_get_by_name(const char *name)
|
||||
{
|
||||
fx_namemap_entry *entry = fx_namemap_get(&type_namemap, name);
|
||||
if (!entry) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return fx_unbox(struct fx_type_info, entry, ty_namemap_entry);
|
||||
}
|
||||
|
||||
@@ -2,41 +2,32 @@
|
||||
#define _TYPE_H_
|
||||
|
||||
#include <fx/bst.h>
|
||||
#include <fx/namemap.h>
|
||||
#include <fx/queue.h>
|
||||
#include <fx/reflection/type.h>
|
||||
#include <fx/type.h>
|
||||
#include <stddef.h>
|
||||
|
||||
enum fx_type_category {
|
||||
FX_TYPE_NONE = 0,
|
||||
FX_TYPE_CLASS,
|
||||
FX_TYPE_INTERFACE,
|
||||
};
|
||||
|
||||
struct fx_type_component {
|
||||
struct fx_bst_node c_node;
|
||||
struct fx_queue_entry c_entry;
|
||||
const struct fx_type_registration *c_type;
|
||||
const struct fx_type_info *c_type;
|
||||
|
||||
size_t c_class_data_offset, c_class_data_size;
|
||||
size_t c_instance_private_data_offset, c_instance_private_data_size;
|
||||
size_t c_instance_protected_data_offset, c_instance_protected_data_size;
|
||||
};
|
||||
|
||||
struct fx_type_registration {
|
||||
enum fx_type_category r_category;
|
||||
const char *r_name;
|
||||
struct fx_bst_node r_node;
|
||||
const fx_type_info *r_info;
|
||||
struct _fx_class *r_class;
|
||||
struct fx_bst r_components;
|
||||
struct fx_queue r_class_hierarchy;
|
||||
|
||||
size_t r_instance_size, r_class_size;
|
||||
struct fx_type_function {
|
||||
struct fx_namemap_entry f_entry;
|
||||
struct fx_function *f_func;
|
||||
};
|
||||
|
||||
extern struct fx_type_registration *fx_type_get_registration(fx_type id);
|
||||
extern struct fx_type_registration *fx_type_get_registration(fx_type_id id);
|
||||
extern struct fx_type_component *fx_type_get_component(
|
||||
const fx_bst *tree,
|
||||
const union fx_type *key);
|
||||
const union fx_type_id *key);
|
||||
extern struct fx_type_info *fx_type_info_get_by_id(const union fx_type_id *key);
|
||||
extern struct fx_type_info *fx_type_info_get_by_name(const char *name);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -159,11 +159,11 @@ static void uint_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_uint)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_uint)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = uint_to_string;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_uint)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_uint)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_uint)
|
||||
FX_TYPE_ID(0x79aee484, 0x5dd5, 0x463a, 0xb0c8, 0x60873abdf088);
|
||||
|
||||
@@ -239,11 +239,11 @@ static void uuid_to_string(const fx_object *uuid, fx_stream *out)
|
||||
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_uuid)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_uuid)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = uuid_to_string;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_uuid)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_END(fx_uuid)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_uuid)
|
||||
FX_TYPE_ID(0x17037068, 0x92f7, 0x4582, 0xad1f, 0x0dea43b628de);
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
#include <fx/uint.h>
|
||||
#include <fx/value.h>
|
||||
|
||||
void fx_value_init(fx_value *v, fx_type type)
|
||||
void fx_value_init(fx_value *v, fx_type_id type)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ bool fx_value_is_pointer(const fx_value *v)
|
||||
return (v->v_type.t_primitive == FX_VALUE_TYPE_POINTER);
|
||||
}
|
||||
|
||||
bool fx_value_is_object(const fx_value *v, fx_type type)
|
||||
bool fx_value_is_object(const fx_value *v, fx_type_id type)
|
||||
{
|
||||
if (v->v_type.t_primitive > __FX_VALUE_TYPE_OBJECT_BOUNDARY) {
|
||||
if (fx_type_id_compare(v->v_type.t_object, type)) {
|
||||
|
||||
Reference in New Issue
Block a user