fx: re-arrange type system to allow for reflection
This commit is contained in:
+70
-50
@@ -282,8 +282,9 @@ static fx_string *string_duplicate(const struct fx_string_p *str)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct fx_string_p *new_str_p
|
||||
= fx_object_get_private(new_str, FX_TYPE_STRING);
|
||||
struct fx_string_p *new_str_p = fx_object_get_private(
|
||||
new_str,
|
||||
FX_TYPE_STRING);
|
||||
|
||||
string_change_capacity(new_str_p, str->s_len);
|
||||
const char *src = string_ptr(str);
|
||||
@@ -385,8 +386,9 @@ static enum fx_status replace_utf8(
|
||||
}
|
||||
|
||||
size_t new_data_nr_bytes = strlen(new_data);
|
||||
size_t new_data_nr_codepoints
|
||||
= fx_wchar_utf8_codepoint_count(new_data, new_data_nr_bytes);
|
||||
size_t new_data_nr_codepoints = fx_wchar_utf8_codepoint_count(
|
||||
new_data,
|
||||
new_data_nr_bytes);
|
||||
if (new_data_nr_codepoints == 0) {
|
||||
/* new_data is not a valid utf-8 string */
|
||||
return FX_ERR_INVALID_ARGUMENT;
|
||||
@@ -404,8 +406,8 @@ static enum fx_status replace_utf8(
|
||||
return status;
|
||||
}
|
||||
|
||||
size_t new_total_bytes
|
||||
= str->s_len - old_data_nr_bytes + new_data_nr_bytes;
|
||||
size_t new_total_bytes = str->s_len - old_data_nr_bytes
|
||||
+ new_data_nr_bytes;
|
||||
if (new_total_bytes > str->s_max) {
|
||||
status = string_reserve(str, new_total_bytes);
|
||||
}
|
||||
@@ -734,8 +736,9 @@ static enum fx_status string_insert_wstr_ansi(
|
||||
at = dest->s_len;
|
||||
}
|
||||
|
||||
size_t utf8_encoded_size
|
||||
= fx_wchar_utf8_string_encoded_size(src, nr_codepoints);
|
||||
size_t utf8_encoded_size = fx_wchar_utf8_string_encoded_size(
|
||||
src,
|
||||
nr_codepoints);
|
||||
if (utf8_encoded_size == 0) {
|
||||
return FX_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
@@ -782,8 +785,9 @@ static enum fx_status string_insert_wstr_utf8(
|
||||
codepoint_offset = dest->s_codepoints;
|
||||
}
|
||||
|
||||
size_t utf8_encoded_size
|
||||
= fx_wchar_utf8_string_encoded_size(src, nr_codepoints);
|
||||
size_t utf8_encoded_size = fx_wchar_utf8_string_encoded_size(
|
||||
src,
|
||||
nr_codepoints);
|
||||
if (utf8_encoded_size == 0) {
|
||||
return FX_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
@@ -1026,8 +1030,9 @@ static fx_iterator *string_tokenise(
|
||||
}
|
||||
|
||||
fx_string_iterator *it_obj = fx_object_create(FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it
|
||||
= fx_object_get_private(it_obj, FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it = fx_object_get_private(
|
||||
it_obj,
|
||||
FX_TYPE_STRING_ITERATOR);
|
||||
|
||||
it->_m = ITERATOR_MODE_TOKENS;
|
||||
it->_d = delims;
|
||||
@@ -1136,8 +1141,9 @@ static fx_string *string_substr(
|
||||
}
|
||||
|
||||
fx_string *newstr = fx_string_create();
|
||||
struct fx_string_p *newstr_p
|
||||
= fx_object_get_private(newstr, FX_TYPE_STRING);
|
||||
struct fx_string_p *newstr_p = fx_object_get_private(
|
||||
newstr,
|
||||
FX_TYPE_STRING);
|
||||
string_reserve(newstr_p, len);
|
||||
|
||||
const char *src = string_ptr(str) + start;
|
||||
@@ -1304,10 +1310,12 @@ enum fx_status fx_string_insert_s(
|
||||
const fx_string *src,
|
||||
size_t at)
|
||||
{
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
const struct fx_string_p *src_p
|
||||
= fx_object_get_private(src, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p = fx_object_get_private(
|
||||
dest,
|
||||
FX_TYPE_STRING);
|
||||
const struct fx_string_p *src_p = fx_object_get_private(
|
||||
src,
|
||||
FX_TYPE_STRING);
|
||||
return string_insert_s(dest_p, src_p, at);
|
||||
}
|
||||
|
||||
@@ -1316,8 +1324,9 @@ enum fx_status fx_string_insert_cstr(
|
||||
const char *src,
|
||||
size_t at)
|
||||
{
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p = fx_object_get_private(
|
||||
dest,
|
||||
FX_TYPE_STRING);
|
||||
return string_insert_cstr(dest_p, src, strlen(src), at);
|
||||
}
|
||||
|
||||
@@ -1326,8 +1335,9 @@ enum fx_status fx_string_insert_wstr(
|
||||
const fx_wchar *src,
|
||||
size_t at)
|
||||
{
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p = fx_object_get_private(
|
||||
dest,
|
||||
FX_TYPE_STRING);
|
||||
return string_insert_wstr(dest_p, src, fx_wstrlen(src), at);
|
||||
}
|
||||
|
||||
@@ -1337,8 +1347,9 @@ enum fx_status fx_string_insert_cstrf(
|
||||
const char *format,
|
||||
...)
|
||||
{
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p = fx_object_get_private(
|
||||
dest,
|
||||
FX_TYPE_STRING);
|
||||
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
@@ -1365,8 +1376,9 @@ enum fx_status fx_string_insert_cstrn(
|
||||
|
||||
enum fx_status fx_string_append_cstrf(fx_string *dest, const char *format, ...)
|
||||
{
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p = fx_object_get_private(
|
||||
dest,
|
||||
FX_TYPE_STRING);
|
||||
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
@@ -1378,8 +1390,9 @@ enum fx_status fx_string_append_cstrf(fx_string *dest, const char *format, ...)
|
||||
|
||||
enum fx_status fx_string_prepend_cstrf(fx_string *dest, const char *format, ...)
|
||||
{
|
||||
struct fx_string_p *dest_p
|
||||
= fx_object_get_private(dest, FX_TYPE_STRING);
|
||||
struct fx_string_p *dest_p = fx_object_get_private(
|
||||
dest,
|
||||
FX_TYPE_STRING);
|
||||
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
@@ -1545,8 +1558,9 @@ static void string_to_string(const fx_object *obj, fx_stream *out)
|
||||
|
||||
static void iterator_fini(fx_iterator *obj)
|
||||
{
|
||||
struct fx_string_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_TYPE_STRING_ITERATOR);
|
||||
if (it->_tmp) {
|
||||
fx_string_unref(it->_tmp);
|
||||
}
|
||||
@@ -1557,8 +1571,9 @@ static void iterator_fini(fx_iterator *obj)
|
||||
static fx_iterator *iterator_begin(fx_object *obj)
|
||||
{
|
||||
fx_string_iterator *it_obj = fx_object_create(FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it
|
||||
= fx_object_get_private(it_obj, FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it = fx_object_get_private(
|
||||
it_obj,
|
||||
FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_p *p = fx_object_get_private(obj, FX_TYPE_STRING);
|
||||
|
||||
if (!p->s_len) {
|
||||
@@ -1631,8 +1646,9 @@ static enum fx_status tokens_iterator_move_next(struct fx_string_iterator_p *it)
|
||||
|
||||
static enum fx_status iterator_move_next(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_string_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_TYPE_STRING_ITERATOR);
|
||||
|
||||
switch (it->_m) {
|
||||
case ITERATOR_MODE_CHARS:
|
||||
@@ -1658,8 +1674,9 @@ static fx_iterator_value tokens_iterator_get_value(
|
||||
|
||||
static fx_iterator_value iterator_get_value(fx_iterator *obj)
|
||||
{
|
||||
struct fx_string_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_TYPE_STRING_ITERATOR);
|
||||
|
||||
switch (it->_m) {
|
||||
case ITERATOR_MODE_CHARS:
|
||||
@@ -1673,8 +1690,9 @@ static fx_iterator_value iterator_get_value(fx_iterator *obj)
|
||||
|
||||
static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
||||
{
|
||||
struct fx_string_iterator_p *it
|
||||
= fx_object_get_private(obj, FX_TYPE_STRING_ITERATOR);
|
||||
struct fx_string_iterator_p *it = fx_object_get_private(
|
||||
obj,
|
||||
FX_TYPE_STRING_ITERATOR);
|
||||
|
||||
switch (it->_m) {
|
||||
case ITERATOR_MODE_CHARS:
|
||||
@@ -1689,19 +1707,20 @@ static const fx_iterator_value iterator_get_cvalue(const fx_iterator *obj)
|
||||
/*** CLASS DEFINITION *********************************************************/
|
||||
|
||||
// ---- fx_string DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_string)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_string)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = string_to_string;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_INTERFACE_ENTRY(it_begin) = iterator_begin;
|
||||
FX_INTERFACE_ENTRY(it_cbegin) = iterator_cbegin;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_string)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterable, FX_TYPE_ITERABLE)
|
||||
FX_TYPE_CLASS_END(fx_string)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_string)
|
||||
FX_TYPE_ID(0x200194f6, 0x0327, 0x4a82, 0xb9c9, 0xb62ddd038c33);
|
||||
FX_TYPE_NAME("fx.string");
|
||||
FX_TYPE_IMPLEMENTS(FX_TYPE_ITERABLE);
|
||||
FX_TYPE_CLASS(fx_string_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_string_p);
|
||||
@@ -1710,21 +1729,22 @@ FX_TYPE_DEFINITION_BEGIN(fx_string)
|
||||
FX_TYPE_DEFINITION_END(fx_string)
|
||||
|
||||
// ---- fx_string_iterator DEFINITION
|
||||
FX_TYPE_CLASS_DEFINITION_BEGIN(fx_string_iterator)
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_CLASS_BEGIN(fx_string_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
||||
FX_INTERFACE_ENTRY(to_string) = NULL;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
||||
|
||||
FX_TYPE_CLASS_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_INTERFACE_ENTRY(it_move_next) = iterator_move_next;
|
||||
FX_INTERFACE_ENTRY(it_erase) = NULL;
|
||||
FX_INTERFACE_ENTRY(it_get_value) = iterator_get_value;
|
||||
FX_INTERFACE_ENTRY(it_get_cvalue) = iterator_get_cvalue;
|
||||
FX_TYPE_CLASS_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_DEFINITION_END(fx_string_iterator)
|
||||
FX_TYPE_VTABLE_INTERFACE_END(fx_iterator, FX_TYPE_ITERATOR)
|
||||
FX_TYPE_CLASS_END(fx_string_iterator)
|
||||
|
||||
FX_TYPE_DEFINITION_BEGIN(fx_string_iterator)
|
||||
FX_TYPE_ID(0xfc06cee1, 0xb63a, 0x4718, 0x9b8e, 0x3bd2eb7a8608);
|
||||
FX_TYPE_NAME("fx.string.iterator");
|
||||
FX_TYPE_EXTENDS(FX_TYPE_ITERATOR);
|
||||
FX_TYPE_CLASS(fx_string_iterator_class);
|
||||
FX_TYPE_INSTANCE_PRIVATE(struct fx_string_iterator_p);
|
||||
|
||||
Reference in New Issue
Block a user