8#include "../nyx_node_internal.h"
12static void internal_list_clear(
42 internal_list_clear(
object);
49static void internal_list_clear(
nyx_list_t *
object)
53 for(nyx_list_node_t *node = object->head; node != NULL;)
57 nyx_list_node_t *temp = node;
63 temp->value->parent = NULL;
65 nyx_object_unref(temp->value);
84 internal_list_clear(
object);
93 for(nyx_list_node_t *prev_node = NULL, *curr_node = object->head; curr_node != NULL; prev_node = curr_node, curr_node = curr_node->next, idx--)
101 object->head = curr_node->next;
105 prev_node->next = curr_node->next;
110 if(curr_node == object->tail)
112 object->tail = prev_node;
117 curr_node->value->parent = NULL;
119 nyx_object_unref(curr_node->value);
136 if(iter->
head != NULL)
143 *
object = iter->
head->value;
146 iter->
idx += 0x0000000000001;
161 for(nyx_list_node_t *curr_node = object->head; curr_node != NULL; curr_node = curr_node->next, idx--)
165 return curr_node->value;
176bool nyx_list_set(
nyx_list_t *
object,
size_t idx,
void *value)
180 if(!NYX_OBJECT_CHECK_MAGIC(value))
206 bool modified =
true;
208 for(nyx_list_node_t *curr_node = object->head; curr_node != NULL; curr_node = curr_node->next, idx--)
212 modified = !nyx_object_equal(curr_node->value, value);
214 curr_node->value->parent = NULL;
216 nyx_object_ref( value );
217 nyx_object_unref(curr_node->value);
219 curr_node->value = value;
229 nyx_object_ref(value);
236 if(object->head == NULL)
243 object->tail->next = node;
262 for(nyx_list_node_t *node = object->head; node != NULL; node = node->next, result++) { };
273 nyx_string_builder_t *sb = nyx_string_builder_new();
275 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
"[");
277 for(nyx_list_node_t *curr_node = object->head; curr_node != NULL; curr_node = curr_node->next)
281 str_t curr_node_val = nyx_object_to_string(curr_node->value);
283 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE, curr_node_val);
289 if(curr_node->next != NULL)
291 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
",");
296 nyx_string_builder_append(sb, NYX_SB_NO_ESCAPE,
"]");
298 str_t result = nyx_string_builder_to_string(sb);
300 nyx_string_builder_free(sb);
struct nyx_list_node_s * head
Next JSON object to visit.
size_t idx
Current zero-based iteration index.
str_t nyx_list_to_string(const nyx_list_t *object)
Returns a string representing the provided JSON list object.
void nyx_list_del(nyx_list_t *object, size_t idx)
Deletes the entry at the provided index.
bool nyx_list_iterate(nyx_list_iter_t *iter, size_t *idx, nyx_object_t **object)
Iterates over a JSON list object.
nyx_list_t * nyx_list_new(void)
Allocates a new JSON list.
nyx_object_t * nyx_list_get(const nyx_list_t *object, size_t idx)
Gets the JSON object at the provided index.
size_t nyx_list_size(const nyx_list_t *object)
Gets the number of items in the provided JSON list object.
void nyx_list_clear(nyx_list_t *object)
Clears the content of the provided JSON list object.
Struct describing a JSON list iterator.
Struct describing a JSON list object.
#define NYX_LOG_FATAL(fmt,...)
Logs a fatal message.
#define NYX_LOG_ERROR(fmt,...)
Logs an error message.
__NYX_NULLABLE__ buff_t nyx_memory_alloc(__NYX_ZEROABLE__ size_t size)
Similar to libc malloc except that a memory overflow causes the node to stop.
__NYX_ZEROABLE__ size_t nyx_memory_free(__NYX_NULLABLE__ buff_t buff)
Similar to libc free except that it returns the amount of memory freed.
#define str_t
Alias for char *.
@ NYX_TYPE_LIST
List object.
Struct describing a JSON object.