meta: rename to fx

This commit is contained in:
2026-03-16 10:35:43 +00:00
parent 84df46489a
commit e9d0e323f0
233 changed files with 12875 additions and 12869 deletions
View File
+218
View File
@@ -0,0 +1,218 @@
/**
* A heterogeneous array of objects. fx_array only stores references
* to the objects that it contains, not the object data itself.
*
* fx_array stores pointers to objects in a single contiguous array,
* but this is an implementation detail that may change in the future.
* Users of fx_array should not rely on this being the case.
*/
#ifndef FX_DS_ARRAY_H_
#define FX_DS_ARRAY_H_
#include <fx/core/iterator.h>
#include <fx/core/macros.h>
#include <fx/core/misc.h>
#include <fx/core/status.h>
FX_DECLS_BEGIN;
#define FX_TYPE_ARRAY (fx_array_get_type())
#define FX_TYPE_ARRAY_ITERATOR (fx_array_iterator_get_type())
struct fx_array_p;
FX_DECLARE_TYPE(fx_array);
FX_DECLARE_TYPE(fx_array_iterator);
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_array)
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_TYPE_DEFAULT_CONSTRUCTOR(fx_array, FX_TYPE_ARRAY);
/**
* Creates an fx_array initialised with the contents of the provided
* fx_object pointer array. The fx_array will take a reference to each
* object specified in `values`, and will increment the reference count.
* The order of objects in the new fx_array will be the same as the order
* of objects in `values`. Any NULL pointers in the `values` array will
* be ignored, and will not result in gaps in the created fx_array.
* However, `nr_values` should be large enough to cover the final
* non-NULL pointer in `values`, including any NULL pointers in-between.
*
* @param values The list of object pointers which should make up the
* contents of the new fx_array.
* @param nr_values The size of the `values` array.
* @return A pointer to the new fx_array, or NULL if an error occurred.
*/
FX_API fx_array *fx_array_create_with_values(
fx_object *const *values, size_t nr_values);
/**
* Remove all object references from an fx_array, resetting the size of the array to zero.
* The reference counts of all objects in the array will be decremented.
*
* @param array The fx_array to clear.
*/
FX_API void fx_array_clear(fx_array *array);
/**
* Inserts an object at the end of an fx_array. The reference count of
* the object will be incremented.
*
* @param array The fx_array to append the object to.
* @param value The object to append.
* @return FX_SUCCESS if the object was appended successfully, or an
* error code if an error occurred.
*/
FX_API fx_status fx_array_append(fx_array *array, fx_object *value);
/**
* Inserts an object at the beginning of an fx_array. The reference count
* of the object will be incremented. All other objects in the array
* will be moved to make space for the object being pre-pended.
*
* @param array The fx_array to prepend the object to.
* @param value The object to prepend.
* @return FX_SUCCESS if the object was prepended successfully, or an
* error code if an error occurred.
*/
FX_API fx_status fx_array_prepend(fx_array *array, fx_object *value);
/**
* Inserts an object into an fx_array at a given index. The reference
* count of the object will be incremented. If the specified index is at
* the beginning or mid-way through the array (i.e. not at the end),
* some or all of the objects already in the array will be moved to make
* space for the object being inserted.
*
* @param array The fx_array to insert the object into.
* @param value The object to insert.
* @param at The index to insert the object at. If the index is
* `FX_NPOS`, the object will be inserted at the end of the fx_array.
* @return FX_SUCCESS if the object was inserted, or a status code
* describing any error that occurred.
*/
FX_API fx_status fx_array_insert(fx_array *array, fx_object *value, size_t at);
/**
* Removes the object at the specified index from an fx_array. The
* reference count of the removed object will be decremented. If the
* specified index is at the beginning or mid-way through the array
* (i.e. not at the end), the remaining objects will be moved to fill
* the empty space created by the object's removal.
*
* @param array The fx_array to remove the object from.
* @param at The index of the object to be removed.
* @return FX_SUCCESS if the object was removed, or a status code
* describing any error that occurred.
*/
FX_API fx_status fx_array_remove(fx_array *array, size_t at);
/**
* Removes the object at the beginning of an fx_array. The reference count
* of the removed object will be decremented. The remaining objects will be moved
* to fill the empty space created by the object's removal.
*
* @param array The fx_array to remove the object from.
* @return FX_SUCCESS if the object was removed, or a status code describing any error that occurred.
*/
FX_API fx_status fx_array_remove_front(fx_array *array);
/**
* Removes the object at the end of an fx_array. The reference count
* of the removed object will be decremented.
*
* @param array The fx_array to remove the object from.
* @return FX_SUCCESS if the object was removed, or a status code describing any error that occurred.
*/
FX_API fx_status fx_array_remove_back(fx_array *array);
/**
* Removes the object at the specified index of an fx_array, and returns
* a pointer to it. The reference count of the removed object will NOT
* be decremented. The caller becomes the owner of the array's reference
* to the object. If the specified index is at the beginning or mid-way
* through the array (i.e. not at the end), the remaining objects will
* be moved to fill the empty space created by the object's removal.
*
* @param array The fx_array to remove the object from.
* @param at The index of the object to be removed.
* @return An pointer to the removed object. This pointer is owned by
* the caller. Returns NULL if an error occurred.
*/
FX_API fx_object *fx_array_pop(fx_array *array, size_t at);
/**
* Removes the object at the beginning of an fx_array, and returns a
* pointer to it. The reference count of the removed object will NOT be
* decremented. The caller becomes the owner of the array's reference to
* the object. The remaining objects in the fx_array will be moved to
* fill the empty space left by the removed object.
*
* @param array The fx_array to remove the object from.
* @return An pointer to the removed object. This pointer is owned by
* the caller. Returns NULL if an error occurred.
*/
FX_API fx_object *fx_array_pop_front(fx_array *array);
/**
* Removes the object at the end of an fx_array, and returns a pointer to it. The
* reference count of the removed object will NOT be decremented. The caller
* becomes the owner of the array's reference to the object.
*
* @param array The fx_array to remove the object from.
* @return An pointer to the removed object. This pointer is owned by the
* caller. Returns NULL if an error occurred.
*/
FX_API fx_object *fx_array_pop_back(fx_array *array);
/**
* Returns an unowned pointer to the object at the given index of an fx_array.
* The caller does not own the returned pointer, and MUST NOT release it.
*
* @param array The fx_array.
* @param at The index of the object to return.
* @return A pointer to the object at the given index. This pointer is NOT owned
* by the caller. Returns NULL if an error occurred.
*/
FX_API fx_object *fx_array_at(const fx_array *array, size_t at);
/**
* Returns an owned pointer to the object at the given index of an
* fx_array. The caller owns the returned pointer, and must release it
* when they are finished with it.
*
* @param array The fx_array.
* @param at The index of the object to return.
* @return A pointer to the object at the given index. This pointer is
* owned by the caller. Returns NULL if an error occurred.
*/
FX_API fx_object *fx_array_get(fx_array *array, size_t at);
/**
* Returns the number of objects contained in an fx_array.
*
* @param array The fx_array.
* @return The number of objects contained in the fx_array.
*/
FX_API size_t fx_array_size(const fx_array *array);
/**
* Returns the current maximum capacity of an fx_array. This represents
* the number of objects that can be stored in an fx_array before its
* internal buffer would need to be re-sized.
*
* @param array The fx_array.
* @return The maximum capacity of the fx_array.
*/
FX_API size_t fx_array_capacity(const fx_array *array);
FX_DECLS_END;
#endif
+25
View File
@@ -0,0 +1,25 @@
#ifndef FX_DS_BITBUFFER_H_
#define FX_DS_BITBUFFER_H_
#include <fx/core/macros.h>
FX_DECLS_BEGIN;
FX_DECLARE_TYPE(fx_bitbuffer);
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_bitbuffer)
;
FX_TYPE_CLASS_DECLARATION_END(fx_bitbuffer);
FX_API fx_status fx_bitbuffer_put_bit(fx_bitbuffer *buf, int bit);
FX_API fx_status fx_bitbuffer_put_bool(fx_bitbuffer *buf, bool b);
FX_API fx_status fx_bitbuffer_put_int(
fx_bitbuffer *buf, uint64_t v, unsigned int nr_bits);
FX_API fx_status fx_bitbuffer_put_bytes(
fx_bitbuffer *buf, const void *p, size_t len, size_t bits_per_byte);
FX_API fx_status fx_bitbuffer_put_string(
fx_bitbuffer *buf, const char *p, size_t len, size_t bits_per_char);
FX_DECLS_END;
#endif
+40
View File
@@ -0,0 +1,40 @@
#ifndef FX_DS_BITMAP_H_
#define FX_DS_BITMAP_H_
#include <fx/core/macros.h>
#include <fx/core/misc.h>
#include <stdbool.h>
FX_DECLS_BEGIN;
#define FX_TYPE_BITMAP (fx_bitmap_get_type())
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_bitmap *fx_bitmap_create(size_t nr_bits);
FX_API void fx_bitmap_set_bit(fx_bitmap *map, size_t bit);
FX_API void fx_bitmap_clear_bit(fx_bitmap *map, size_t bit);
FX_API void fx_bitmap_set_range(fx_bitmap *map, size_t first_bit, size_t nbits);
FX_API void fx_bitmap_clear_range(fx_bitmap *map, size_t first_bit, size_t nbits);
FX_API void fx_bitmap_set_all(fx_bitmap *map);
FX_API void fx_bitmap_clear_all(fx_bitmap *map);
FX_API bool fx_bitmap_check_bit(const fx_bitmap *map, size_t bit);
FX_API size_t fx_bitmap_count_set_bits(const fx_bitmap *map);
FX_API size_t fx_bitmap_count_clear_bits(const fx_bitmap *map);
FX_API size_t fx_bitmap_highest_set_bit(const fx_bitmap *map);
FX_API size_t fx_bitmap_highest_clear_bit(const fx_bitmap *map);
FX_API size_t fx_bitmap_lowest_set_bit(const fx_bitmap *map);
FX_API size_t fx_bitmap_lowest_clear_bit(const fx_bitmap *map);
FX_DECLS_END;
#endif
+49
View File
@@ -0,0 +1,49 @@
#ifndef FX_DS_BUFFER_H_
#define FX_DS_BUFFER_H_
#include <fx/core/macros.h>
#include <stddef.h>
FX_DECLS_BEGIN;
#define FX_TYPE_BUFFER (fx_buffer_get_type())
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_buffer *fx_buffer_create(size_t item_sz);
FX_API fx_buffer *fx_buffer_create_from_bytes(const void *p, size_t len);
FX_API fx_buffer *fx_buffer_create_from_array(
const void *p, size_t item_sz, size_t len);
FX_API void *fx_buffer_steal(fx_buffer *buf);
FX_API fx_status fx_buffer_reserve(fx_buffer *buf, size_t capacity);
FX_API fx_status fx_buffer_resize(fx_buffer *buf, size_t length);
FX_API fx_status fx_buffer_append(fx_buffer *dest, const void *p, size_t count);
FX_API fx_status fx_buffer_prepend(fx_buffer *dest, const void *p, size_t count);
FX_API fx_status fx_buffer_insert(
fx_buffer *dest, const void *p, size_t count, size_t at);
FX_API fx_status fx_buffer_remove(fx_buffer *dest, size_t at, size_t count);
FX_API fx_status fx_buffer_clear(fx_buffer *buf);
FX_API fx_status fx_buffer_push_back(fx_buffer *buf, size_t count, void **p);
FX_API fx_status fx_buffer_push_front(fx_buffer *buf, size_t count, void **p);
FX_API fx_status fx_buffer_pop_back(fx_buffer *buf, size_t count);
FX_API fx_status fx_buffer_pop_front(fx_buffer *buf, size_t count);
FX_API size_t fx_buffer_get_size(const fx_buffer *buf);
FX_API size_t fx_buffer_get_item_size(const fx_buffer *buf);
FX_API size_t fx_buffer_get_capacity(const fx_buffer *buf);
FX_API void *fx_buffer_ptr(const fx_buffer *buf);
FX_API void *fx_buffer_get(const fx_buffer *buf, size_t at);
FX_DECLS_END;
#endif
+48
View File
@@ -0,0 +1,48 @@
#ifndef FX_DS_DATETIME_H_
#define FX_DS_DATETIME_H_
#include <fx/core/macros.h>
#include <fx/core/status.h>
#include <ctype.h>
FX_DECLS_BEGIN;
#define FX_TYPE_DATETIME (fx_datetime_get_type())
FX_DECLARE_TYPE(fx_datetime);
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_datetime)
FX_TYPE_CLASS_DECLARATION_END(fx_datetime)
typedef enum fx_datetime_format {
FX_DATETIME_FORMAT_RFC3339 = 1,
} fx_datetime_format;
FX_API fx_type fx_datetime_get_type(void);
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_datetime, FX_TYPE_DATETIME);
FX_API fx_datetime *fx_datetime_parse(fx_datetime_format format, const char *s);
FX_API void fx_datetime_to_string(
const fx_datetime *dt, fx_datetime_format format,
FX_TYPE_FWDREF(fx_stream) * dest);
FX_API bool fx_datetime_is_localtime(const fx_datetime *dt);
FX_API bool fx_datetime_has_date(const fx_datetime *dt);
FX_API bool fx_datetime_has_time(const fx_datetime *dt);
FX_API long fx_datetime_year(const fx_datetime *dt);
FX_API long fx_datetime_month(const fx_datetime *dt);
FX_API long fx_datetime_day(const fx_datetime *dt);
FX_API long fx_datetime_hour(const fx_datetime *dt);
FX_API long fx_datetime_minute(const fx_datetime *dt);
FX_API long fx_datetime_second(const fx_datetime *dt);
FX_API long fx_datetime_subsecond(const fx_datetime *dt);
FX_API bool fx_datetime_zone_offset_is_negative(const fx_datetime *dt);
FX_API long fx_datetime_zone_offset_hour(const fx_datetime *dt);
FX_API long fx_datetime_zone_offset_minute(const fx_datetime *dt);
FX_DECLS_END;
#endif
+62
View File
@@ -0,0 +1,62 @@
#ifndef FX_DS_DICT_H_
#define FX_DS_DICT_H_
#include <fx/core/btree.h>
#include <fx/core/macros.h>
#include <fx/core/misc.h>
#include <fx/core/queue.h>
#include <fx/core/status.h>
#include <fx/ds/string.h>
FX_DECLS_BEGIN;
#define FX_TYPE_DICT (fx_dict_get_type())
#define FX_TYPE_DICT_ITERATOR (fx_dict_iterator_get_type())
struct fx_dict_p;
FX_DECLARE_TYPE(fx_dict);
FX_DECLARE_TYPE(fx_dict_iterator);
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_dict)
FX_TYPE_CLASS_DECLARATION_END(fx_dict)
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_dict_iterator)
FX_TYPE_CLASS_DECLARATION_END(fx_dict_iterator)
#define FX_DICT_ITEM(k, v) {.key = (k), .value = (v)}
#define FX_DICT_ITEM_END {.key = NULL, .value = NULL}
#define fx_dict_foreach(it, dict) \
for (int z__fx_unique_name() = fx_dict_iterator_begin(dict, it); \
(it)->key != NULL; fx_dict_iterator_next(it))
typedef struct fx_dict_item {
const fx_string *key;
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_TYPE_DEFAULT_CONSTRUCTOR(fx_dict, FX_TYPE_DICT);
#if 0
FX_API fx_dict *fx_dict_create_with_items(const fx_dict_item *items);
#endif
FX_API fx_status fx_dict_put(fx_dict *dict, const char *key, fx_object *value);
FX_API fx_status fx_dict_put_sk(fx_dict *dict, const fx_string *key, fx_object *value);
FX_API fx_object *fx_dict_at(const fx_dict *dict, const char *key);
FX_API fx_object *fx_dict_at_sk(const fx_dict *dict, const fx_string *key);
FX_API fx_object *fx_dict_get(fx_dict *dict, const char *key);
FX_API fx_object *fx_dict_get_sk(fx_dict *dict, const fx_string *key);
FX_API bool fx_dict_has_key(const fx_dict *dict, const char *key);
FX_API bool fx_dict_has_skey(const fx_dict *dict, const fx_string *key);
FX_API size_t fx_dict_get_size(const fx_dict *dict);
FX_API bool fx_dict_is_empty(const fx_dict *dict);
FX_DECLS_END;
#endif
+83
View File
@@ -0,0 +1,83 @@
#ifndef FX_DS_HASHMAP_H_
#define FX_DS_HASHMAP_H_
#include <fx/core/btree.h>
#include <fx/core/macros.h>
#include <fx/core/misc.h>
#include <fx/core/queue.h>
#include <fx/core/status.h>
#include <stddef.h>
FX_DECLS_BEGIN;
struct fx_hashmap_p;
#define FX_TYPE_HASHMAP (fx_hashmap_get_type())
#define FX_TYPE_HASHMAP_ITERATOR (fx_hashmap_iterator_get_type())
FX_DECLARE_TYPE(fx_hashmap);
FX_DECLARE_TYPE(fx_hashmap_iterator);
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_hashmap)
FX_TYPE_CLASS_DECLARATION_END(fx_hashmap)
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_hashmap_iterator)
FX_TYPE_CLASS_DECLARATION_END(fx_hashmap_iterator)
#define FX_HASHMAP_KEY(k, ks) {.key_data = (k), .key_size = (ks)}
#define FX_HASHMAP_VALUE(v, vs) {.value_data = (v), .value_size = (vs)}
#define FX_HASHMAP_ITEM(k, ks, v, vs) \
{.key = FX_HASHMAP_KEY(k, ks), .value = FX_HASHMAP_VALUE(v, vs)}
#define FX_HASHMAP_ITEM_END {.key = {0}, .value = {0}}
#define fx_hashmap_foreach(it, hashmap) \
for (int z__fx_unique_name() = fx_hashmap_iterator_begin(hashmap, it); \
(it)->key != NULL; fx_hashmap_iterator_next(it))
typedef void (*fx_hashmap_key_destructor)(void *);
typedef void (*fx_hashmap_value_destructor)(void *);
typedef enum fx_hashmap_key_flags {
FX_HASHMAP_KEY_F_INTVALUE = 0x01u,
} fx_hashmap_key_flags;
typedef struct fx_hashmap_key {
fx_hashmap_key_flags key_flags;
const void *key_data;
size_t key_size;
} fx_hashmap_key;
typedef struct fx_hashmap_value {
void *value_data;
size_t value_size;
} fx_hashmap_value;
typedef struct fx_hashmap_item {
fx_hashmap_key key;
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_hashmap *fx_hashmap_create(
fx_hashmap_key_destructor key_dtor, fx_hashmap_value_destructor value_dtor);
FX_API fx_hashmap *fx_hashmap_create_with_items(const fx_hashmap_item *items);
FX_API fx_status fx_hashmap_put(
fx_hashmap *hashmap, const fx_hashmap_key *key, const fx_hashmap_value *value);
FX_API const fx_hashmap_value *fx_hashmap_get(
const fx_hashmap *hashmap, const fx_hashmap_key *key);
FX_API bool fx_hashmap_has_key(const fx_hashmap *hashmap, const fx_hashmap_key *key);
FX_API size_t fx_hashmap_get_size(const fx_hashmap *hashmap);
FX_API bool fx_hashmap_is_empty(const fx_hashmap *hashmap);
FX_API fx_iterator *fx_hashmap_begin(fx_hashmap *hashmap);
FX_API const fx_iterator *fx_hashmap_cbegin(const fx_hashmap *hashmap);
FX_DECLS_END;
#endif
+63
View File
@@ -0,0 +1,63 @@
#ifndef FX_DS_LIST_H_
#define FX_DS_LIST_H_
#include <fx/core/iterator.h>
#include <fx/core/macros.h>
#include <fx/core/status.h>
FX_DECLS_BEGIN;
#define FX_TYPE_LIST (fx_list_get_type())
#define FX_TYPE_LIST_ITERATOR (fx_list_iterator_get_type())
struct fx_list_p;
FX_DECLARE_TYPE(fx_list);
FX_DECLARE_TYPE(fx_list_iterator);
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_list)
FX_TYPE_CLASS_DECLARATION_END(fx_list)
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_list_iterator)
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_TYPE_DEFAULT_CONSTRUCTOR(fx_list, FX_TYPE_LIST);
FX_API bool fx_list_empty(fx_list *q);
FX_API void *fx_list_first_item(const fx_list *q);
FX_API void *fx_list_last_item(const fx_list *q);
FX_API fx_list_entry *fx_list_first_entry(const fx_list *q);
FX_API fx_list_entry *fx_list_last_entry(const fx_list *q);
FX_API fx_list_entry *fx_list_next(const fx_list_entry *entry);
FX_API fx_list_entry *fx_list_prev(const fx_list_entry *entry);
FX_API size_t fx_list_length(const fx_list *q);
FX_API fx_list_entry *fx_list_insert_before(
fx_list *q, void *ptr, fx_list_entry *before);
FX_API fx_list_entry *fx_list_insert_after(
fx_list *q, void *ptr, fx_list_entry *after);
FX_API fx_list_entry *fx_list_push_front(fx_list *q, void *ptr);
FX_API fx_list_entry *fx_list_push_back(fx_list *q, void *ptr);
FX_API void *fx_list_pop_front(fx_list *q);
FX_API void *fx_list_pop_back(fx_list *q);
FX_API fx_status fx_list_delete_item(fx_list *q, void *ptr);
FX_API fx_status fx_list_delete_entry(fx_list *q, fx_list_entry *entry);
FX_API void fx_list_delete_all(fx_list *q);
FX_API void *fx_list_entry_value(const fx_list_entry *entry);
FX_API fx_iterator *fx_list_begin(fx_list *q);
FX_API const fx_iterator *fx_list_cbegin(const fx_list *q);
FX_DECLS_END;
#endif
+254
View File
@@ -0,0 +1,254 @@
#ifndef FX_DS_NUMBER_H
#define FX_DS_NUMBER_H
#include <fx/core/macros.h>
#include <stdbool.h>
FX_DECLS_BEGIN;
#define FX_INT8(v) (fx_number_create_int8(v))
#define FX_INT16(v) (fx_number_create_int16(v))
#define FX_INT32(v) (fx_number_create_int32(v))
#define FX_INT64(v) (fx_number_create_int64(v))
#define FX_FLOAT32(v) (fx_number_create_float32(v))
#define FX_FLOAT64(v) (fx_number_create_float64(v))
#define FX_CHAR(v) (fx_number_create_char(v))
#define FX_SHORT(v) (fx_number_create_short(v))
#define FX_INT(v) (fx_number_create_int(v))
#define FX_LONG(v) (fx_number_create_long(v))
#define FX_LONGLONG(v) (fx_number_create_longlong(v))
#define FX_FLOAT(v) (fx_number_create_float(v))
#define FX_DOUBLE(v) (fx_number_create_double(v))
#define FX_SIZE_T(v) (fx_number_create_size_t(v))
#define FX_RV_INT8(v) FX_RV(fx_number_create_int8(v))
#define FX_RV_INT16(v) FX_RV(fx_number_create_int16(v))
#define FX_RV_INT32(v) FX_RV(fx_number_create_int32(v))
#define FX_RV_INT64(v) FX_RV(fx_number_create_int64(v))
#define FX_RV_FLOAT32(v) FX_RV(fx_number_create_float32(v))
#define FX_RV_FLOAT64(v) FX_RV(fx_number_create_float64(v))
#define FX_RV_CHAR(v) FX_RV(fx_number_create_char(v))
#define FX_RV_SHORT(v) FX_RV(fx_number_create_short(v))
#define FX_RV_INT(v) FX_RV(fx_number_create_int(v))
#define FX_RV_LONG(v) FX_RV(fx_number_create_long(v))
#define FX_RV_LONGLONG(v) FX_RV(fx_number_create_longlong(v))
#define FX_RV_FLOAT(v) FX_RV(fx_number_create_float(v))
#define FX_RV_DOUBLE(v) FX_RV(fx_number_create_double(v))
#define FX_RV_SIZE_T(v) FX_RV(fx_number_create_size_t(v))
#define FX_NUMBER_IVAL(p) (fx_number_get_size_t(p))
#define FX_NUMBER_FVAL(p) (fx_number_get_double(p))
#define FX_TYPE_NUMBER (fx_number_get_type())
FX_DECLARE_TYPE(fx_number);
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_number)
FX_TYPE_CLASS_DECLARATION_END(fx_number)
typedef enum fx_number_type {
FX_NUMBER_INT8,
FX_NUMBER_INT16,
FX_NUMBER_INT32,
FX_NUMBER_INT64,
FX_NUMBER_FLOAT32,
FX_NUMBER_FLOAT64,
FX_NUMBER_CHAR,
FX_NUMBER_SHORT,
FX_NUMBER_INT,
FX_NUMBER_LONG,
FX_NUMBER_LONGLONG,
FX_NUMBER_FLOAT,
FX_NUMBER_DOUBLE,
FX_NUMBER_SIZE_T,
FX_NUMBER_HANDLE,
FX_NUMBER_TYPE_COUNT,
FX_NUMBER_BYTE = FX_NUMBER_INT8,
FX_NUMBER_WORD = FX_NUMBER_INT16,
FX_NUMBER_DWORD = FX_NUMBER_INT32,
FX_NUMBER_QWORD = FX_NUMBER_INT64,
} fx_number_type;
FX_API fx_type fx_number_get_type(void);
FX_API fx_number *fx_number_create(fx_number_type type, void *value_ptr);
static inline fx_number *fx_number_create_int8(int8_t value)
{
return fx_number_create(FX_NUMBER_INT8, &value);
}
static inline fx_number *fx_number_create_int16(int16_t value)
{
return fx_number_create(FX_NUMBER_INT16, &value);
}
static inline fx_number *fx_number_create_int32(int32_t value)
{
return fx_number_create(FX_NUMBER_INT32, &value);
}
static inline fx_number *fx_number_create_int64(int64_t value)
{
return fx_number_create(FX_NUMBER_INT64, &value);
}
static inline fx_number *fx_number_create_float32(float value)
{
return fx_number_create(FX_NUMBER_FLOAT32, &value);
}
static inline fx_number *fx_number_create_float64(double value)
{
return fx_number_create(FX_NUMBER_FLOAT64, &value);
}
static inline fx_number *fx_number_create_char(char value)
{
return fx_number_create(FX_NUMBER_CHAR, &value);
}
static inline fx_number *fx_number_create_short(short value)
{
return fx_number_create(FX_NUMBER_SHORT, &value);
}
static inline fx_number *fx_number_create_int(int value)
{
return fx_number_create(FX_NUMBER_INT, &value);
}
static inline fx_number *fx_number_create_long(long value)
{
return fx_number_create(FX_NUMBER_LONG, &value);
}
static inline fx_number *fx_number_create_longlong(long long value)
{
return fx_number_create(FX_NUMBER_LONGLONG, &value);
}
static inline fx_number *fx_number_create_float(float value)
{
return fx_number_create(FX_NUMBER_FLOAT, &value);
}
static inline fx_number *fx_number_create_double(double value)
{
return fx_number_create(FX_NUMBER_DOUBLE, &value);
}
static inline fx_number *fx_number_create_size_t(size_t value)
{
return fx_number_create(FX_NUMBER_SIZE_T, &value);
}
FX_API fx_number_type fx_number_get_number_type(const fx_number *number);
FX_API int fx_number_get_value(
const fx_number *number, fx_number_type type, void *value_ptr);
static inline int8_t fx_number_get_int8(const fx_number *number)
{
int8_t v;
fx_number_get_value(number, FX_NUMBER_INT8, &v);
return v;
}
static inline int16_t fx_number_get_int16(const fx_number *number)
{
int16_t v;
fx_number_get_value(number, FX_NUMBER_INT16, &v);
return v;
}
static inline int32_t fx_number_get_int32(const fx_number *number)
{
int32_t v;
fx_number_get_value(number, FX_NUMBER_INT32, &v);
return v;
}
static inline int64_t fx_number_get_int64(const fx_number *number)
{
int64_t v;
fx_number_get_value(number, FX_NUMBER_INT64, &v);
return v;
}
static inline float fx_number_get_float32(const fx_number *number)
{
float v;
fx_number_get_value(number, FX_NUMBER_FLOAT32, &v);
return v;
}
static inline double fx_number_get_float64(const fx_number *number)
{
double v;
fx_number_get_value(number, FX_NUMBER_FLOAT64, &v);
return v;
}
static inline char fx_number_get_char(const fx_number *number)
{
char v;
fx_number_get_value(number, FX_NUMBER_CHAR, &v);
return v;
}
static inline short fx_number_get_short(const fx_number *number)
{
short v;
fx_number_get_value(number, FX_NUMBER_SHORT, &v);
return v;
}
static inline int fx_number_get_int(const fx_number *number)
{
int v;
fx_number_get_value(number, FX_NUMBER_INT, &v);
return v;
}
static inline long fx_number_get_long(const fx_number *number)
{
long v;
fx_number_get_value(number, FX_NUMBER_LONG, &v);
return v;
}
static inline long long fx_number_get_longlong(const fx_number *number)
{
long long v;
fx_number_get_value(number, FX_NUMBER_LONGLONG, &v);
return v;
}
static inline float fx_number_get_float(const fx_number *number)
{
float v;
fx_number_get_value(number, FX_NUMBER_FLOAT, &v);
return v;
}
static inline double fx_number_get_double(const fx_number *number)
{
double v;
fx_number_get_value(number, FX_NUMBER_DOUBLE, &v);
return v;
}
static inline size_t fx_number_get_size_t(const fx_number *number)
{
size_t v;
fx_number_get_value(number, FX_NUMBER_SIZE_T, &v);
return v;
}
FX_API bool fx_number_is_integer(const fx_number *number);
FX_API bool fx_number_is_float(const fx_number *number);
FX_API bool fx_number_is_inf(const fx_number *number);
FX_API bool fx_number_is_inf_positive(const fx_number *number);
FX_API bool fx_number_is_inf_negative(const fx_number *number);
FX_API bool fx_number_is_nan(const fx_number *number);
FX_API bool fx_number_is_nan_positive(const fx_number *number);
FX_API bool fx_number_is_nan_negative(const fx_number *number);
FX_API void fx_number_set_inf_positive(fx_number *number, bool v);
FX_API void fx_number_set_inf_negative(fx_number *number, bool v);
FX_API void fx_number_set_nan_positive(fx_number *number, bool v);
FX_API void fx_number_set_nan_negative(fx_number *number, bool v);
FX_API size_t fx_number_data_size(const fx_number *number);
FX_DECLS_END;
#endif
+129
View File
@@ -0,0 +1,129 @@
#ifndef FX_DS_STRING_H_
#define FX_DS_STRING_H_
#include <fx/core/encoding.h>
#include <fx/core/iterator.h>
#include <fx/core/macros.h>
#include <fx/core/status.h>
#include <fx/core/stringstream.h>
#include <ctype.h>
FX_DECLS_BEGIN;
struct fx_stream;
struct fx_string_p;
#define FX_TYPE_STRING (fx_string_get_type())
#define FX_TYPE_STRING_ITERATOR (fx_string_iterator_get_type())
FX_DECLARE_TYPE(fx_string);
FX_DECLARE_TYPE(fx_string_iterator);
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_string)
FX_TYPE_CLASS_DECLARATION_END(fx_string)
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_string_iterator)
FX_TYPE_CLASS_DECLARATION_END(fx_string_iterator)
#define FX_CSTR(s) (fx_string_create_from_cstr(s))
#define FX_RV_CSTR(s) (FX_RV(fx_string_create_from_cstr(s)))
typedef enum fx_strlen_flags {
FX_STRLEN_NORMAL = 0,
FX_STRLEN_IGNORE_ESC = 0x01u,
FX_STRLEN_IGNORE_MOD = 0x02u,
FX_STRLEN_CODEPOINTS = 0x04u,
} fx_strlen_flags;
typedef enum fx_string_tokenise_flags {
FX_STRING_TOK_F_NORMAL = 0x00u,
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_TYPE_DEFAULT_CONSTRUCTOR(fx_string, FX_TYPE_STRING);
FX_API fx_string *fx_string_create_from_cstr(const char *s);
FX_API fx_string *fx_string_create_from_wstr(const fx_wchar *s);
FX_API fx_string *fx_string_create_from_c(char c, size_t count);
FX_API fx_string *fx_string_duplicate(const fx_string *str);
FX_API char *fx_string_steal(fx_string *str);
FX_API fx_status fx_string_reserve(fx_string *str, size_t capacity);
FX_API fx_status fx_string_replace(
fx_string *str, size_t start, size_t length, const char *new_data);
FX_API fx_status fx_string_replace_all(fx_string *str, const char *new_data);
FX_API fx_status fx_string_replace_all_with_stringstream(
fx_string *str, const fx_stringstream *new_data);
FX_API fx_status fx_string_remove(fx_string *str, size_t start, size_t length);
FX_API fx_status fx_string_transform(fx_string *str, int (*transformer)(int));
FX_API fx_status fx_string_trim(fx_string *str);
static inline fx_status fx_string_toupper(fx_string *str)
{
return fx_string_transform(str, toupper);
}
static inline fx_status fx_string_tolower(fx_string *str)
{
return fx_string_transform(str, tolower);
}
FX_API fx_status fx_string_append_c(fx_string *dest, char c);
FX_API fx_status fx_string_append_wc(fx_string *dest, fx_wchar c);
FX_API fx_status fx_string_append_s(fx_string *dest, const fx_string *src);
FX_API fx_status fx_string_append_cstr(fx_string *dest, const char *src);
FX_API fx_status fx_string_append_wstr(fx_string *dest, const fx_wchar *src);
FX_API fx_status fx_string_append_cstrf(fx_string *dest, const char *format, ...);
FX_API fx_status fx_string_prepend_c(fx_string *dest, char c);
FX_API fx_status fx_string_prepend_wc(fx_string *dest, fx_wchar c);
FX_API fx_status fx_string_prepend_cstr(fx_string *dest, const char *src);
FX_API fx_status fx_string_prepend_wstr(fx_string *dest, const fx_wchar *src);
FX_API fx_status fx_string_prepend_cstrf(fx_string *dest, const char *format, ...);
FX_API fx_status fx_string_insert_c(fx_string *dest, char c, size_t at);
FX_API fx_status fx_string_insert_wc(fx_string *dest, fx_wchar c, size_t at);
FX_API fx_status fx_string_insert_s(fx_string *dest, const fx_string *src, size_t at);
FX_API fx_status fx_string_insert_cstr(fx_string *dest, const char *src, size_t at);
FX_API fx_status fx_string_insert_wstr(
fx_string *dest, const fx_wchar *src, size_t at);
FX_API fx_status fx_string_insert_cstrn(
fx_string *dest, const char *src, size_t len, size_t at);
FX_API fx_status fx_string_insert_wstrn(
fx_string *dest, const char *src, size_t len, size_t at);
FX_API fx_status fx_string_insert_cstrf(
fx_string *dest, size_t at, const char *format, ...);
FX_API void fx_string_clear(fx_string *str);
FX_API fx_iterator *fx_string_tokenise(
fx_string *str, const char *delims[], size_t nr_delims,
fx_string_tokenise_flags flags);
FX_API size_t fx_string_get_size(const fx_string *str, fx_strlen_flags flags);
FX_API size_t fx_string_get_capacity(const fx_string *str);
FX_API bool fx_string_compare(const fx_string *a, const fx_string *b);
FX_API char fx_string_front(const fx_string *str);
FX_API char fx_string_back(const fx_string *str);
FX_API void fx_string_pop_back(fx_string *str);
FX_API const char *fx_string_ptr(const fx_string *str);
FX_API fx_string *fx_string_substr(const fx_string *str, size_t start, size_t len);
FX_API int fx_string_iterator_begin(const fx_string *string, fx_string_iterator *it);
FX_API bool fx_string_iterator_next(fx_string_iterator *it);
// FX_API fx_status fx_string_iterator_erase(fx_string_iterator *it);
FX_API bool fx_string_iterator_is_valid(const fx_string_iterator *it);
FX_API char *fx_strdup(const char *s);
FX_API size_t fx_strlen(const char *s, fx_strlen_flags flags);
FX_API fx_wchar *fx_wstrdup(const fx_wchar *s);
FX_API size_t fx_wstrlen(const fx_wchar *s);
FX_API uint64_t fx_string_hash(const fx_string *s);
FX_DECLS_END;
#endif
+57
View File
@@ -0,0 +1,57 @@
#ifndef FX_DS_TREE_H_
#define FX_DS_TREE_H_
#include <fx/core/macros.h>
#include <fx/core/misc.h>
#include <fx/core/queue.h>
#include <fx/ds/string.h>
FX_DECLS_BEGIN;
#define FX_TYPE_TREE (fx_tree_get_type())
#define FX_TYPE_TREE_ITERATOR (fx_tree_iterator_get_type())
FX_DECLARE_TYPE(fx_tree);
FX_DECLARE_TYPE(fx_tree_iterator);
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_tree)
FX_TYPE_CLASS_DECLARATION_END(fx_tree)
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_tree_iterator)
FX_TYPE_CLASS_DECLARATION_END(fx_tree_iterator)
#define FX_TREE_NODE_INIT ((fx_tree_node) {0})
#define FX_TREE_CONTAINER(t, m, v) \
((void *)((v) ? (uintptr_t)(v) - (offsetof(t, m)) : 0))
typedef struct fx_tree_node {
struct fx_tree_node *__p01, *__p02, *__p03;
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_TYPE_DEFAULT_CONSTRUCTOR(fx_tree, FX_TYPE_TREE);
FX_API void fx_tree_set_root(fx_tree *tree, struct fx_tree_node *node);
FX_API void fx_tree_node_add_child(fx_tree_node *parent, fx_tree_node *child);
FX_API void fx_tree_node_add_sibling(fx_tree_node *node, fx_tree_node *to_add);
FX_API fx_tree_node *fx_tree_node_get_child(fx_tree_node *node, size_t at);
FX_API fx_tree_node *fx_tree_node_get_parent(fx_tree_node *node);
FX_API fx_iterator *fx_tree_begin(fx_tree *tree);
FX_API const fx_iterator *fx_tree_cbegin(const fx_tree *tree);
FX_API fx_iterator *fx_tree_node_begin(fx_tree_node *node);
FX_API const fx_iterator *fx_tree_node_cbegin(const fx_tree_node *node);
FX_API fx_iterator *fx_tree_node_begin_recursive(fx_tree_node *node);
FX_API const fx_iterator *fx_tree_node_cbegin_recursive(const fx_tree_node *node);
FX_DECLS_END;
#endif
+50
View File
@@ -0,0 +1,50 @@
#ifndef FX_DS_UUID_H_
#define FX_DS_UUID_H_
#include <fx/core/macros.h>
#include <fx/core/status.h>
#include <fx/ds/string.h>
#define FX_UUID_NBYTES 16
#define FX_UUID_STRING_MAX 37
FX_DECLS_BEGIN;
#define FX_TYPE_UUID (fx_uuid_get_type())
FX_DECLARE_TYPE(fx_uuid);
FX_TYPE_CLASS_DECLARATION_BEGIN(fx_uuid)
FX_TYPE_CLASS_DECLARATION_END(fx_uuid)
typedef union fx_uuid_bytes {
uint8_t uuid_bytes[FX_UUID_NBYTES];
uint16_t uuid_words[FX_UUID_NBYTES / 2];
uint32_t uuid_dwords[FX_UUID_NBYTES / 4];
uint64_t uuid_qwords[FX_UUID_NBYTES / 8];
} fx_uuid_bytes;
FX_API fx_type fx_uuid_get_type(void);
FX_TYPE_DEFAULT_CONSTRUCTOR(fx_uuid, FX_TYPE_UUID);
FX_API fx_uuid *fx_uuid_create_from_bytes(
unsigned char u00, unsigned char u01, unsigned char u02,
unsigned char u03, unsigned char u04, unsigned char u05,
unsigned char u06, unsigned char u07, unsigned char u08,
unsigned char u09, unsigned char u10, unsigned char u11, unsigned char u12,
unsigned char u13, unsigned char u14, unsigned char u15);
FX_API fx_uuid *fx_uuid_create_from_bytev(const unsigned char bytes[FX_UUID_NBYTES]);
FX_API fx_uuid *fx_uuid_create_from_uuid_bytes(const fx_uuid_bytes *bytes);
FX_API fx_uuid *fx_uuid_create_from_string(const fx_string *string);
FX_API fx_uuid *fx_uuid_create_from_cstr(const char *s);
FX_API fx_status fx_uuid_to_cstr(const fx_uuid *uuid, char out[FX_UUID_STRING_MAX]);
FX_API void fx_uuid_get_bytes(
const fx_uuid *uuid, unsigned char bytes[FX_UUID_NBYTES]);
FX_API void fx_uuid_get_uuid_bytes(const fx_uuid *uuid, fx_uuid_bytes *bytes);
FX_API fx_uuid_bytes *fx_uuid_ptr(fx_uuid *uuid);
FX_DECLS_END;
#endif