~ubuntu-branches/debian/squeeze/glib2.0/squeeze

« back to all changes in this revision

Viewing changes to gobject/gvaluearray.c

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-02-15 13:00:43 UTC
  • mfrom: (1.3.1 upstream) (69.1.10 intrepid)
  • Revision ID: james.westby@ubuntu.com-20090215130043-q47fbt3owmt42m2f
Tags: 2.18.4-2
* Release to unstable
* debian/rules:
- bump SHVER, since we are already forcing a 2.18.0 dependecy on the
  symbols introduced in the development versions
* debian/control.in:
- added Homepage and Vcs-* control fields

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * MT safe
22
22
 */
23
23
 
24
 
#include <config.h>
25
 
 
26
 
#include        "gvaluearray.h"
27
 
#include        "gobjectalias.h"
28
 
#include        <string.h>
29
 
#include        <stdlib.h>      /* qsort() */
 
24
#include "config.h"
 
25
 
 
26
#include <string.h>
 
27
#include <stdlib.h>  /* qsort() */
 
28
 
 
29
#include "gvaluearray.h"
 
30
#include "gobjectalias.h"
 
31
 
 
32
 
 
33
/**
 
34
 * SECTION:value_arrays
 
35
 * @short_description: A container structure to maintain an array of
 
36
 *     generic values
 
37
 * @see_also: #GValue, #GParamSpecValueArray, g_param_spec_value_array()
 
38
 * @title: Value arrays
 
39
 *
 
40
 * The prime purpose of a #GValueArray is for it to be used as an
 
41
 * object property that holds an array of values. A #GValueArray wraps
 
42
 * an array of #GValue elements in order for it to be used as a boxed
 
43
 * type through %G_TYPE_VALUE_ARRAY.
 
44
 */
 
45
 
30
46
 
31
47
#ifdef  DISABLE_MEM_POOLS
32
48
#  define       GROUP_N_VALUES  (1)     /* power of 2 !! */
36
52
 
37
53
 
38
54
/* --- functions --- */
 
55
/**
 
56
 * g_value_array_get_nth:
 
57
 * @value_array: #GValueArray to get a value from
 
58
 * @index_: index of the value of interest
 
59
 *
 
60
 * Return a pointer to the value at @index_ containd in @value_array.
 
61
 *
 
62
 * Returns: pointer to a value at @index_ in @value_array
 
63
 */
39
64
GValue*
40
65
g_value_array_get_nth (GValueArray *value_array,
41
66
                       guint        index)
79
104
#endif
80
105
}
81
106
 
 
107
/**
 
108
 * g_value_array_new:
 
109
 * @n_prealloced: number of values to preallocate space for
 
110
 *
 
111
 * Allocate and initialize a new #GValueArray, optionally preserve space
 
112
 * for @n_prealloced elements. New arrays always contain 0 elements,
 
113
 * regardless of the value of @n_prealloced.
 
114
 *
 
115
 * Returns: a newly allocated #GValueArray with 0 values
 
116
 */
82
117
GValueArray*
83
118
g_value_array_new (guint n_prealloced)
84
119
{
93
128
  return value_array;
94
129
}
95
130
 
 
131
/**
 
132
 * g_value_array_free:
 
133
 * @value_array: #GValueArray to free
 
134
 *
 
135
 * Free a #GValueArray including its contents.
 
136
 */
96
137
void
97
138
g_value_array_free (GValueArray *value_array)
98
139
{
111
152
  g_slice_free (GValueArray, value_array);
112
153
}
113
154
 
 
155
/**
 
156
 * g_value_array_copy:
 
157
 * @value_array: #GValueArray to copy
 
158
 *
 
159
 * Construct an exact copy of a #GValueArray by duplicating all its
 
160
 * contents.
 
161
 *
 
162
 * Returns: Newly allocated copy of #GValueArray
 
163
 */
