57
57
typedef struct SDynamicArray SDynamicArray;
59
typedef struct SDynamicArrayPrivate SDynamicArrayPrivate;
63
SDynamicArrayPrivate * priv;
68
#define S_DYNAMIC_ARRAY(k) (SDynamicArray *)(k)
60
#define S_DYNAMIC_ARRAY(k) ((SDynamicArray *)(k))
71
63
* Create a new dynamic array.
73
65
* @param len The length of the initial array.
74
* @param free_func The function to be used when freeing the items. Can be \c NULL.
66
* @param free_func The function to be used when freeing the items. Can be NULL.
75
67
* If free_func is NULL, it will use the standard library's
78
* Normally a function with the signature <tt> (DynamicArray * self,
79
spointer item, spointer data) </tt> should be used but cast to FreeFunc.
82
s_dynamic_array_new (size_t len, FreeFunc free_func);
70
* The free function should have the the signature <tt> (DynamicArray * self,
71
* spointer item, spointer data) </tt> should be used but cast to FreeFunc.
74
s_dynamic_array_new (size_t len,
78
* Same as s_dynamic_array_new() but with support for to_json and from_json
81
* @param to_json This function is used, on an item basis, to serialise the data
82
* in that item into a json representation.
84
* @param from_json This function talkes a string and marchal it into an object.
86
* The to_json function should have the signature:
87
* <tt>char * name (spointer item)</tt> and return a string.
88
* If this is not set, it will return <tt>"(pointer)"</tt>.
90
* The from_json function should have the signature:
91
* <tt>spointer name (char * json)</tt>.
92
* If this function is not set, the s_matrix_deserialize_json() function will
96
s_dynamic_array_new_json (size_t len,
99
FuncPointer from_json);
85
102
* Frees the dynamic array.
147
164
s_dynamic_array_for_each_with_return (SDynamicArray * self,
169
* Returns a JSON representation of the array.
171
* If the to_json function is not set, this will return <tt>(pointer)</tt> for
174
* @param self The SDynamicArray to get the JSON representation from.
176
* @return a string with the JSON representation of the SDynamicArray.
179
s_dynamic_array_serialize_json (SDynamicArray * self);
182
* appends itmes to an the array
184
* If the from_json function is not set, this will couse undefined behaviour.
187
s_dynamic_array_deserialize_json (SDynamicArray * self, char * json);