meta: rename legacy object module to 'ds'

This commit is contained in:
2025-08-09 19:57:42 +01:00
parent a5e3e06306
commit 0751ef469f
80 changed files with 460 additions and 460 deletions

View File

@@ -9,7 +9,7 @@ set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(b_modules core object serial term cmd io compress)
set(b_modules core ds serial term cmd io compress)
set(b_system_name ${CMAKE_SYSTEM_NAME})
string(TOLOWER ${b_system_name} b_system_name)

View File

@@ -49,7 +49,7 @@ if (Bluelib_STATIC)
set(_lib_suffix "-s")
endif ()
set(supported_components Core Object Term Cmd Io Serial Compress)
set(supported_components Core Ds Term Cmd Io Serial Compress)
set(components ${Bluelib_FIND_COMPONENTS})
string(REPLACE ";" ", " supported_components_string_list "${supported_components}")
@@ -118,12 +118,12 @@ if (Bluelib_FOUND)
endforeach (component)
foreach (component ${created_targets})
if ("${component}" STREQUAL "Object")
if ("${component}" STREQUAL "Ds")
if (NOT TARGET Bluelib::Core)
message(FATAL_ERROR "Bluelib: Module 'Object' depends on 'Core', which was not specified in find_package()")
message(FATAL_ERROR "Bluelib: Module 'Ds' depends on 'Core', which was not specified in find_package()")
endif ()
target_link_libraries(Bluelib::Object INTERFACE Bluelib::Core)
target_link_libraries(Bluelib::Ds INTERFACE Bluelib::Core)
endif ()
if ("${component}" STREQUAL "Term")
@@ -131,11 +131,11 @@ if (Bluelib_FOUND)
message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET Bluelib::Object)
message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Object', which was not specified in find_package()")
if (NOT TARGET Bluelib::Ds)
message(FATAL_ERROR "Bluelib: Module 'Term' depends on 'Ds', which was not specified in find_package()")
endif ()
target_link_libraries(Bluelib::Term INTERFACE Bluelib::Core Bluelib::Object)
target_link_libraries(Bluelib::Term INTERFACE Bluelib::Core Bluelib::Ds)
endif ()
if ("${component}" STREQUAL "Serial")
@@ -143,11 +143,11 @@ if (Bluelib_FOUND)
message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET Bluelib::Object)
message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Object', which was not specified in find_package()")
if (NOT TARGET Bluelib::Ds)
message(FATAL_ERROR "Bluelib: Module 'Serial' depends on 'Ds', which was not specified in find_package()")
endif ()
target_link_libraries(Bluelib::Serial INTERFACE Bluelib::Core Bluelib::Object)
target_link_libraries(Bluelib::Serial INTERFACE Bluelib::Core Bluelib::Ds)
endif ()
if ("${component}" STREQUAL "Cmd")
@@ -155,15 +155,15 @@ if (Bluelib_FOUND)
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET Bluelib::Object)
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Object', which was not specified in find_package()")
if (NOT TARGET Bluelib::Ds)
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Ds', which was not specified in find_package()")
endif ()
if (NOT TARGET Bluelib::Term)
message(FATAL_ERROR "Bluelib: Module 'Cmd' depends on 'Term', which was not specified in find_package()")
endif ()
target_link_libraries(Bluelib::Cmd INTERFACE Bluelib::Core Bluelib::Object Bluelib::Term)
target_link_libraries(Bluelib::Cmd INTERFACE Bluelib::Core Bluelib::Ds Bluelib::Term)
endif ()
if ("${component}" STREQUAL "Io")
@@ -171,11 +171,11 @@ if (Bluelib_FOUND)
message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Core', which was not specified in find_package()")
endif ()
if (NOT TARGET Bluelib::Object)
message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Object', which was not specified in find_package()")
if (NOT TARGET Bluelib::Ds)
message(FATAL_ERROR "Bluelib: Module 'Io' depends on 'Ds', which was not specified in find_package()")
endif ()
target_link_libraries(Bluelib::Io INTERFACE Bluelib::Core Bluelib::Object)
target_link_libraries(Bluelib::Io INTERFACE Bluelib::Core Bluelib::Ds)
endif ()
if ("${component}" STREQUAL "Compress")
@@ -183,7 +183,7 @@ if (Bluelib_FOUND)
message(FATAL_ERROR "Bluelib: Module 'Compress' depends on 'Core', which was not specified in find_package()")
endif ()
target_link_libraries(Bluelib::Compress INTERFACE Bluelib::Core Bluelib::Object)
target_link_libraries(Bluelib::Compress INTERFACE Bluelib::Core Bluelib::Ds)
endif ()
endforeach (component)
endif()

View File

@@ -1,3 +1,3 @@
include(../cmake/Templates.cmake)
add_bluelib_module(NAME cmd DEPENDENCIES core object term)
add_bluelib_module(NAME cmd DEPENDENCIES core ds term)

View File

@@ -1,7 +1,7 @@
#include "command.h"
#include <blue/cmd.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <stdlib.h>
#include <string.h>

View File

@@ -2,7 +2,7 @@
#include "command.h"
#include <blue/cmd.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <blue/term/print.h>
#include <blue/term/tty.h>
#include <stdarg.h>

View File

@@ -2,7 +2,7 @@
#include <blue/cmd.h>
#include <blue/core/btree.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <blue/term/print.h>
#include <blue/term/tty.h>
#include <stdio.h>

View File

@@ -5,7 +5,7 @@
#include <blue/core/init.h>
#include <blue/core/iterator.h>
#include <blue/core/queue.h>
#include <blue/object/array.h>
#include <blue/ds/array.h>
#include <stdbool.h>
#include <stdint.h>

View File

@@ -1,7 +1,7 @@
#include "command.h"
#include <blue/cmd.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <stdlib.h>
#include <string.h>

View File

@@ -1,7 +1,7 @@
#include "command.h"
#include <blue/core/stringstream.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <blue/term/print.h>
#include <stdio.h>

View File

@@ -1,5 +1,5 @@
#include <blue/object/array.h>
#include <blue/object/number.h>
#include <blue/ds/array.h>
#include <blue/ds/number.h>
#include <stdio.h>
int main(void)

View File