114
164
GValueArray*
115
165
g_value_array_copy (const GValueArray *value_array)
116
166
{
135
185
  return new_array;
136
186
}
137
187
 
 
188
/**
 
189
 * g_value_array_prepend:
 
190
 * @value_array: #GValueArray to add an element to
 
191
 * @value: #GValue to copy into #GValueArray
 
192
 *
 
193
 * Insert a copy of @value as first element of @value_array.
 
194
 *
 
195
 * Returns: the #GValueArray passed in as @value_array
 
196
 */
138
197
GValueArray*
139
198
g_value_array_prepend (GValueArray  *value_array,
140
199
                       const GValue *value)
144
203
  return g_value_array_insert (value_array, 0, value);
145
204
}
146
205
 
 
206
/**
 
207
 * g_value_array_append:
 
208
 * @value_array: #GValueArray to add an element to
 
209
 * @value: #GValue to copy into #GValueArray
 
210
 *
 
211
 * Insert a copy of @value as last element of @value_array.
 
212
 *
 
213
 * Returns: the #GValueArray passed in as @value_array
 
214
 */
147
215
GValueArray*
148
216
g_value_array_append (GValueArray  *value_array,
149
217
                      const GValue *value)
153
221
  return g_value_array_insert (value_array, value_array->n_values, value);
154
222
}
155
223
 
 
224
/**
 
225
 * g_value_array_insert:
 
226
 * @value_array: #GValueArray to add an element to
 
227
 * @index_: insertion position, must be &lt;= value_array-&gt;n_values
 
228
 * @value: #GValue to copy into #GValueArray
 
229
 *
 
230
 * Insert a copy of @value at specified position into @value_array.
 
231
 *
 
232
 * Returns: the #GValueArray passed in as @value_array
 
233
 */
156
234
GValueArray*
157
235
g_value_array_insert (GValueArray  *value_array,
158
236
                      guint         index,
179
257
  return value_array;
180
258
}
181
259
 
 
260
/**
 
261
 * g_value_array_remove:
 
262
 * @value_array: #GValueArray to remove an element from
 
263
 * @index_: position of value to remove, must be &lt; value_array->n_values
 
264
 *
 
265
 * Remove the value at position @index_ from @value_array.
 
266
 *
 
267
 * Returns: the #GValueArray passed in as @value_array
 
268
 */
182
269
GValueArray*
183
270
g_value_array_remove (GValueArray *value_array,
184
271
                      guint        index)
199
286
  return value_array;
200
287
}
201
288
 
 
289
/**
 
290
 * g_value_array_sort:
 
291
 * @value_array: #GValueArray to sort
 
292
 * @compare_func: function to compare elements
 
293
 *
 
294
 * Sort @value_array using @compare_func to compare the elements accoring to
 
295
 * the semantics of #GCompareFunc.
 
296
 *
 
297
 * The current implementation uses Quick-Sort as sorting algorithm.
 
298
 *
 
299
 * Returns: the #GValueArray passed in as @value_array
 
300
 */
202
301
GValueArray*
203
302
g_value_array_sort (GValueArray *value_array,
204
303
                    GCompareFunc compare_func)
213
312
  return value_array;
214
313
}
215
314
 
 
315
/**
 
316
 * g_value_array_sort_with_data:
 
317
 * @value_array: #GValueArray to sort
 
318
 * @compare_func: function to compare elements
 
319
 * @user_data: extra data argument provided for @compare_func
 
320
 *
 
321
 * Sort @value_array using @compare_func to compare the elements accoring
 
322
 * to the semantics of #GCompareDataFunc.
 
323
 *
 
324
 * The current implementation uses Quick-Sort as sorting algorithm.
 
325
 *
 
326
 * Returns: the #GValueArray passed in as @value_array
 
327
 */
216
328
GValueArray*
217
329
g_value_array_sort_with_data (GValueArray     *value_array,
218
330
                              GCompareDataFunc compare_func,