/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk

« back to all changes in this revision

Viewing changes to libssts/DynamicArray.h

  • Committer: Gustav Hartvigsson
  • Date: 2015-10-24 19:55:57 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20151024195557-lpmkc68r52x4t63h
* General cleanup/make it pritty.
* Added s_dynamic_array_append.
* Implimented the new Error System w/ error domains.
* Added s_string_is_equal
* changed char to schar here and there.
TODO:
  Change the tests to match the new error system.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 * SDynamicArray is an imlpementation of a dynamic array, it is usefule when
37
37
 * dealing with lare amounts of data that may change over time, or with an
38
38
 * unknowned numebr of items.
39
 
 * 
 
39
 *
40
40
 * Note that accsess time is constant, but write time is not guarenteed to be.
41
 
 * 
 
41
 *
42
42
 * When the size of the array is equal to the number of elements in it, it will
43
43
 * re-allocate the array with a larger size.
44
44
 */
64
64
 *
65
65
 * @param len The length of the initial array.
66
66
 * @param free_func The function to be used when freeing the items. Can be NULL.
67
 
 *        If free_func is NULL, it will use the standard library's 
 
67
 *        If free_func is NULL, it will use the standard library's
68
68
 *       <tt>free()</tt>.
69
69
 *
70
70
 * The free function should have the the signature <tt> (DynamicArray * self,
100
100
 
101
101
/**
102
102
 * Frees the dynamic array.
103
 
 * 
 
103
 *
104
104
 * after this is run the data will be lost.
105
105
 */
106
106
void
107
 
s_dynamic_array_free (SDynamicArray * self, sboolean free_data);
 
107
s_dynamic_array_free (SDynamicArray * self,
 
108
                      sboolean free_data);
108
109
 
109
110
 
110
111
/**
111
112
 * Get an item from the array.
112
113
 */
113
114
spointer
114
 
s_dynamic_array_get (SDynamicArray * self, size_t index);
 
115
s_dynamic_array_get (SDynamicArray * self,
 
116
                     size_t index);
115
117
 
116
118
/**
117
 
 *
118
 
 */
119
 
void
120
 
s_dynamic_array_set (SDynamicArray * self, size_t index, spointer item);
 
119
 * Set an item at index.
 
120
 *
 
121
 * @param self The Dynamic Array to set the item on.
 
122
 * @param index The index at which to set the item.
 
123
 * @para item The item to put in the array.
 
124
 */
 
125
void
 
126
s_dynamic_array_set (SDynamicArray * self,
 
127
                     size_t index,
 
128
                     spointer item);
 
129
/**
 
130
 * Append an item to a dynamic array.
 
131
 * @note The item will not be added to the first free slot in the array, but
 
132
 *       in the first slot after the last item.
 
133
 *
 
134
 * @param self The dynamic array to add the item to.
 
135
 * @param item The item to add.
 
136
 */
 
137
void
 
138
s_dynamic_array_append (SDynamicArray * self,
 
139
                        spointer item);
121
140
 
122
141
/**
123
142
 * Get the size of the array, this is not the same as the length of the array.
124
143
 * The size is the number of elements that can be allocated without resizing
125
144
 * the array.
126
 
 * 
 
145
 *
127
146
 * To get the length of the array use s_dynamic_array_len ().
128
147
 */
129
148
size_t
141
160
 
142
161
/**
143
162
 * Dumps a copy of the array. Must be cast.
144
 
 * 
 
163
 *
145
164
 * Is not freed when the dynamic array is freed.
146
 
 * 
 
165
 *
147
166
 * Is null-terminated.
148
167
 */
149
168
spointer *
182
201
s_dynamic_array_serialize_json (SDynamicArray * self);
183
202
 
184
203
/**
185
 
 * appends itmes to an the array 
 
204
 * appends itmes to an the array
186
205
 *
187
206
 * If the from_json function is not set, this will couse undefined behaviour.
188
207
 */