@@ -1,5 +1,5 @@
#include <CuTest.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
static void test_string_create(CuTest *tc)
{

View File

@@ -1,4 +1,4 @@
#include <blue/object/number.h>
#include <blue/ds/number.h>
#include <stdio.h>
int main(void)

View File

@@ -1,5 +1,5 @@
#include <blue/core/stream.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <stdio.h>
int main(int argc, const char **argv)

View File

@@ -1,5 +1,5 @@
#include <blue/core/stringstream.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <stdio.h>
#include <stdlib.h>

View File

@@ -1,7 +1,7 @@
#include <blue/core/btree.h>
#include <blue/object/dict.h>
#include <blue/object/number.h>
#include <blue/object/tree.h>
#include <blue/ds/dict.h>
#include <blue/ds/number.h>
#include <blue/ds/tree.h>
#include <stdio.h>
#define NITEMS 16

View File

@@ -1,4 +1,4 @@
#include <blue/object/uuid.h>
#include <blue/ds/uuid.h>
#include <stdio.h>
int main(void)

3
ds/CMakeLists.txt Normal file
View File

@@ -0,0 +1,3 @@
include(../cmake/Templates.cmake)
add_bluelib_module(NAME ds DEPENDENCIES core)

View File

@@ -2,17 +2,17 @@
#include <blue/core/iterator.h>
#include <blue/core/stream.h>
#include <blue/object/array.h>
#include <blue/object/type.h>
#include <blue/ds/array.h>
#include <blue/ds/type.h>
#include <stdlib.h>
#include <string.h>
static void array_release(struct b_object *obj);
static void array_to_string(struct b_object *obj, struct b_stream *out);
static void array_release(struct b_dsref *obj);
static void array_to_string(struct b_dsref *obj, struct b_stream *out);
static struct b_object_type array_type = {
.t_flags = B_OBJECT_FUNDAMENTAL,
.t_id = B_OBJECT_TYPE_ARRAY,
static struct b_dsref_type array_type = {
.t_flags = B_DSREF_FUNDAMENTAL,
.t_id = B_DSREF_TYPE_ARRAY,
.t_name = "corelib::array",
.t_instance_size = sizeof(struct b_array),
.t_release = array_release,
@@ -22,7 +22,7 @@ static struct b_object_type array_type = {
struct b_array *b_array_create(void)
{
struct b_array *array
= (struct b_array *)b_object_type_instantiate(&array_type);
= (struct b_array *)b_dsref_type_instantiate(&array_type);
if (!array) {
return NULL;
}
@@ -31,7 +31,7 @@ struct b_array *b_array_create(void)
}
struct b_array *b_array_create_with_values(
struct b_object *const *values, size_t nr_values)
struct b_dsref *const *values, size_t nr_values)
{
struct b_array *array = b_array_create();
if (!array) {
@@ -47,7 +47,7 @@ struct b_array *b_array_create_with_values(
array->ar_len = real_nr_values;
array->ar_cap = real_nr_values;
array->ar_data = calloc(real_nr_values, sizeof(struct b_object *));
array->ar_data = calloc(real_nr_values, sizeof(struct b_dsref *));
if (!array->ar_data) {
b_array_release(array);
return NULL;
@@ -65,7 +65,7 @@ static b_status resize_array(struct b_array *array, size_t new_capacity)
{
if (array->ar_cap < new_capacity) {
void *new_data = realloc(
array->ar_data, new_capacity * sizeof(struct b_object *));
array->ar_data, new_capacity * sizeof(struct b_dsref *));
if (!new_data) {
return B_ERR_NO_MEMORY;
}
@@ -77,7 +77,7 @@ static b_status resize_array(struct b_array *array, size_t new_capacity)
}
void *new_data = realloc(
array->ar_data, new_capacity * sizeof(struct b_object *));
array->ar_data, new_capacity * sizeof(struct b_dsref *));
if (!new_data) {
return B_ERR_NO_MEMORY;
}
@@ -93,17 +93,17 @@ static b_status resize_array(struct b_array *array, size_t new_capacity)
return B_SUCCESS;
}
b_status b_array_append(struct b_array *array, struct b_object *value)
b_status b_array_append(struct b_array *array, struct b_dsref *value)
{
return b_array_insert(array, value, B_NPOS);
}
b_status b_array_prepend(struct b_array *array, struct b_object *value)
b_status b_array_prepend(struct b_array *array, struct b_dsref *value)
{
return b_array_insert(array, value, 0);
}
b_status b_array_insert(struct b_array *array, struct b_object *value, size_t at)
b_status b_array_insert(struct b_array *array, struct b_dsref *value, size_t at)
{
if (at == B_NPOS) {
at = array->ar_len;
@@ -123,9 +123,9 @@ b_status b_array_insert(struct b_array *array, struct b_object *value, size_t at
}
}
struct b_object **src = array->ar_data + at;
struct b_object **dest = src + 1;
size_t move_len = (array->ar_len - at) * sizeof(struct b_object *);
struct b_dsref **src = array->ar_data + at;
struct b_dsref **dest = src + 1;
size_t move_len = (array->ar_len - at) * sizeof(struct b_dsref *);
memmove(dest, src, move_len);
@@ -141,9 +141,9 @@ b_status b_array_remove(struct b_array *array, size_t at)
return B_ERR_OUT_OF_BOUNDS;
}
struct b_object **src = array->ar_data + at;
struct b_object **dest = src + 1;
size_t move_len = array->ar_len * sizeof(struct b_object *);
struct b_dsref **src = array->ar_data + at;
struct b_dsref **dest = src + 1;
size_t move_len = array->ar_len * sizeof(struct b_dsref *);
b_release(array->ar_data[at]);
@@ -164,17 +164,17 @@ b_status b_array_remove_back(struct b_array *array)
return b_array_remove(array, array->ar_len - 1);
}
struct b_object *b_array_pop(b_array *array, size_t at)
struct b_dsref *b_array_pop(b_array *array, size_t at)
{
if (at >= array->ar_len) {
return NULL;
}
struct b_object **src = array->ar_data + at;
struct b_object **dest = src + 1;
size_t move_len = array->ar_len * sizeof(struct b_object *);
struct b_dsref **src = array->ar_data + at;
struct b_dsref **dest = src + 1;
size_t move_len = array->ar_len * sizeof(struct b_dsref *);
struct b_object *out = array->ar_data[at];
struct b_dsref *out = array->ar_data[at];
memmove(dest, src, move_len);
@@ -183,17 +183,17 @@ struct b_object *b_array_pop(b_array *array, size_t at)
return out;
}
struct b_object *b_array_pop_front(struct b_array *array)
struct b_dsref *b_array_pop_front(struct b_array *array)
{
return b_array_pop(array, 0);
}
struct b_object *b_array_pop_back(struct b_array *array)
struct b_dsref *b_array_pop_back(struct b_array *array)
{
return b_array_pop(array, array->ar_len - 1);
}
struct b_object *b_array_at(const struct b_array *array, size_t at)
struct b_dsref *b_array_at(const struct b_array *array, size_t at)
{
if (at >= array->ar_len) {
return NULL;
@@ -202,7 +202,7 @@ struct b_object *b_array_at(const struct b_array *array, size_t at)
return array->ar_data[at];
}
struct b_object *b_array_get(struct b_array *array, size_t at)
struct b_dsref *b_array_get(struct b_array *array, size_t at)
{
if (at >= array->ar_len) {
return NULL;
@@ -221,7 +221,7 @@ size_t b_array_capacity(const struct b_array *array)
return array->ar_cap;
}
static void array_to_string(struct b_object *obj, struct b_stream *out)
static void array_to_string(struct b_dsref *obj, struct b_stream *out)
{
struct b_array *array = B_ARRAY(obj);
@@ -238,7 +238,7 @@ static void array_to_string(struct b_object *obj, struct b_stream *out)
b_array_iterator it;
b_array_foreach(&it, array)
{
bool is_string = b_typeid(it.value) == B_OBJECT_TYPE_STRING;
bool is_string = b_typeid(it.value) == B_DSREF_TYPE_STRING;
if (is_string) {
b_stream_write_char(out, '"');
@@ -261,7 +261,7 @@ static void array_to_string(struct b_object *obj, struct b_stream *out)
b_stream_write_char(out, ']');
}
static void array_release(struct b_object *obj)
static void array_release(struct b_dsref *obj)
{
struct b_array *array = B_ARRAY(obj);
@@ -374,7 +374,7 @@ bool b_array_iterator_is_valid(const struct b_array_iterator *it)
return it->value != NULL;
}
b_object_type_id b_array_type_id(void)
b_dsref_type_id b_array_type_id(void)
{
return (b_object_type_id)&array_type;
return (b_dsref_type_id)&array_type;
}

View File

@@ -4,12 +4,12 @@
#include "../object.h"
struct b_array {
struct b_object ar_base;
struct b_dsref ar_base;
/* number of items in array */
unsigned int ar_len;
/* maximum number of items that can currently be stored in array */
unsigned int ar_cap;
struct b_object **ar_data;
struct b_dsref **ar_data;
};
#endif

View File

@@ -1,5 +1,5 @@
#include <string.h>
#include <blue/object/bitmap.h>
#include <blue/ds/bitmap.h>
#include <blue/core/bitop.h>
void b_bitmap_zero(b_bitmap_word *map, unsigned long nbits)

View File

@@ -1,16 +1,16 @@
#include "buffer.h"
#include <blue/core/iterator.h>
#include <blue/object/buffer.h>
#include <blue/object/type.h>
#include <blue/ds/buffer.h>
#include <blue/ds/type.h>
#include <stdlib.h>
#include <string.h>
static void buffer_release(struct b_object *obj);
static void buffer_release(struct b_dsref *obj);
static struct b_object_type buffer_type = {
.t_flags = B_OBJECT_FUNDAMENTAL,
.t_id = B_OBJECT_TYPE_BUFFER,
static struct b_dsref_type buffer_type = {
.t_flags = B_DSREF_FUNDAMENTAL,
.t_id = B_DSREF_TYPE_BUFFER,
.t_name = "corelib::buffer",
.t_instance_size = sizeof(struct b_buffer),
.t_release = buffer_release,
@@ -19,7 +19,7 @@ static struct b_object_type buffer_type = {
struct b_buffer *b_buffer_create(size_t item_sz)
{
struct b_buffer *buffer
= (struct b_buffer *)b_object_type_instantiate(&buffer_type);
= (struct b_buffer *)b_dsref_type_instantiate(&buffer_type);
if (!buffer) {
return NULL;
}
@@ -219,7 +219,7 @@ size_t b_buffer_capacity(const struct b_buffer *buffer)
return buffer->buf_cap;
}
void buffer_release(struct b_object *obj)
void buffer_release(struct b_dsref *obj)
{
struct b_buffer *buffer = B_BUFFER(obj);
@@ -319,7 +319,7 @@ size_t b_buffer_get_capacity(const struct b_buffer *buf)
return buf->buf_cap;
}
b_object_type_id b_buffer_type_id(void)
b_dsref_type_id b_buffer_type_id(void)
{
return (b_object_type_id)&buffer_type;
return (b_dsref_type_id)&buffer_type;
}

View File

@@ -4,7 +4,7 @@
#include "../object.h"
struct b_buffer {
struct b_object buf_base;
struct b_dsref buf_base;
/* number of items in buffer */
unsigned int buf_len;
/* maximum number of items that can currently be stored in array */

View File

@@ -2,9 +2,9 @@
#include <blue/core/status.h>
#include <blue/core/stream.h>
#include <blue/object/dict.h>
#include <blue/object/string.h>
#include <blue/object/type.h>
#include <blue/ds/dict.h>
#include <blue/ds/string.h>
#include <blue/ds/type.h>
#include <stdbool.h>
#include <stdlib.h>
@@ -23,13 +23,13 @@ uint64_t b_cstr_hash(const char *s)
return hash;
}
static void dict_release(struct b_object *obj);
static void dict_to_string(struct b_object *obj, struct b_stream *out);
static void dict_release(struct b_dsref *obj);
static void dict_to_string(struct b_dsref *obj, struct b_stream *out);
static struct b_object_type dict_type = {
static struct b_dsref_type dict_type = {
.t_name = "corelib::dict",
.t_flags = B_OBJECT_FUNDAMENTAL,
.t_id = B_OBJECT_TYPE_DICT,
.t_flags = B_DSREF_FUNDAMENTAL,
.t_id = B_DSREF_TYPE_DICT,
.t_instance_size = sizeof(struct b_dict),
.t_release = dict_release,
.t_to_string = dict_to_string,
@@ -38,7 +38,7 @@ static struct b_object_type dict_type = {
struct b_dict *b_dict_create(void)
{
struct b_dict *dict
= (struct b_dict *)b_object_type_instantiate(&dict_type);
= (struct b_dict *)b_dsref_type_instantiate(&dict_type);
if (!dict) {
return NULL;
}
@@ -86,7 +86,7 @@ static struct b_dict_bucket_item *create_bucket_item(void)
return item;
}
b_status b_dict_put(struct b_dict *dict, const char *key, b_object *value)
b_status b_dict_put(struct b_dict *dict, const char *key, b_dsref *value)
{
uint64_t hash = b_cstr_hash(key);
struct b_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
@@ -113,7 +113,7 @@ b_status b_dict_put(struct b_dict *dict, const char *key, b_object *value)
return B_SUCCESS;
}
b_object *b_dict_at(const struct b_dict *dict, const char *key)
b_dsref *b_dict_at(const struct b_dict *dict, const char *key)
{
uint64_t hash = b_cstr_hash(key);
struct b_dict_bucket *bucket = get_bucket(&dict->d_buckets, hash);
@@ -134,9 +134,9 @@ b_object *b_dict_at(const struct b_dict *dict, const char *key)
return NULL;
}
b_object *b_dict_get(struct b_dict *dict, const char *key)
b_dsref *b_dict_get(struct b_dict *dict, const char *key)
{
b_object *value = b_dict_at(dict, key);
b_dsref *value = b_dict_at(dict, key);
if (value) {
b_retain(value);
}
@@ -186,7 +186,7 @@ bool b_dict_is_empty(const b_dict *dict)
return false;
}
static void dict_to_string(struct b_object *obj, struct b_stream *out)
static void dict_to_string(struct b_dsref *obj, struct b_stream *out)
{
struct b_dict *dict = B_DICT(obj);
@@ -205,7 +205,7 @@ static void dict_to_string(struct b_object *obj, struct b_stream *out)
{
b_stream_write_fmt(out, NULL, "%s: ", it.key);
bool is_string = b_typeid(it.value) == B_OBJECT_TYPE_STRING;
bool is_string = b_typeid(it.value) == B_DSREF_TYPE_STRING;
if (is_string) {
b_stream_write_char(out, '"');
@@ -433,7 +433,7 @@ bool b_dict_iterator_is_valid(const struct b_dict_iterator *it)
return it->key != NULL;
}
static void dict_release(struct b_object *obj)
static void dict_release(struct b_dsref *obj)
{
struct b_dict *dict = B_DICT(obj);
@@ -477,7 +477,7 @@ static void dict_release(struct b_object *obj)
#endif
}
b_object_type_id b_dict_type_id(void)
b_dsref_type_id b_dict_type_id(void)
{
return (b_object_type_id)&dict_type;
return (b_dsref_type_id)&dict_type;
}

View File

@@ -9,7 +9,7 @@
struct b_dict_bucket_item {
b_queue_entry bi_entry;
char *bi_str;
struct b_object *bi_value;
struct b_dsref *bi_value;
};
struct b_dict_bucket {
@@ -19,7 +19,7 @@ struct b_dict_bucket {
};
struct b_dict {
struct b_object d_base;
struct b_dsref d_base;
b_btree d_buckets;
};

View File

@@ -2,9 +2,9 @@
#include <blue/core/misc.h>
#include <blue/core/status.h>
#include <blue/object/hashmap.h>
#include <blue/object/string.h>
#include <blue/object/type.h>
#include <blue/ds/hashmap.h>
#include <blue/ds/string.h>
#include <blue/ds/type.h>
#include <stdbool.h>
#include <stdlib.h>
@@ -38,12 +38,12 @@ static uint64_t hash_data(const void *p, size_t size)
return hash;
}
static void hashmap_release(struct b_object *obj);
static void hashmap_release(struct b_dsref *obj);
static struct b_object_type hashmap_type = {
static struct b_dsref_type hashmap_type = {
.t_name = "corelib::hashmap",
.t_flags = B_OBJECT_FUNDAMENTAL,
.t_id = B_OBJECT_TYPE_HASHMAP,
.t_flags = B_DSREF_FUNDAMENTAL,
.t_id = B_DSREF_TYPE_HASHMAP,
.t_instance_size = sizeof(struct b_hashmap),
.t_release = hashmap_release,
};
@@ -52,7 +52,7 @@ struct b_hashmap *b_hashmap_create(
b_hashmap_key_destructor key_dtor, b_hashmap_value_destructor value_dtor)
{
struct b_hashmap *hashmap
= (struct b_hashmap *)b_object_type_instantiate(&hashmap_type);
= (struct b_hashmap *)b_dsref_type_instantiate(&hashmap_type);
if (!hashmap) {
return NULL;
}
@@ -444,7 +444,7 @@ bool b_hashmap_iterator_is_valid(const struct b_hashmap_iterator *it)
return it->key != NULL;
}
static void hashmap_release(struct b_object *obj)
static void hashmap_release(struct b_dsref *obj)
{
struct b_hashmap *map = B_HASHMAP(obj);
@@ -455,7 +455,7 @@ static void hashmap_release(struct b_object *obj)
}
}
b_object_type_id b_hashmap_type_id(void)
b_dsref_type_id b_hashmap_type_id(void)
{
return (b_object_type_id)&hashmap_type;
return (b_dsref_type_id)&hashmap_type;
}

View File

@@ -3,7 +3,7 @@
#include <blue/core/btree.h>
#include <blue/core/queue.h>
#include <blue/object/hashmap.h>
#include <blue/ds/hashmap.h>
struct b_hashmap_bucket_item {
struct b_queue_entry bi_entry;
@@ -18,7 +18,7 @@ struct b_hashmap_bucket {
};
struct b_hashmap {
struct b_object h_base;
struct b_dsref h_base;
struct b_btree h_buckets;
b_hashmap_key_destructor h_key_dtor;
b_hashmap_value_destructor h_value_dtor;

View File

@@ -4,11 +4,11 @@
#include <blue/core/iterator.h>
#include <blue/core/misc.h>
#include <blue/core/status.h>
#include <blue/object/object.h>
#include <blue/object/type.h>
#include <blue/ds/object.h>
#include <blue/ds/type.h>
/**
* Cast a generic b_object pointer to an b_array pointer.
* Cast a generic b_dsref pointer to an b_array pointer.
*/
#define B_ARRAY(p) ((b_array *)(p))
@@ -43,7 +43,7 @@ typedef struct b_array b_array;
/**
* Iterator for traversing the contents of an b_array.
*
* The iterator provides the current b_object `value`, as well
* The iterator provides the current b_dsref `value`, as well
* as the index `i` of that value within the array.
*
* Any members whose names begin with _ (underscore) are reserved
@@ -56,7 +56,7 @@ typedef struct b_array_iterator {
/** The index of the current value */
size_t i;
/** The current value */
b_object *value;
b_dsref *value;
} b_array_iterator;
/**
@@ -67,7 +67,7 @@ typedef struct b_array_iterator {
BLUE_API b_array *b_array_create(void);
/**
* Creates an b_array initialised with the contents of the provided b_object
* Creates an b_array initialised with the contents of the provided b_dsref
* pointer array. The b_array will take a reference to each object specified in
* `values`, and will increment the reference count. The order of objects in the
* new b_array will be the same as the order of objects in `values`. Any NULL
@@ -82,7 +82,7 @@ BLUE_API b_array *b_array_create(void);
* @return A pointer to the new b_array, or NULL if an error occurred.
*/
BLUE_API b_array *b_array_create_with_values(
b_object *const *values, size_t nr_values);
b_dsref *const *values, size_t nr_values);
/**
* Increment the reference counter of an b_array.
@@ -92,7 +92,7 @@ BLUE_API b_array *b_array_create_with_values(
*/
static inline b_array *b_array_retain(b_array *array)
{
return B_ARRAY(b_retain(B_OBJECT(array)));
return B_ARRAY(b_retain(B_DSREF(array)));
}
/**
@@ -101,7 +101,7 @@ static inline b_array *b_array_retain(b_array *array)
*/
static inline void b_array_release(b_array *array)
{
b_release(B_OBJECT(array));
b_release(B_DSREF(array));
}
/**
@@ -120,7 +120,7 @@ BLUE_API void b_array_clear(b_array *array);
* @param value The object to append.
* @return B_SUCCESS if the object was appended successfully, or an error code if an error occurred.
*/
BLUE_API b_status b_array_append(b_array *array, b_object *value);
BLUE_API b_status b_array_append(b_array *array, b_dsref *value);
/**
* Inserts an object at the beginning of an b_array. The reference count of the object
@@ -131,7 +131,7 @@ BLUE_API b_status b_array_append(b_array *array, b_object *value);
* @param value The object to prepend.
* @return B_SUCCESS if the object was prepended successfully, or an error code if an error occurred.
*/
BLUE_API b_status b_array_prepend(b_array *array, b_object *value);
BLUE_API b_status b_array_prepend(b_array *array, b_dsref *value);
/**
* Inserts an object into an b_array at a given index. The reference count of the object
@@ -145,7 +145,7 @@ BLUE_API b_status b_array_prepend(b_array *array, b_object *value);
* be inserted at the end of the b_array.
* @return B_SUCCESS if the object was inserted, or a status code describing any error that occurred.
*/
BLUE_API b_status b_array_insert(b_array *array, b_object *value, size_t at);
BLUE_API b_status b_array_insert(b_array *array, b_dsref *value, size_t at);
/**
* Removes the object at the specified index from an b_array. The reference count
@@ -191,7 +191,7 @@ BLUE_API b_status b_array_remove_back(b_array *array);
* @return An pointer to the removed object. This pointer is owned by the
* caller. Returns NULL if an error occurred.
*/
BLUE_API b_object *b_array_pop(b_array *array, size_t at);
BLUE_API b_dsref *b_array_pop(b_array *array, size_t at);
/**
* Removes the object at the beginning of an b_array, and returns a pointer to
@@ -204,7 +204,7 @@ BLUE_API b_object *b_array_pop(b_array *array, size_t at);
* @return An pointer to the removed object. This pointer is owned by the
* caller. Returns NULL if an error occurred.
*/
BLUE_API b_object *b_array_pop_front(b_array *array);
BLUE_API b_dsref *b_array_pop_front(b_array *array);
/**
* Removes the object at the end of an b_array, and returns a pointer to it. The
@@ -215,7 +215,7 @@ BLUE_API b_object *b_array_pop_front(b_array *array);
* @return An pointer to the removed object. This pointer is owned by the
* caller. Returns NULL if an error occurred.
*/
BLUE_API b_object *b_array_pop_back(b_array *array);
BLUE_API b_dsref *b_array_pop_back(b_array *array);
/**
* Returns an unowned pointer to the object at the given index of an b_array.
@@ -226,7 +226,7 @@ BLUE_API b_object *b_array_pop_back(b_array *array);
* @return A pointer to the object at the given index. This pointer is NOT owned
* by the caller. Returns NULL if an error occurred.
*/
BLUE_API b_object *b_array_at(const b_array *array, size_t at);
BLUE_API b_dsref *b_array_at(const b_array *array, size_t at);
/**
* Returns an owned pointer to the object at the given index of an b_array. The caller owns
@@ -237,7 +237,7 @@ BLUE_API b_object *b_array_at(const b_array *array, size_t at);
* @return A pointer to the object at the given index. This pointer is owned by the caller.
* Returns NULL if an error occurred.
*/
BLUE_API b_object *b_array_get(b_array *array, size_t at);
BLUE_API b_dsref *b_array_get(b_array *array, size_t at);
/**
* Returns the number of objects contained in an b_array.

View File

@@ -1,7 +1,7 @@
#ifndef BLUE_OBJECT_BITBUFFER_H_
#define BLUE_OBJECT_BITBUFFER_H_
#include <blue/object/object.h>
#include <blue/ds/object.h>
#define B_BITBUFFER(p) ((b_bitbuffer *)(p))
@@ -11,11 +11,11 @@ BLUE_API b_bitbuffer *b_bitbuffer_create(void);
static inline b_bitbuffer *b_bitbuffer_retain(b_bitbuffer *buf)
{
return B_BITBUFFER(b_retain(B_OBJECT(buf)));
return B_BITBUFFER(b_retain(B_DSREF(buf)));
}
static inline void b_bitbuffer_release(b_bitbuffer *buf)
{
b_release(B_OBJECT(buf));
b_release(B_DSREF(buf));
}
BLUE_API b_status b_bitbuffer_put_bit(b_bitbuffer *buf, int bit);

View File

@@ -1,8 +1,8 @@
#ifndef BLUELIB_BUFFER_H_
#define BLUELIB_BUFFER_H_
#include <blue/object/object.h>
#include <blue/object/type.h>
#include <blue/ds/object.h>
#include <blue/ds/type.h>
#include <stddef.h>
#define B_BUFFER(p) ((b_buffer *)(p))
@@ -16,11 +16,11 @@ BLUE_API b_buffer *b_buffer_create_from_array(
static inline b_buffer *b_buffer_retain(b_buffer *buf)
{
return B_BUFFER(b_retain(B_OBJECT(buf)));
return B_BUFFER(b_retain(B_DSREF(buf)));
}
static inline void b_buffer_release(b_buffer *buf)
{
b_release(B_OBJECT(buf));
b_release(B_DSREF(buf));
}
BLUE_API void *b_buffer_steal(b_buffer *buf);
BLUE_API b_status b_buffer_reserve(b_buffer *buf, size_t capacity);

View File

@@ -5,8 +5,8 @@
#include <blue/core/misc.h>
#include <blue/core/queue.h>
#include <blue/core/status.h>
#include <blue/object/object.h>
#include <blue/object/type.h>
#include <blue/ds/object.h>
#include <blue/ds/type.h>
#define B_DICT(p) ((b_dict *)(p))
@@ -29,7 +29,7 @@ typedef struct b_dict_iterator {
b_iterator _base;
size_t i;
const char *key;
b_object *value;
b_dsref *value;
b_dict *_d;
b_btree_node *_cbn;
@@ -38,7 +38,7 @@ typedef struct b_dict_iterator {
typedef struct b_dict_item {
const char *key;
b_object *value;
b_dsref *value;
} b_dict_item;
BLUE_API b_dict *b_dict_create(void);
@@ -46,16 +46,16 @@ BLUE_API b_dict *b_dict_create_with_items(const b_dict_item *items);
static inline b_dict *b_dict_retain(b_dict *dict)
{
return B_DICT(b_retain(B_OBJECT(dict)));
return B_DICT(b_retain(B_DSREF(dict)));
}
static inline void b_dict_release(b_dict *dict)
{
b_release(B_OBJECT(dict));
b_release(B_DSREF(dict));
}
BLUE_API b_status b_dict_put(b_dict *dict, const char *key, b_object *value);
BLUE_API b_object *b_dict_at(const b_dict *dict, const char *key);
BLUE_API b_object *b_dict_get(b_dict *dict, const char *key);
BLUE_API b_status b_dict_put(b_dict *dict, const char *key, b_dsref *value);
BLUE_API b_dsref *b_dict_at(const b_dict *dict, const char *key);
BLUE_API b_dsref *b_dict_get(b_dict *dict, const char *key);
BLUE_API bool b_dict_has_key(const b_dict *dict, const char *key);
BLUE_API size_t b_dict_get_size(const b_dict *dict);

View File

@@ -5,8 +5,8 @@
#include <blue/core/misc.h>
#include <blue/core/queue.h>
#include <blue/core/status.h>
#include <blue/object/object.h>
#include <blue/object/type.h>
#include <blue/ds/object.h>
#include <blue/ds/type.h>
#define B_HASHMAP(p) ((b_hashmap *)(p))
@@ -70,11 +70,11 @@ BLUE_API b_hashmap *b_hashmap_create_with_items(const b_hashmap_item *items);
static inline b_hashmap *b_hashmap_retain(b_hashmap *hashmap)
{
return B_HASHMAP(b_retain(B_OBJECT(hashmap)));
return B_HASHMAP(b_retain(B_DSREF(hashmap)));
}
static inline void b_hashmap_release(b_hashmap *hashmap)
{
b_release(B_OBJECT(hashmap));
b_release(B_DSREF(hashmap));
}
BLUE_API b_status b_hashmap_put(

View File

@@ -2,7 +2,7 @@
#define BLUE_OBJECT_LIST_H_
#include <blue/core/status.h>
#include <blue/object/object.h>
#include <blue/ds/object.h>
#define B_LIST(p) ((b_list *)(p))
@@ -25,11 +25,11 @@ BLUE_API b_list *b_list_create(void);
static inline b_list *b_list_retain(b_list *str)
{
return B_LIST(b_retain(B_OBJECT(str)));
return B_LIST(b_retain(B_DSREF(str)));
}
static inline void b_list_release(b_list *str)
{
b_release(B_OBJECT(str));
b_release(B_DSREF(str));
}
BLUE_API bool b_list_empty(b_list *q);

View File

@@ -1,8 +1,8 @@
#ifndef BLUELIB_NUMBER_H
#define BLUELIB_NUMBER_H
#include <blue/object/object.h>
#include <blue/object/type.h>
#include <blue/ds/object.h>
#include <blue/ds/type.h>
#include <stdbool.h>
#define B_NUMBER(p) ((b_number *)(p))
@@ -69,11 +69,11 @@ typedef enum b_number_type {
BLUE_API b_number *b_number_create(b_number_type type, void *value_ptr);
static inline b_number *b_number_retain(b_number *number)
{
return B_NUMBER(b_retain(B_OBJECT(number)));
return B_NUMBER(b_retain(B_DSREF(number)));
}
static inline void b_number_release(b_number *number)
{
b_release(B_OBJECT(number));
b_release(B_DSREF(number));
}
static inline b_number *b_number_create_int8(int8_t value)

View File

@@ -0,0 +1,40 @@
#ifndef BLUELIB_DSREF_H_
#define BLUELIB_DSREF_H_
#include <blue/ds/type.h>
#define B_DSREF(p) ((b_dsref *)(p))
#define B_TYPEOF(object) ((struct b_dsref *)(object)->ob_type)
#define B_TYPEID(object) (b_typeid(B_DSREF(object)))
#define B_RV(p) (b_make_rvalue(B_DSREF(p)))
#define B_RVT(t, p) ((t *)(b_make_rvalue(B_DSREF(p))))
#define B_DSREF_IS(object, type) (B_TYPEID(object) == B_DSREF_TYPE_##type)
struct b_string;
struct b_stream;
typedef enum b_comparison_result {
B_LESS = -1,
B_EQUAL = 0,
B_GREATER = 1,
} b_comparison_result_t;
typedef struct b_dsref {
unsigned int ob_ref;
const struct b_dsref_type *ob_type;
} b_dsref;
BLUE_API b_dsref *b_make_rvalue(b_dsref *obj);
BLUE_API b_dsref *b_retain(b_dsref *obj);
BLUE_API void b_release(b_dsref *obj);
BLUE_API void b_to_string(b_dsref *obj, struct b_stream *out);
BLUE_API b_dsref_type_id b_typeid(const b_dsref *obj);
BLUE_API b_comparison_result_t b_compare(const b_dsref *a, const b_dsref *b);
#endif

View File

@@ -2,8 +2,8 @@
#define BLUELIB_STRING_H_
#include <blue/core/status.h>
#include <blue/object/object.h>
#include <blue/object/type.h>
#include <blue/ds/object.h>
#include <blue/ds/type.h>
#include <ctype.h>
struct b_stream;
@@ -28,11 +28,11 @@ BLUE_API b_string *b_string_duplicate(const b_string *str);
static inline b_string *b_string_retain(b_string *str)
{
return B_STRING(b_retain(B_OBJECT(str)));
return B_STRING(b_retain(B_DSREF(str)));
}
static inline void b_string_release(b_string *str)
{
b_release(B_OBJECT(str));
b_release(B_DSREF(str));
}
BLUE_API char *b_string_steal(b_string *str);
BLUE_API b_status b_string_reserve(b_string *str, size_t capacity);

View File

@@ -3,7 +3,7 @@
#include <blue/core/misc.h>
#include <blue/core/queue.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#define B_TREE(p) ((b_tree *)(p))
#define B_TREE_NODE_INIT ((b_tree_node){0})
@@ -45,11 +45,11 @@ BLUE_API b_tree *b_tree_create(void);
static inline b_tree *b_tree_retain(b_tree *tree)
{
return B_TREE(b_retain(B_OBJECT(tree)));
return B_TREE(b_retain(B_DSREF(tree)));
}
static inline void b_tree_release(b_tree *tree)
{
b_release(B_OBJECT(tree));
b_release(B_DSREF(tree));
}
BLUE_API void b_tree_set_root(b_tree *tree, struct b_tree_node *node);

53
ds/include/blue/ds/type.h Normal file
View File

@@ -0,0 +1,53 @@
#ifndef BLUELIB_TYPE_H_
#define BLUELIB_TYPE_H_
#include <blue/core/queue.h>
#include <blue/core/status.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define B_NPOS ((size_t)INTPTR_MAX)
struct b_dsref;
struct b_stream;
typedef uintptr_t b_dsref_type_id;
typedef enum b_fundamental_type_id {
B_DSREF_TYPE_NONE = 0,
B_DSREF_TYPE_ANY,
B_DSREF_TYPE_LIST,
B_DSREF_TYPE_ARRAY,
B_DSREF_TYPE_BUFFER,
B_DSREF_TYPE_DICT,
B_DSREF_TYPE_ERROR,
B_DSREF_TYPE_HASHMAP,
B_DSREF_TYPE_NUMBER,
B_DSREF_TYPE_STRING,
B_DSREF_TYPE_TREE,
B_DSREF_TYPE_UUID,
B_DSREF_TYPE_PATH,
B_DSREF_TYPE_FILE,
B_DSREF_TYPE_DIRECTORY,
} b_fundamental_type_id;
typedef enum b_dsref_type_flags {
B_DSREF_FUNDAMENTAL = 0x01u,
} b_dsref_type_flags;
typedef struct b_dsref_type {
b_dsref_type_flags t_flags;
char t_name[64];
size_t t_instance_size;
b_dsref_type_id t_id;
b_queue_entry t_entry;
void (*t_init)(struct b_dsref *);
void (*t_release)(struct b_dsref *);
void (*t_to_string)(struct b_dsref *, struct b_stream *);
} b_dsref_type;
BLUE_API b_status b_dsref_type_register(b_dsref_type *type);
BLUE_API struct b_dsref *b_dsref_type_instantiate(const b_dsref_type *type);
#endif

View File

@@ -2,8 +2,8 @@
#define BLUELIB_UUID_H_
#include <blue/core/status.h>
#include <blue/object/object.h>
#include <blue/object/type.h>
#include <blue/ds/object.h>
#include <blue/ds/type.h>
#define B_UUID(p) ((b_uuid *)(p))
@@ -33,11 +33,11 @@ BLUE_API b_uuid *b_uuid_create_from_cstr(const char *s);
static inline b_uuid *b_uuid_retain(b_uuid *uuid)
{
return B_UUID(b_retain(B_OBJECT(uuid)));
return B_UUID(b_retain(B_DSREF(uuid)));
}
static inline void b_uuid_release(b_uuid *uuid)
{
b_release(B_OBJECT(uuid));
b_release(B_DSREF(uuid));
}
BLUE_API b_status b_uuid_to_string(const b_uuid *uuid, struct b_string *out);

View File

@@ -1,15 +1,15 @@
#include "list.h"
#include <blue/object/list.h>
#include <blue/ds/list.h>
#include <stdlib.h>
#include <string.h>
static void list_release(struct b_object *obj);
static void list_release(struct b_dsref *obj);
static struct b_object_type list_type = {
static struct b_dsref_type list_type = {
.t_name = "corelib::list",
.t_flags = B_OBJECT_FUNDAMENTAL,
.t_id = B_OBJECT_TYPE_LIST,
.t_flags = B_DSREF_FUNDAMENTAL,
.t_id = B_DSREF_TYPE_LIST,
.t_instance_size = sizeof(struct b_list),
.t_release = list_release,
};
@@ -17,7 +17,7 @@ static struct b_object_type list_type = {
struct b_list *b_list_create(void)
{
struct b_list *list
= (struct b_list *)b_object_type_instantiate(&list_type);
= (struct b_list *)b_dsref_type_instantiate(&list_type);
if (!list) {
return NULL;
}
@@ -335,7 +335,7 @@ void *b_list_entry_value(const struct b_list_entry *entry)
return entry ? entry->e_data : NULL;
}
static void list_release(struct b_object *obj)
static void list_release(struct b_dsref *obj)
{
struct b_list *list = B_LIST(obj);
b_list_delete_all(list);

View File

@@ -6,7 +6,7 @@
#include <blue/core/queue.h>
struct b_list {
struct b_object l_base;
struct b_dsref l_base;
struct b_queue l_queue;
size_t l_len;
};

View File

@@ -1,7 +1,7 @@
#include "number.h"
#include <blue/core/stream.h>
#include <blue/object/type.h>
#include <blue/ds/type.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
@@ -10,12 +10,12 @@ typedef int (*number_converter_t)(const struct b_number *, void *);
static number_converter_t converters[B_NUMBER_TYPE_COUNT][B_NUMBER_TYPE_COUNT];
static void number_to_string(struct b_object *obj, struct b_stream *out);
static void number_to_string(struct b_dsref *obj, struct b_stream *out);
static struct b_object_type number_type = {
static struct b_dsref_type number_type = {
.t_name = "corelib::number",
.t_flags = B_OBJECT_FUNDAMENTAL,
.t_id = B_OBJECT_TYPE_NUMBER,
.t_flags = B_DSREF_FUNDAMENTAL,
.t_id = B_DSREF_TYPE_NUMBER,
.t_instance_size = sizeof(b_number),
.t_to_string = number_to_string,
};
@@ -23,7 +23,7 @@ static struct b_object_type number_type = {
struct b_number *b_number_create(b_number_type type, void *value_ptr)
{
struct b_number *n
= (struct b_number *)b_object_type_instantiate(&number_type);
= (struct b_number *)b_dsref_type_instantiate(&number_type);
if (!n) {
return NULL;
}
@@ -175,7 +175,7 @@ size_t b_number_data_size(const struct b_number *number)
}
}
static void number_to_string(struct b_object *obj, struct b_stream *out)
static void number_to_string(struct b_dsref *obj, struct b_stream *out)
{
struct b_number *number = B_NUMBER(obj);
switch (number->n_type) {
@@ -1675,7 +1675,7 @@ static number_converter_t converters[B_NUMBER_TYPE_COUNT][B_NUMBER_TYPE_COUNT] =
},
};
b_object_type_id b_number_type_id(void)
b_dsref_type_id b_number_type_id(void)
{
return (b_object_type_id)&number_type;
return (b_dsref_type_id)&number_type;
}

View File

@@ -3,10 +3,10 @@
#include "object.h"
#include <blue/object/number.h>
#include <blue/ds/number.h>
struct b_number {
struct b_object n_base;
struct b_dsref n_base;
b_number_type n_type;
union {
int8_t v_int8;

View File

@@ -1,31 +1,31 @@
#include "object.h"
#include <blue/core/stream.h>
#include <blue/object/object.h>
#include <blue/object/string.h>
#include <blue/object/type.h>
#include <blue/ds/object.h>
#include <blue/ds/string.h>
#include <blue/ds/type.h>
#include <stdio.h>
#include <stdlib.h>
void b_object_init(struct b_object *obj, struct b_object_type *type)
void b_dsref_init(struct b_dsref *obj, struct b_dsref_type *type)
{
obj->ob_ref = 1;
obj->ob_type = type;
}
struct b_object *b_make_rvalue(struct b_object *obj)
struct b_dsref *b_make_rvalue(struct b_dsref *obj)
{
obj->ob_ref = 0;
return obj;
}
struct b_object *b_retain(struct b_object *obj)
struct b_dsref *b_retain(struct b_dsref *obj)
{
obj->ob_ref++;
return obj;
}
void b_release(struct b_object *obj)
void b_release(struct b_dsref *obj)
{
if (obj->ob_ref > 1) {
obj->ob_ref--;
@@ -41,7 +41,7 @@ void b_release(struct b_object *obj)
free(obj);
}
void b_to_string(struct b_object *obj, struct b_stream *out)
void b_to_string(struct b_dsref *obj, struct b_stream *out)
{
if (obj->ob_type->t_to_string) {
obj->ob_type->t_to_string(obj, out);
@@ -56,11 +56,11 @@ void b_to_string(struct b_object *obj, struct b_stream *out)
b_stream_write_fmt(out, NULL, "<%s@%p>", name, obj);
}
b_object_type_id b_typeid(const struct b_object *obj)
b_dsref_type_id b_typeid(const struct b_dsref *obj)
{
if (obj->ob_type->t_flags & B_OBJECT_FUNDAMENTAL) {
if (obj->ob_type->t_flags & B_DSREF_FUNDAMENTAL) {
return obj->ob_type->t_id;
}
return (b_object_type_id)obj->ob_type;
return (b_dsref_type_id)obj->ob_type;
}

6
ds/object.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef _BLUELIB_DSREF_H_
#define _BLUELIB_DSREF_H_
#include <blue/ds/object.h>
#endif

View File

@@ -2,8 +2,8 @@
#include <blue/core/stream.h>
#include <blue/core/stringstream.h>
#include <blue/object/string.h>
#include <blue/object/type.h>
#include <blue/ds/string.h>
#include <blue/ds/type.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdbool.h>
@@ -11,13 +11,13 @@
#include <stdlib.h>
#include <string.h>
static void string_release(struct b_object *obj);
static void string_to_string(struct b_object *obj, struct b_stream *out);
static void string_release(struct b_dsref *obj);
static void string_to_string(struct b_dsref *obj, struct b_stream *out);
static struct b_object_type string_type = {
static struct b_dsref_type string_type = {
.t_name = "corelib::string",
.t_flags = B_OBJECT_FUNDAMENTAL,
.t_id = B_OBJECT_TYPE_STRING,
.t_flags = B_DSREF_FUNDAMENTAL,
.t_id = B_DSREF_TYPE_STRING,
.t_instance_size = sizeof(struct b_string),
.t_release = string_release,
.t_to_string = string_to_string,
@@ -26,7 +26,7 @@ static struct b_object_type string_type = {
struct b_string *b_string_create(void)
{
struct b_string *str
= (struct b_string *)b_object_type_instantiate(&string_type);
= (struct b_string *)b_dsref_type_instantiate(&string_type);
if (!str) {
return NULL;
}
@@ -613,7 +613,7 @@ struct b_string *b_string_substr(const struct b_string *str, size_t start, size_
return newstr;
}
static void string_release(struct b_object *obj)
static void string_release(struct b_dsref *obj)
{
struct b_string *str = B_STRING(obj);
if (!string_is_inline(str)) {
@@ -621,7 +621,7 @@ static void string_release(struct b_object *obj)
}
}
static void string_to_string(struct b_object *obj, struct b_stream *out)
static void string_to_string(struct b_dsref *obj, struct b_stream *out)
{
b_string *str = B_STRING(obj);
b_stream_write_fmt(out, NULL, "%s", b_string_ptr(str));
@@ -677,7 +677,7 @@ size_t b_strlen(const char *s, b_strlen_flags flags)
return out;
}
b_object_type_id b_string_type_id(void)
b_dsref_type_id b_string_type_id(void)
{
return (b_object_type_id)&string_type;
return (b_dsref_type_id)&string_type;
}

View File

@@ -7,7 +7,7 @@
#define STRING_INLINE_CAPACITY 15
struct b_string {
struct b_object s_base;
struct b_dsref s_base;
/* length of string, not including null-terminator */
unsigned int s_len;
/* maximum length of string storable in the currently-allocated buffer, not including null terminator */

View File

@@ -1,8 +1,8 @@
#include "tree.h"
#include <blue/object/object.h>
#include <blue/object/tree.h>
#include <blue/object/type.h>
#include <blue/ds/object.h>
#include <blue/ds/tree.h>
#include <blue/ds/type.h>
#include <stdlib.h>
#include <string.h>
@@ -16,17 +16,17 @@
#define NODE_FIRST_CHILD(n) ((n)->__p02)
#define NODE_NEXT_SIBLING(n) ((n)->__p03)
static struct b_object_type tree_type = {
static struct b_dsref_type tree_type = {
.t_name = "corelib::tree",
.t_flags = B_OBJECT_FUNDAMENTAL,
.t_id = B_OBJECT_TYPE_TREE,
.t_flags = B_DSREF_FUNDAMENTAL,
.t_id = B_DSREF_TYPE_TREE,
.t_instance_size = sizeof(struct b_tree),
};
struct b_tree *b_tree_create(void)
{
struct b_tree *tree
= (struct b_tree *)b_object_type_instantiate(&tree_type);
= (struct b_tree *)b_dsref_type_instantiate(&tree_type);
if (!tree) {
return NULL;
}
@@ -294,7 +294,7 @@ bool b_tree_iterator_is_valid(const struct b_tree_iterator *it)
return it->node != NULL;
}
b_object_type_id b_tree_type_id(void)
b_dsref_type_id b_tree_type_id(void)
{
return (b_object_type_id)&tree_type;
return (b_dsref_type_id)&tree_type;
}

View File

@@ -4,10 +4,10 @@
#include "../object.h"
#include <blue/core/queue.h>
#include <blue/object/tree.h>
#include <blue/ds/tree.h>
struct b_tree {
struct b_object t_base;
struct b_dsref t_base;
struct b_tree_node *t_root;
};

View File

@@ -1,17 +1,17 @@
#include "object.h"
#include <blue/core/queue.h>
#include <blue/object/type.h>
#include <blue/ds/type.h>
#include <stdlib.h>
#include <string.h>
struct b_object *b_object_type_instantiate(const b_object_type *type)
struct b_dsref *b_dsref_type_instantiate(const b_dsref_type *type)
{
if (!type || type->t_instance_size < sizeof(struct b_object)) {
if (!type || type->t_instance_size < sizeof(struct b_dsref)) {
return NULL;
}
struct b_object *out = malloc(type->t_instance_size);
struct b_dsref *out = malloc(type->t_instance_size);
if (!out) {
return NULL;
}

View File

@@ -1,25 +1,25 @@
#include "uuid.h"
#include <blue/core/stringstream.h>
#include <blue/object/string.h>
#include <blue/object/type.h>
#include <blue/object/uuid.h>
#include <blue/ds/string.h>
#include <blue/ds/type.h>
#include <blue/ds/uuid.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static struct b_object_type uuid_type = {
static struct b_dsref_type uuid_type = {
.t_name = "corelib::uuid",
.t_flags = B_OBJECT_FUNDAMENTAL,
.t_id = B_OBJECT_TYPE_UUID,
.t_flags = B_DSREF_FUNDAMENTAL,
.t_id = B_DSREF_TYPE_UUID,
.t_instance_size = sizeof(struct b_uuid),
};
struct b_uuid *b_uuid_create(void)
{
struct b_uuid *out
= (struct b_uuid *)b_object_type_instantiate(&uuid_type);
= (struct b_uuid *)b_dsref_type_instantiate(&uuid_type);
if (!out) {
return NULL;
}
@@ -192,7 +192,7 @@ struct b_uuid_bytes *b_uuid_ptr(struct b_uuid *uuid)
return &uuid->uuid_bytes;
}
b_object_type_id b_uuid_type_id(void)
b_dsref_type_id b_uuid_type_id(void)
{
return (b_object_type_id)&uuid_type;
return (b_dsref_type_id)&uuid_type;
}

View File

@@ -1,10 +1,10 @@
#ifndef _BLUELIB_UUID_H_
#define _BLUELIB_UUID_H_
#include <blue/object/uuid.h>
#include <blue/ds/uuid.h>
struct b_uuid {
struct b_object u_base;
struct b_dsref u_base;
struct b_uuid_bytes uuid_bytes;
};

View File

@@ -1,7 +1,7 @@
#include <CuTest.h>
#include <blue/core/stringstream.h>
#include <blue/io/path.h>
#include <blue/object/object.h>
#include <blue/ds/object.h>
#include <stdio.h>
void test_path_1(CuTest *tc)
@@ -11,7 +11,7 @@ void test_path_1(CuTest *tc)
b_stringstream str;
b_stringstream_begin(&str, buf, sizeof buf);
b_to_string(B_OBJECT(path), (b_stream *)&str);
b_to_string(B_DSREF(path), (b_stream *)&str);
printf("%s\n", buf);
@@ -23,7 +23,7 @@ void test_path_1(CuTest *tc)
b_path *path4 = b_path_join(paths, sizeof paths / sizeof paths[0]);
b_stringstream_begin(&str, buf, sizeof buf);
b_to_string(B_OBJECT(path4), (b_stream *)&str);
b_to_string(B_DSREF(path4), (b_stream *)&str);
printf("%s\n", buf);
}

View File

@@ -1,3 +1,3 @@
include(../cmake/Templates.cmake)
add_bluelib_module(NAME io DEPENDENCIES core object)
add_bluelib_module(NAME io DEPENDENCIES core ds)

View File

@@ -69,12 +69,12 @@ BLUE_API bool b_directory_iterator_is_valid(const b_directory_iterator *it);
static inline b_directory *b_directory_retain(b_directory *dir)
{
return B_DIRECTORY(b_retain(B_OBJECT(dir)));
return B_DIRECTORY(b_retain(B_DSREF(dir)));
}
static inline void b_directory_release(b_directory *dir)
{
b_release(B_OBJECT(dir));
b_release(B_DSREF(dir));
}
#endif

View File

@@ -4,7 +4,7 @@
#include <blue/core/error.h>
#include <blue/core/misc.h>
#include <blue/core/stream.h>
#include <blue/object/object.h>
#include <blue/ds/object.h>
#define B_FILE(p) ((b_file *)(p))
@@ -73,11 +73,11 @@ BLUE_API b_status b_file_write(
static inline b_file *b_file_retain(b_file *file)
{
return B_FILE(b_retain(B_OBJECT(file)));
return B_FILE(b_retain(B_DSREF(file)));
}
static inline void b_file_release(b_file *file)
{
b_release(B_OBJECT(file));
b_release(B_DSREF(file));
}
#endif

View File

@@ -3,7 +3,7 @@
#include <blue/core/misc.h>
#include <blue/core/status.h>
#include <blue/object/object.h>
#include <blue/ds/object.h>
#include <stddef.h>
#define B_PATH(p) ((b_path *)p)
@@ -43,12 +43,12 @@ BLUE_API size_t b_path_length(const b_path *path);
static inline b_path *b_path_retain(b_path *path)
{
return B_PATH(b_retain(B_OBJECT(path)));
return B_PATH(b_retain(B_DSREF(path)));
}
static inline void b_path_release(b_path *path)
{
b_release(B_OBJECT(path));
b_release(B_DSREF(path));
}
#endif

View File

@@ -3,7 +3,7 @@
#include <blue/core/error.h>
#include <blue/io/directory.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <errno.h>
#include <fcntl.h>
#include <fts.h>
@@ -17,7 +17,7 @@ enum directory_flags {
};
struct b_directory {
struct b_object base;
struct b_dsref base;
enum directory_flags flags;
int fd;
struct b_path *rel_path;
@@ -29,12 +29,12 @@ struct z__b_directory_iterator {
FTSENT *ent;
};
static void directory_release(struct b_object *obj);
static void directory_release(struct b_dsref *obj);
static struct b_object_type directory_type = {
static struct b_dsref_type directory_type = {
.t_name = "corelib::directory",
.t_flags = B_OBJECT_FUNDAMENTAL,
.t_id = B_OBJECT_TYPE_PATH,
.t_flags = B_DSREF_FUNDAMENTAL,
.t_id = B_DSREF_TYPE_PATH,
.t_instance_size = sizeof(struct b_directory),
.t_release = directory_release,
};
@@ -133,7 +133,7 @@ b_result b_directory_open(
}
struct b_directory *dir
= (struct b_directory *)b_object_type_instantiate(&directory_type);
= (struct b_directory *)b_dsref_type_instantiate(&directory_type);
struct b_path *cwd = NULL;
@@ -579,7 +579,7 @@ bool b_directory_iterator_is_valid(const struct b_directory_iterator *it)
return true;
}
static void directory_release(struct b_object *obj)
static void directory_release(struct b_dsref *obj)
{
struct b_directory *dir = B_DIRECTORY(obj);

View File

@@ -5,7 +5,7 @@
#include <blue/io/directory.h>
#include <blue/io/file.h>
#include <blue/io/path.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@@ -15,18 +15,18 @@
#include <unistd.h>
struct b_file {
struct b_object base;
struct b_dsref base;
enum b_file_mode mode;
int fd;
struct b_path *path;
};
static void file_release(struct b_object *obj);
static void file_release(struct b_dsref *obj);
static struct b_object_type file_type = {
static struct b_dsref_type file_type = {
.t_name = "corelib::file",
.t_flags = B_OBJECT_FUNDAMENTAL,
.t_id = B_OBJECT_TYPE_FILE,
.t_flags = B_DSREF_FUNDAMENTAL,
.t_id = B_DSREF_TYPE_FILE,
.t_instance_size = sizeof(struct b_file),
.t_release = file_release,
};
@@ -104,7 +104,7 @@ b_result b_file_open(
}
struct b_file *file
= (struct b_file *)b_object_type_instantiate(&file_type);
= (struct b_file *)b_dsref_type_instantiate(&file_type);
if (!file) {
close(fd);
b_path_release(abs_path);
@@ -482,7 +482,7 @@ enum b_status b_file_write(
return status;
}
static void file_release(struct b_object *obj)
static void file_release(struct b_dsref *obj)
{
struct b_file *file = (struct b_file *)obj;
close(file->fd);

View File

@@ -3,7 +3,7 @@
#include <blue/core/stringstream.h>
#include <blue/io/file.h>
#include <blue/io/path.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@@ -13,17 +13,17 @@
#include <unistd.h>
struct b_path {
struct b_object base;
struct b_dsref base;
struct b_string *pathstr;
};
static void path_release(struct b_object *obj);
static void path_to_string(struct b_object *obj, struct b_stream *out);
static void path_release(struct b_dsref *obj);
static void path_to_string(struct b_dsref *obj, struct b_stream *out);
static struct b_object_type path_type = {
static struct b_dsref_type path_type = {
.t_name = "corelib::path",
.t_flags = B_OBJECT_FUNDAMENTAL,
.t_id = B_OBJECT_TYPE_PATH,
.t_flags = B_DSREF_FUNDAMENTAL,
.t_id = B_DSREF_TYPE_PATH,
.t_instance_size = sizeof(struct b_path),
.t_release = path_release,
.t_to_string = path_to_string,
@@ -32,7 +32,7 @@ static struct b_object_type path_type = {
struct b_path *b_path_create()
{
struct b_path *path
= (struct b_path *)b_object_type_instantiate(&path_type);
= (struct b_path *)b_dsref_type_instantiate(&path_type);
if (!path) {
return NULL;
}
@@ -305,14 +305,14 @@ size_t b_path_length(const struct b_path *path)
return b_string_get_size(path->pathstr, B_STRLEN_NORMAL);
}
void path_release(struct b_object *obj)
void path_release(struct b_dsref *obj)
{
struct b_path *path = (struct b_path *)obj;
b_string_release(path->pathstr);
}
void path_to_string(struct b_object *obj, struct b_stream *out)
void path_to_string(struct b_dsref *obj, struct b_stream *out)
{
struct b_path *path = (struct b_path *)obj;

View File

@@ -6,7 +6,7 @@
#include <string.h>
struct b_directory {
struct b_object base;
struct b_dsref base;
HANDLE handle;
struct b_path *abs_path;
};
@@ -23,12 +23,12 @@ struct iteration_state {
bool child_search_complete;
};
static void directory_release(struct b_object *obj);
static void directory_release(struct b_dsref *obj);
static struct b_object_type directory_type = {
static struct b_dsref_type directory_type = {
.t_name = "corelib::directory",
.t_flags = B_OBJECT_FUNDAMENTAL,
.t_id = B_OBJECT_TYPE_PATH,
.t_flags = B_DSREF_FUNDAMENTAL,
.t_id = B_DSREF_TYPE_PATH,
.t_instance_size = sizeof(struct b_directory),
.t_release = directory_release,
};
@@ -89,7 +89,7 @@ enum b_status b_directory_open(
}
struct b_directory *dir
= (struct b_directory *)b_object_type_instantiate(&directory_type);
= (struct b_directory *)b_dsref_type_instantiate(&directory_type);
if (!path) {
CloseHandle(dir_handle);
b_path_release(new_path);
@@ -361,6 +361,6 @@ bool b_directory_iterator_is_valid(const struct b_directory_iterator *it)
return true;
}
static void directory_release(struct b_object *obj)
static void directory_release(struct b_dsref *obj)
{
}

View File

@@ -2,24 +2,24 @@
#include <blue/core/stringstream.h>
#include <blue/io/path.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <Windows.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
struct b_path {
struct b_object base;
struct b_dsref base;
struct b_string *pathstr;
};
static void path_release(struct b_object *obj);
static void path_to_string(struct b_object *obj, struct b_stringstream *out);
static void path_release(struct b_dsref *obj);
static void path_to_string(struct b_dsref *obj, struct b_stringstream *out);
static struct b_object_type path_type = {
static struct b_dsref_type path_type = {
.t_name = "corelib::path",
.t_flags = B_OBJECT_FUNDAMENTAL,
.t_id = B_OBJECT_TYPE_PATH,
.t_flags = B_DSREF_FUNDAMENTAL,
.t_id = B_DSREF_TYPE_PATH,
.t_instance_size = sizeof(struct b_path),
.t_release = path_release,
.t_to_string = path_to_string,
@@ -28,7 +28,7 @@ static struct b_object_type path_type = {
struct b_path *b_path_create()
{
struct b_path *path
= (struct b_path *)b_object_type_instantiate(&path_type);
= (struct b_path *)b_dsref_type_instantiate(&path_type);
if (!path) {
return NULL;
}
@@ -234,13 +234,13 @@ const char *b_path_ptr(const struct b_path *path)
return b_string_ptr(path->pathstr);
}
void path_release(struct b_object* obj)
void path_release(struct b_dsref* obj)
{
struct b_path *path = B_PATH(obj);
b_string_release(path->pathstr);
}
void path_to_string(struct b_object* obj, struct b_stringstream* out)
void path_to_string(struct b_dsref* obj, struct b_stringstream* out)
{
struct b_path *path = (struct b_path *)obj;

View File

@@ -1,3 +0,0 @@
include(../cmake/Templates.cmake)
add_bluelib_module(NAME object DEPENDENCIES core)

View File

@@ -1,40 +0,0 @@
#ifndef BLUELIB_OBJECT_H_
#define BLUELIB_OBJECT_H_
#include <blue/object/type.h>
#define B_OBJECT(p) ((b_object *)(p))
#define B_TYPEOF(object) ((struct b_object *)(object)->ob_type)
#define B_TYPEID(object) (b_typeid(B_OBJECT(object)))
#define B_RV(p) (b_make_rvalue(B_OBJECT(p)))
#define B_RVT(t, p) ((t *)(b_make_rvalue(B_OBJECT(p))))
#define B_OBJECT_IS(object, type) (B_TYPEID(object) == B_OBJECT_TYPE_##type)
struct b_string;
struct b_stream;
typedef enum b_comparison_result {
B_LESS = -1,
B_EQUAL = 0,
B_GREATER = 1,
} b_comparison_result_t;
typedef struct b_object {
unsigned int ob_ref;
const struct b_object_type *ob_type;
} b_object;
BLUE_API b_object *b_make_rvalue(b_object *obj);
BLUE_API b_object *b_retain(b_object *obj);
BLUE_API void b_release(b_object *obj);
BLUE_API void b_to_string(b_object *obj, struct b_stream *out);
BLUE_API b_object_type_id b_typeid(const b_object *obj);
BLUE_API b_comparison_result_t b_compare(const b_object *a, const b_object *b);
#endif

View File

@@ -1,53 +0,0 @@
#ifndef BLUELIB_TYPE_H_
#define BLUELIB_TYPE_H_
#include <blue/core/queue.h>
#include <blue/core/status.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define B_NPOS ((size_t)INTPTR_MAX)
struct b_object;
struct b_stream;
typedef uintptr_t b_object_type_id;
typedef enum b_fundamental_type_id {
B_OBJECT_TYPE_NONE = 0,
B_OBJECT_TYPE_ANY,
B_OBJECT_TYPE_LIST,
B_OBJECT_TYPE_ARRAY,
B_OBJECT_TYPE_BUFFER,
B_OBJECT_TYPE_DICT,
B_OBJECT_TYPE_ERROR,
B_OBJECT_TYPE_HASHMAP,
B_OBJECT_TYPE_NUMBER,
B_OBJECT_TYPE_STRING,
B_OBJECT_TYPE_TREE,
B_OBJECT_TYPE_UUID,
B_OBJECT_TYPE_PATH,
B_OBJECT_TYPE_FILE,
B_OBJECT_TYPE_DIRECTORY,
} b_fundamental_type_id;
typedef enum b_object_type_flags {
B_OBJECT_FUNDAMENTAL = 0x01u,
} b_object_type_flags;
typedef struct b_object_type {
b_object_type_flags t_flags;
char t_name[64];
size_t t_instance_size;
b_object_type_id t_id;
b_queue_entry t_entry;
void (*t_init)(struct b_object *);
void (*t_release)(struct b_object *);
void (*t_to_string)(struct b_object *, struct b_stream *);
} b_object_type;
BLUE_API b_status b_object_type_register(b_object_type *type);
BLUE_API struct b_object *b_object_type_instantiate(const b_object_type *type);
#endif

View File

@@ -1,6 +0,0 @@
#ifndef _BLUELIB_OBJECT_H_
#define _BLUELIB_OBJECT_H_
#include <blue/object/object.h>
#endif

View File

@@ -1,8 +1,8 @@
#include <blue/core/stream.h>
#include <blue/object/array.h>
#include <blue/object/dict.h>
#include <blue/object/number.h>
#include <blue/object/string.h>
#include <blue/ds/array.h>
#include <blue/ds/dict.h>
#include <blue/ds/number.h>
#include <blue/ds/string.h>
#include <blue/serial.h>
#include <stdio.h>
@@ -26,11 +26,11 @@ int main(void)
b_dict_put(dict, "strings", B_RV(array));
b_to_string(B_OBJECT(dict), b_stdout);
b_to_string(B_DSREF(dict), b_stdout);
b_stream_write_char(b_stdout, '\n');
b_serial_ctx_serialise(
ctx, B_SERIAL_FORMAT_JSON, B_OBJECT(dict), b_stdout, 0);
ctx, B_SERIAL_FORMAT_JSON, B_DSREF(dict), b_stdout, 0);
b_dict_release(dict);
b_serial_ctx_destroy(ctx);

View File

@@ -1,3 +1,3 @@
include(../cmake/Templates.cmake)
add_bluelib_module(NAME serial DEPENDENCIES core object)
add_bluelib_module(NAME serial DEPENDENCIES core ds)

View File

@@ -5,7 +5,7 @@
#include <blue/core/status.h>
#include <blue/core/stream.h>
struct b_object;
struct b_dsref;
typedef enum b_serial_format {
B_SERIAL_FORMAT_NONE = 0,
@@ -24,11 +24,11 @@ BLUE_API b_status b_serial_ctx_create(b_serial_ctx **out);
BLUE_API b_status b_serial_ctx_destroy(b_serial_ctx *ctx);
BLUE_API b_status b_serial_ctx_serialise(
b_serial_ctx *ctx, b_serial_format fmt, struct b_object *src,
b_serial_ctx *ctx, b_serial_format fmt, struct b_dsref *src,
b_stream *dest, b_serial_flags flags);
BLUE_API b_status b_serial_ctx_deserialise(
b_serial_ctx *ctx, b_serial_format fmt, b_stream *src,
struct b_object **dest, b_serial_flags flags);
struct b_dsref **dest, b_serial_flags flags);
#endif

View File

@@ -37,12 +37,12 @@
#pragma warning(disable : 4001)
#endif
#include <blue/object/array.h>
#include <blue/object/dict.h>
#include <blue/object/number.h>
#include <blue/object/object.h>
#include <blue/object/string.h>
#include <blue/object/uuid.h>
#include <blue/ds/array.h>
#include <blue/ds/dict.h>
#include <blue/ds/number.h>
#include <blue/ds/object.h>
#include <blue/ds/string.h>
#include <blue/ds/uuid.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
@@ -2933,9 +2933,9 @@ CJSON_PUBLIC(void) cJSON_free(void *object)
object = NULL;
}
static enum b_status b_object_to_cJSON(const struct b_object *object, cJSON **out);
static enum b_status b_dsref_to_cJSON(const struct b_dsref *object, cJSON **out);
static enum b_status serialise_array(const struct b_object *object, cJSON **out)
static enum b_status serialise_array(const struct b_dsref *object, cJSON **out)
{
cJSON *json_array = cJSON_CreateArray();
if (!json_array) {
@@ -2947,7 +2947,7 @@ static enum b_status serialise_array(const struct b_object *object, cJSON **out)
b_array_foreach(&it, array)
{
cJSON *child = NULL;
enum b_status status = b_object_to_cJSON(it.value, &child);
enum b_status status = b_dsref_to_cJSON(it.value, &child);
if (!B_OK(status)) {
cJSON_Delete(json_array);
return status;
@@ -2960,7 +2960,7 @@ static enum b_status serialise_array(const struct b_object *object, cJSON **out)
return B_SUCCESS;
}
static enum b_status serialise_dict(const struct b_object *object, cJSON **out)
static enum b_status serialise_dict(const struct b_dsref *object, cJSON **out)
{
cJSON *json_dict = cJSON_CreateObject();
if (!json_dict) {
@@ -2972,7 +2972,7 @@ static enum b_status serialise_dict(const struct b_object *object, cJSON **out)
b_dict_foreach(&it, dict)
{
cJSON *child = NULL;
enum b_status status = b_object_to_cJSON(it.value, &child);
enum b_status status = b_dsref_to_cJSON(it.value, &child);
if (!B_OK(status)) {
cJSON_Delete(json_dict);
return status;
@@ -2985,7 +2985,7 @@ static enum b_status serialise_dict(const struct b_object *object, cJSON **out)
return B_SUCCESS;
}
static enum b_status serialise_number(const struct b_object *object, cJSON **out)
static enum b_status serialise_number(const struct b_dsref *object, cJSON **out)
{
cJSON *json_number = cJSON_CreateNumber(0);
if (!json_number) {
@@ -3049,7 +3049,7 @@ static enum b_status serialise_number(const struct b_object *object, cJSON **out
return B_SUCCESS;
}
static enum b_status serialise_string(const struct b_object *object, cJSON **out)
static enum b_status serialise_string(const struct b_dsref *object, cJSON **out)
{
struct b_string *string = B_STRING(object);
cJSON *json_string = cJSON_CreateStringReference(b_string_ptr(string));
@@ -3061,7 +3061,7 @@ static enum b_status serialise_string(const struct b_object *object, cJSON **out
return B_SUCCESS;
}
static enum b_status serialise_uuid(const struct b_object *object, cJSON **out)
static enum b_status serialise_uuid(const struct b_dsref *object, cJSON **out)
{
struct b_uuid *uuid = B_UUID(object);
char s[B_UUID_STRING_MAX];
@@ -3077,21 +3077,21 @@ static enum b_status serialise_uuid(const struct b_object *object, cJSON **out)
}
typedef enum b_status (*object_serialise_callback)(
const struct b_object *, cJSON **);
const struct b_dsref *, cJSON **);
static const object_serialise_callback object_serialise[] = {
[B_OBJECT_TYPE_ARRAY] = serialise_array,
[B_OBJECT_TYPE_DICT] = serialise_dict,
[B_OBJECT_TYPE_NUMBER] = serialise_number,
[B_OBJECT_TYPE_STRING] = serialise_string,
[B_OBJECT_TYPE_UUID] = serialise_uuid,
[B_DSREF_TYPE_ARRAY] = serialise_array,
[B_DSREF_TYPE_DICT] = serialise_dict,
[B_DSREF_TYPE_NUMBER] = serialise_number,
[B_DSREF_TYPE_STRING] = serialise_string,
[B_DSREF_TYPE_UUID] = serialise_uuid,
};
static const size_t nr_object_serialise
= sizeof object_serialise / sizeof object_serialise[0];
static enum b_status b_object_to_cJSON(const struct b_object *object, cJSON **out)
static enum b_status b_dsref_to_cJSON(const struct b_dsref *object, cJSON **out)
{
b_object_type_id type = b_typeid(object);
b_dsref_type_id type = b_typeid(object);
if (type >= nr_object_serialise) {
return B_ERR_NOT_SUPPORTED;
}
@@ -3104,9 +3104,9 @@ static enum b_status b_object_to_cJSON(const struct b_object *object, cJSON **ou
return callback(object, out);
}
static enum b_status cJSON_to_b_object(cJSON *json, struct b_object **out);
static enum b_status cJSON_to_b_dsref(cJSON *json, struct b_dsref **out);
static enum b_status deserialise_dict(cJSON *json, struct b_object **out)
static enum b_status deserialise_dict(cJSON *json, struct b_dsref **out)
{
struct b_dict *dict = b_dict_create();
if (!dict) {
@@ -3117,8 +3117,8 @@ static enum b_status deserialise_dict(cJSON *json, struct b_object **out)
enum b_status status = B_SUCCESS;
while (item) {
struct b_object *child = NULL;
status = cJSON_to_b_object(item, &child);
struct b_dsref *child = NULL;
status = cJSON_to_b_dsref(item, &child);
if (!B_OK(status)) {
b_dict_release(dict);
dict = NULL;
@@ -3133,11 +3133,11 @@ static enum b_status deserialise_dict(cJSON *json, struct b_object **out)
item = item->next;
}
*out = B_OBJECT(dict);
*out = B_DSREF(dict);
return B_SUCCESS;
}
static enum b_status deserialise_array(cJSON *json, struct b_object **out)
static enum b_status deserialise_array(cJSON *json, struct b_dsref **out)
{
struct b_array *array = b_array_create();
if (!array) {
@@ -3148,8 +3148,8 @@ static enum b_status deserialise_array(cJSON *json, struct b_object **out)
enum b_status status = B_SUCCESS;
while (item) {
struct b_object *child = NULL;
status = cJSON_to_b_object(item, &child);
struct b_dsref *child = NULL;
status = cJSON_to_b_dsref(item, &child);
if (!B_OK(status)) {
b_array_release(array);
array = NULL;
@@ -3164,22 +3164,22 @@ static enum b_status deserialise_array(cJSON *json, struct b_object **out)
item = item->next;
}
*out = B_OBJECT(array);
*out = B_DSREF(array);
return B_SUCCESS;
}
static enum b_status deserialise_string(cJSON *json, struct b_object **out)
static enum b_status deserialise_string(cJSON *json, struct b_dsref **out)
{
struct b_string *string = b_string_create_from_cstr(json->valuestring);
if (!string) {
return B_ERR_NO_MEMORY;
}
*out = B_OBJECT(string);
*out = B_DSREF(string);
return B_SUCCESS;
}
static enum b_status deserialise_number(cJSON *json, struct b_object **out)
static enum b_status deserialise_number(cJSON *json, struct b_dsref **out)
{
struct b_number *number = NULL;
@@ -3193,11 +3193,11 @@ static enum b_status deserialise_number(cJSON *json, struct b_object **out)
return B_ERR_NO_MEMORY;
}
*out = B_OBJECT(number);
*out = B_DSREF(number);
return B_SUCCESS;
}
static enum b_status deserialise_bool(cJSON *json, struct b_object **out)
static enum b_status deserialise_bool(cJSON *json, struct b_dsref **out)
{
struct b_number *number = NULL;
@@ -3211,11 +3211,11 @@ static enum b_status deserialise_bool(cJSON *json, struct b_object **out)
return B_ERR_NO_MEMORY;
}
*out = B_OBJECT(number);
*out = B_DSREF(number);
return B_SUCCESS;
}
static enum b_status cJSON_to_b_object(cJSON *json, struct b_object **out)
static enum b_status cJSON_to_b_dsref(cJSON *json, struct b_dsref **out)
{
switch (json->type) {
case cJSON_True:
@@ -3238,11 +3238,11 @@ static enum b_status cJSON_to_b_object(cJSON *json, struct b_object **out)
}
static enum b_status json_serialise(
struct b_serial_ctx *ctx, struct b_object *src, struct b_stream *dest,
struct b_serial_ctx *ctx, struct b_dsref *src, struct b_stream *dest,
enum b_serial_flags flags)
{
cJSON *json;
enum b_status status = b_object_to_cJSON(src, &json);
enum b_status status = b_dsref_to_cJSON(src, &json);
if (!B_OK(status)) {
return status;
@@ -3269,7 +3269,7 @@ static enum b_status json_serialise(
}
static enum b_status json_deserialise(
struct b_serial_ctx *ctx, struct b_stream *src, struct b_object **dest,
struct b_serial_ctx *ctx, struct b_stream *src, struct b_dsref **dest,
enum b_serial_flags flags)
{
struct b_string *json_string = b_string_create();
@@ -3294,7 +3294,7 @@ static enum b_status json_deserialise(
return B_ERR_BAD_FORMAT;
}
status = cJSON_to_b_object(json, dest);
status = cJSON_to_b_dsref(json, dest);
cJSON_Delete(json);

View File

@@ -51,7 +51,7 @@ static const struct b_serial_format_ops *get_formatter(enum b_serial_format fmt)
enum b_status b_serial_ctx_serialise(
struct b_serial_ctx *ctx, enum b_serial_format fmt,
struct b_object *src, struct b_stream *dest, enum b_serial_flags flags)
struct b_dsref *src, struct b_stream *dest, enum b_serial_flags flags)
{
const struct b_serial_format_ops *ops = get_formatter(fmt);
if (!ops) {
@@ -67,7 +67,7 @@ enum b_status b_serial_ctx_serialise(
enum b_status b_serial_ctx_deserialise(
struct b_serial_ctx *ctx, enum b_serial_format fmt,
struct b_stream *src, struct b_object **dest, enum b_serial_flags flags)
struct b_stream *src, struct b_dsref **dest, enum b_serial_flags flags)
{
const struct b_serial_format_ops *ops = get_formatter(fmt);
if (!ops) {

View File

@@ -10,10 +10,10 @@ struct b_serial_ctx {
struct b_serial_format_ops {
enum b_status (*fmt_serialise)(
struct b_serial_ctx *, struct b_object *, struct b_stream *,
struct b_serial_ctx *, struct b_dsref *, struct b_stream *,
enum b_serial_flags);
enum b_status (*fmt_deserialise)(
struct b_serial_ctx *, struct b_stream *, struct b_object **,
struct b_serial_ctx *, struct b_stream *, struct b_dsref **,
enum b_serial_flags);
};

View File

@@ -1,6 +1,6 @@
#include <blue/term/tty.h>
#include <blue/term/print.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <stdio.h>
#define F_GREEN "[green]"

View File

@@ -1,3 +1,3 @@
include(../cmake/Templates.cmake)
add_bluelib_module(NAME term DEPENDENCIES core object)
add_bluelib_module(NAME term DEPENDENCIES core ds)

View File

@@ -1,6 +1,6 @@
#include "print.h"
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <blue/term/print.h>
#include <ctype.h>
#include <stdbool.h>

View File

@@ -1,7 +1,7 @@
#include <blue/core/stream.h>
#include <blue/io/file.h>
#include <blue/io/path.h>
#include <blue/object/string.h>
#include <blue/ds/string.h>
#include <stdio.h>
int main(int argc, const char **argv)

View File

@@ -26,7 +26,7 @@ int main(int argc, const char **argv)
b_serial_ctx *ctx;
b_serial_ctx_create(&ctx);
b_object *data;
b_dsref *data;
b_status status = b_serial_ctx_deserialise(
ctx, B_SERIAL_FORMAT_JSON, src_stream, &data, 0);
if (!B_OK(status)) {
@@ -34,7 +34,7 @@ int main(int argc, const char **argv)
return -1;
}
b_to_string(B_OBJECT(data), b_stdout);
b_to_string(B_DSREF(data), b_stdout);
b_stream_write_char(b_stdout, '\n');
b_release(data);