/src/glib/gobject/gparamspecs.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* GObject - GLib Type, Object, Parameter and Signal Library |
2 | | * Copyright (C) 1997-1999, 2000-2001 Tim Janik and Red Hat, Inc. |
3 | | * Copyright (C) 2010 Christian Persch |
4 | | * |
5 | | * This library is free software; you can redistribute it and/or |
6 | | * modify it under the terms of the GNU Lesser General Public |
7 | | * License as published by the Free Software Foundation; either |
8 | | * version 2.1 of the License, or (at your option) any later version. |
9 | | * |
10 | | * This library is distributed in the hope that it will be useful, |
11 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | | * Lesser General Public License for more details. |
14 | | * |
15 | | * You should have received a copy of the GNU Lesser General |
16 | | * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
17 | | */ |
18 | | |
19 | | /* |
20 | | * MT safe |
21 | | */ |
22 | | |
23 | | #include "config.h" |
24 | | |
25 | | #include <string.h> |
26 | | |
27 | | #ifndef GLIB_DISABLE_DEPRECATION_WARNINGS |
28 | | #define GLIB_DISABLE_DEPRECATION_WARNINGS |
29 | | #endif |
30 | | |
31 | | #include "gparamspecs.h" |
32 | | #include "gtype-private.h" |
33 | | #include "gvaluecollector.h" |
34 | | |
35 | | #include "gvaluearray.h" |
36 | | |
37 | | |
38 | | /** |
39 | | * SECTION:param_value_types |
40 | | * @short_description: Standard Parameter and Value Types |
41 | | * @see_also: #GParamSpec, #GValue, g_object_class_install_property(). |
42 | | * @title: Parameters and Values |
43 | | * |
44 | | * #GValue provides an abstract container structure which can be |
45 | | * copied, transformed and compared while holding a value of any |
46 | | * (derived) type, which is registered as a #GType with a |
47 | | * #GTypeValueTable in its #GTypeInfo structure. Parameter |
48 | | * specifications for most value types can be created as #GParamSpec |
49 | | * derived instances, to implement e.g. #GObject properties which |
50 | | * operate on #GValue containers. |
51 | | * |
52 | | * Parameter names need to start with a letter (a-z or A-Z). Subsequent |
53 | | * characters can be letters, numbers or a '-'. |
54 | | * All other characters are replaced by a '-' during construction. |
55 | | */ |
56 | | |
57 | | |
58 | 0 | #define G_FLOAT_EPSILON (1e-30) |
59 | 0 | #define G_DOUBLE_EPSILON (1e-90) |
60 | | |
61 | | |
62 | | /* --- param spec functions --- */ |
63 | | static void |
64 | | param_char_init (GParamSpec *pspec) |
65 | 0 | { |
66 | 0 | GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec); |
67 | | |
68 | 0 | cspec->minimum = 0x7f; |
69 | 0 | cspec->maximum = 0x80; |
70 | 0 | cspec->default_value = 0; |
71 | 0 | } |
72 | | |
73 | | static void |
74 | | param_char_set_default (GParamSpec *pspec, |
75 | | GValue *value) |
76 | 0 | { |
77 | 0 | value->data[0].v_int = G_PARAM_SPEC_CHAR (pspec)->default_value; |
78 | 0 | } |
79 | | |
80 | | static gboolean |
81 | | param_char_validate (GParamSpec *pspec, |
82 | | GValue *value) |
83 | 0 | { |
84 | 0 | GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec); |
85 | 0 | gint oval = value->data[0].v_int; |
86 | | |
87 | 0 | value->data[0].v_int = CLAMP (value->data[0].v_int, cspec->minimum, cspec->maximum); |
88 | | |
89 | 0 | return value->data[0].v_int != oval; |
90 | 0 | } |
91 | | |
92 | | static void |
93 | | param_uchar_init (GParamSpec *pspec) |
94 | 0 | { |
95 | 0 | GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec); |
96 | | |
97 | 0 | uspec->minimum = 0; |
98 | 0 | uspec->maximum = 0xff; |
99 | 0 | uspec->default_value = 0; |
100 | 0 | } |
101 | | |
102 | | static void |
103 | | param_uchar_set_default (GParamSpec *pspec, |
104 | | GValue *value) |
105 | 0 | { |
106 | 0 | value->data[0].v_uint = G_PARAM_SPEC_UCHAR (pspec)->default_value; |
107 | 0 | } |
108 | | |
109 | | static gboolean |
110 | | param_uchar_validate (GParamSpec *pspec, |
111 | | GValue *value) |
112 | 0 | { |
113 | 0 | GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec); |
114 | 0 | guint oval = value->data[0].v_uint; |
115 | | |
116 | 0 | value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum); |
117 | | |
118 | 0 | return value->data[0].v_uint != oval; |
119 | 0 | } |
120 | | |
121 | | static void |
122 | | param_boolean_set_default (GParamSpec *pspec, |
123 | | GValue *value) |
124 | 0 | { |
125 | 0 | value->data[0].v_int = G_PARAM_SPEC_BOOLEAN (pspec)->default_value; |
126 | 0 | } |
127 | | |
128 | | static gboolean |
129 | | param_boolean_validate (GParamSpec *pspec, |
130 | | GValue *value) |
131 | 0 | { |
132 | 0 | gint oval = value->data[0].v_int; |
133 | | |
134 | 0 | value->data[0].v_int = value->data[0].v_int != FALSE; |
135 | | |
136 | 0 | return value->data[0].v_int != oval; |
137 | 0 | } |
138 | | |
139 | | static void |
140 | | param_int_init (GParamSpec *pspec) |
141 | 0 | { |
142 | 0 | GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec); |
143 | | |
144 | 0 | ispec->minimum = 0x7fffffff; |
145 | 0 | ispec->maximum = 0x80000000; |
146 | 0 | ispec->default_value = 0; |
147 | 0 | } |
148 | | |
149 | | static void |
150 | | param_int_set_default (GParamSpec *pspec, |
151 | | GValue *value) |
152 | 0 | { |
153 | 0 | value->data[0].v_int = G_PARAM_SPEC_INT (pspec)->default_value; |
154 | 0 | } |
155 | | |
156 | | static gboolean |
157 | | param_int_validate (GParamSpec *pspec, |
158 | | GValue *value) |
159 | 0 | { |
160 | 0 | GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec); |
161 | 0 | gint oval = value->data[0].v_int; |
162 | | |
163 | 0 | value->data[0].v_int = CLAMP (value->data[0].v_int, ispec->minimum, ispec->maximum); |
164 | | |
165 | 0 | return value->data[0].v_int != oval; |
166 | 0 | } |
167 | | |
168 | | static gint |
169 | | param_int_values_cmp (GParamSpec *pspec, |
170 | | const GValue *value1, |
171 | | const GValue *value2) |
172 | 0 | { |
173 | 0 | if (value1->data[0].v_int < value2->data[0].v_int) |
174 | 0 | return -1; |
175 | 0 | else |
176 | 0 | return value1->data[0].v_int > value2->data[0].v_int; |
177 | 0 | } |
178 | | |
179 | | static void |
180 | | param_uint_init (GParamSpec *pspec) |
181 | 0 | { |
182 | 0 | GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec); |
183 | | |
184 | 0 | uspec->minimum = 0; |
185 | 0 | uspec->maximum = 0xffffffff; |
186 | 0 | uspec->default_value = 0; |
187 | 0 | } |
188 | | |
189 | | static void |
190 | | param_uint_set_default (GParamSpec *pspec, |
191 | | GValue *value) |
192 | 0 | { |
193 | 0 | value->data[0].v_uint = G_PARAM_SPEC_UINT (pspec)->default_value; |
194 | 0 | } |
195 | | |
196 | | static gboolean |
197 | | param_uint_validate (GParamSpec *pspec, |
198 | | GValue *value) |
199 | 0 | { |
200 | 0 | GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec); |
201 | 0 | guint oval = value->data[0].v_uint; |
202 | | |
203 | 0 | value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum); |
204 | | |
205 | 0 | return value->data[0].v_uint != oval; |
206 | 0 | } |
207 | | |
208 | | static gint |
209 | | param_uint_values_cmp (GParamSpec *pspec, |
210 | | const GValue *value1, |
211 | | const GValue *value2) |
212 | 0 | { |
213 | 0 | if (value1->data[0].v_uint < value2->data[0].v_uint) |
214 | 0 | return -1; |
215 | 0 | else |
216 | 0 | return value1->data[0].v_uint > value2->data[0].v_uint; |
217 | 0 | } |
218 | | |
219 | | static void |
220 | | param_long_init (GParamSpec *pspec) |
221 | 0 | { |
222 | 0 | GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec); |
223 | | |
224 | | #if SIZEOF_LONG == 4 |
225 | | lspec->minimum = 0x7fffffff; |
226 | | lspec->maximum = 0x80000000; |
227 | | #else /* SIZEOF_LONG != 4 (8) */ |
228 | 0 | lspec->minimum = 0x7fffffffffffffff; |
229 | 0 | lspec->maximum = 0x8000000000000000; |
230 | 0 | #endif |
231 | 0 | lspec->default_value = 0; |
232 | 0 | } |
233 | | |
234 | | static void |
235 | | param_long_set_default (GParamSpec *pspec, |
236 | | GValue *value) |
237 | 0 | { |
238 | 0 | value->data[0].v_long = G_PARAM_SPEC_LONG (pspec)->default_value; |
239 | 0 | } |
240 | | |
241 | | static gboolean |
242 | | param_long_validate (GParamSpec *pspec, |
243 | | GValue *value) |
244 | 0 | { |
245 | 0 | GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec); |
246 | 0 | glong oval = value->data[0].v_long; |
247 | | |
248 | 0 | value->data[0].v_long = CLAMP (value->data[0].v_long, lspec->minimum, lspec->maximum); |
249 | | |
250 | 0 | return value->data[0].v_long != oval; |
251 | 0 | } |
252 | | |
253 | | static gint |
254 | | param_long_values_cmp (GParamSpec *pspec, |
255 | | const GValue *value1, |
256 | | const GValue *value2) |
257 | 0 | { |
258 | 0 | if (value1->data[0].v_long < value2->data[0].v_long) |
259 | 0 | return -1; |
260 | 0 | else |
261 | 0 | return value1->data[0].v_long > value2->data[0].v_long; |
262 | 0 | } |
263 | | |
264 | | static void |
265 | | param_ulong_init (GParamSpec *pspec) |
266 | 0 | { |
267 | 0 | GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec); |
268 | | |
269 | 0 | uspec->minimum = 0; |
270 | | #if SIZEOF_LONG == 4 |
271 | | uspec->maximum = 0xffffffff; |
272 | | #else /* SIZEOF_LONG != 4 (8) */ |
273 | 0 | uspec->maximum = 0xffffffffffffffff; |
274 | 0 | #endif |
275 | 0 | uspec->default_value = 0; |
276 | 0 | } |
277 | | |
278 | | static void |
279 | | param_ulong_set_default (GParamSpec *pspec, |
280 | | GValue *value) |
281 | 0 | { |
282 | 0 | value->data[0].v_ulong = G_PARAM_SPEC_ULONG (pspec)->default_value; |
283 | 0 | } |
284 | | |
285 | | static gboolean |
286 | | param_ulong_validate (GParamSpec *pspec, |
287 | | GValue *value) |
288 | 0 | { |
289 | 0 | GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec); |
290 | 0 | gulong oval = value->data[0].v_ulong; |
291 | | |
292 | 0 | value->data[0].v_ulong = CLAMP (value->data[0].v_ulong, uspec->minimum, uspec->maximum); |
293 | | |
294 | 0 | return value->data[0].v_ulong != oval; |
295 | 0 | } |
296 | | |
297 | | static gint |
298 | | param_ulong_values_cmp (GParamSpec *pspec, |
299 | | const GValue *value1, |
300 | | const GValue *value2) |
301 | 0 | { |
302 | 0 | if (value1->data[0].v_ulong < value2->data[0].v_ulong) |
303 | 0 | return -1; |
304 | 0 | else |
305 | 0 | return value1->data[0].v_ulong > value2->data[0].v_ulong; |
306 | 0 | } |
307 | | |
308 | | static void |
309 | | param_int64_init (GParamSpec *pspec) |
310 | 0 | { |
311 | 0 | GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec); |
312 | | |
313 | 0 | lspec->minimum = G_MININT64; |
314 | 0 | lspec->maximum = G_MAXINT64; |
315 | 0 | lspec->default_value = 0; |
316 | 0 | } |
317 | | |
318 | | static void |
319 | | param_int64_set_default (GParamSpec *pspec, |
320 | | GValue *value) |
321 | 0 | { |
322 | 0 | value->data[0].v_int64 = G_PARAM_SPEC_INT64 (pspec)->default_value; |
323 | 0 | } |
324 | | |
325 | | static gboolean |
326 | | param_int64_validate (GParamSpec *pspec, |
327 | | GValue *value) |
328 | 0 | { |
329 | 0 | GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec); |
330 | 0 | gint64 oval = value->data[0].v_int64; |
331 | | |
332 | 0 | value->data[0].v_int64 = CLAMP (value->data[0].v_int64, lspec->minimum, lspec->maximum); |
333 | | |
334 | 0 | return value->data[0].v_int64 != oval; |
335 | 0 | } |
336 | | |
337 | | static gint |
338 | | param_int64_values_cmp (GParamSpec *pspec, |
339 | | const GValue *value1, |
340 | | const GValue *value2) |
341 | 0 | { |
342 | 0 | if (value1->data[0].v_int64 < value2->data[0].v_int64) |
343 | 0 | return -1; |
344 | 0 | else |
345 | 0 | return value1->data[0].v_int64 > value2->data[0].v_int64; |
346 | 0 | } |
347 | | |
348 | | static void |
349 | | param_uint64_init (GParamSpec *pspec) |
350 | 0 | { |
351 | 0 | GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec); |
352 | | |
353 | 0 | uspec->minimum = 0; |
354 | 0 | uspec->maximum = G_MAXUINT64; |
355 | 0 | uspec->default_value = 0; |
356 | 0 | } |
357 | | |
358 | | static void |
359 | | param_uint64_set_default (GParamSpec *pspec, |
360 | | GValue *value) |
361 | 0 | { |
362 | 0 | value->data[0].v_uint64 = G_PARAM_SPEC_UINT64 (pspec)->default_value; |
363 | 0 | } |
364 | | |
365 | | static gboolean |
366 | | param_uint64_validate (GParamSpec *pspec, |
367 | | GValue *value) |
368 | 0 | { |
369 | 0 | GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec); |
370 | 0 | guint64 oval = value->data[0].v_uint64; |
371 | | |
372 | 0 | value->data[0].v_uint64 = CLAMP (value->data[0].v_uint64, uspec->minimum, uspec->maximum); |
373 | | |
374 | 0 | return value->data[0].v_uint64 != oval; |
375 | 0 | } |
376 | | |
377 | | static gint |
378 | | param_uint64_values_cmp (GParamSpec *pspec, |
379 | | const GValue *value1, |
380 | | const GValue *value2) |
381 | 0 | { |
382 | 0 | if (value1->data[0].v_uint64 < value2->data[0].v_uint64) |
383 | 0 | return -1; |
384 | 0 | else |
385 | 0 | return value1->data[0].v_uint64 > value2->data[0].v_uint64; |
386 | 0 | } |
387 | | |
388 | | static void |
389 | | param_unichar_init (GParamSpec *pspec) |
390 | 0 | { |
391 | 0 | GParamSpecUnichar *uspec = G_PARAM_SPEC_UNICHAR (pspec); |
392 | | |
393 | 0 | uspec->default_value = 0; |
394 | 0 | } |
395 | | |
396 | | static void |
397 | | param_unichar_set_default (GParamSpec *pspec, |
398 | | GValue *value) |
399 | 0 | { |
400 | 0 | value->data[0].v_uint = G_PARAM_SPEC_UNICHAR (pspec)->default_value; |
401 | 0 | } |
402 | | |
403 | | static gboolean |
404 | | param_unichar_validate (GParamSpec *pspec, |
405 | | GValue *value) |
406 | 0 | { |
407 | 0 | gunichar oval = value->data[0].v_uint; |
408 | 0 | gboolean changed = FALSE; |
409 | |
|
410 | 0 | if (!g_unichar_validate (oval)) |
411 | 0 | { |
412 | 0 | value->data[0].v_uint = 0; |
413 | 0 | changed = TRUE; |
414 | 0 | } |
415 | |
|
416 | 0 | return changed; |
417 | 0 | } |
418 | | |
419 | | static gint |
420 | | param_unichar_values_cmp (GParamSpec *pspec, |
421 | | const GValue *value1, |
422 | | const GValue *value2) |
423 | 0 | { |
424 | 0 | if (value1->data[0].v_uint < value2->data[0].v_uint) |
425 | 0 | return -1; |
426 | 0 | else |
427 | 0 | return value1->data[0].v_uint > value2->data[0].v_uint; |
428 | 0 | } |
429 | | |
430 | | static void |
431 | | param_enum_init (GParamSpec *pspec) |
432 | 0 | { |
433 | 0 | GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec); |
434 | | |
435 | 0 | espec->enum_class = NULL; |
436 | 0 | espec->default_value = 0; |
437 | 0 | } |
438 | | |
439 | | static void |
440 | | param_enum_finalize (GParamSpec *pspec) |
441 | 0 | { |
442 | 0 | GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec); |
443 | 0 | GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_ENUM)); |
444 | | |
445 | 0 | if (espec->enum_class) |
446 | 0 | { |
447 | 0 | g_type_class_unref (espec->enum_class); |
448 | 0 | espec->enum_class = NULL; |
449 | 0 | } |
450 | | |
451 | 0 | parent_class->finalize (pspec); |
452 | 0 | } |
453 | | |
454 | | static void |
455 | | param_enum_set_default (GParamSpec *pspec, |
456 | | GValue *value) |
457 | 0 | { |
458 | 0 | value->data[0].v_long = G_PARAM_SPEC_ENUM (pspec)->default_value; |
459 | 0 | } |
460 | | |
461 | | static gboolean |
462 | | param_enum_validate (GParamSpec *pspec, |
463 | | GValue *value) |
464 | 0 | { |
465 | 0 | GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec); |
466 | 0 | glong oval = value->data[0].v_long; |
467 | | |
468 | 0 | if (!espec->enum_class || |
469 | 0 | !g_enum_get_value (espec->enum_class, value->data[0].v_long)) |
470 | 0 | value->data[0].v_long = espec->default_value; |
471 | | |
472 | 0 | return value->data[0].v_long != oval; |
473 | 0 | } |
474 | | |
475 | | static void |
476 | | param_flags_init (GParamSpec *pspec) |
477 | 0 | { |
478 | 0 | GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec); |
479 | | |
480 | 0 | fspec->flags_class = NULL; |
481 | 0 | fspec->default_value = 0; |
482 | 0 | } |
483 | | |
484 | | static void |
485 | | param_flags_finalize (GParamSpec *pspec) |
486 | 0 | { |
487 | 0 | GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec); |
488 | 0 | GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_FLAGS)); |
489 | | |
490 | 0 | if (fspec->flags_class) |
491 | 0 | { |
492 | 0 | g_type_class_unref (fspec->flags_class); |
493 | 0 | fspec->flags_class = NULL; |
494 | 0 | } |
495 | | |
496 | 0 | parent_class->finalize (pspec); |
497 | 0 | } |
498 | | |
499 | | static void |
500 | | param_flags_set_default (GParamSpec *pspec, |
501 | | GValue *value) |
502 | 0 | { |
503 | 0 | value->data[0].v_ulong = G_PARAM_SPEC_FLAGS (pspec)->default_value; |
504 | 0 | } |
505 | | |
506 | | static gboolean |
507 | | param_flags_validate (GParamSpec *pspec, |
508 | | GValue *value) |
509 | 0 | { |
510 | 0 | GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec); |
511 | 0 | gulong oval = value->data[0].v_ulong; |
512 | | |
513 | 0 | if (fspec->flags_class) |
514 | 0 | value->data[0].v_ulong &= fspec->flags_class->mask; |
515 | 0 | else |
516 | 0 | value->data[0].v_ulong = fspec->default_value; |
517 | | |
518 | 0 | return value->data[0].v_ulong != oval; |
519 | 0 | } |
520 | | |
521 | | static void |
522 | | param_float_init (GParamSpec *pspec) |
523 | 0 | { |
524 | 0 | GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec); |
525 | | |
526 | 0 | fspec->minimum = -G_MAXFLOAT; |
527 | 0 | fspec->maximum = G_MAXFLOAT; |
528 | 0 | fspec->default_value = 0; |
529 | 0 | fspec->epsilon = G_FLOAT_EPSILON; |
530 | 0 | } |
531 | | |
532 | | static void |
533 | | param_float_set_default (GParamSpec *pspec, |
534 | | GValue *value) |
535 | 0 | { |
536 | 0 | value->data[0].v_float = G_PARAM_SPEC_FLOAT (pspec)->default_value; |
537 | 0 | } |
538 | | |
539 | | static gboolean |
540 | | param_float_validate (GParamSpec *pspec, |
541 | | GValue *value) |
542 | 0 | { |
543 | 0 | GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec); |
544 | 0 | gfloat oval = value->data[0].v_float; |
545 | | |
546 | 0 | value->data[0].v_float = CLAMP (value->data[0].v_float, fspec->minimum, fspec->maximum); |
547 | | |
548 | 0 | return value->data[0].v_float != oval; |
549 | 0 | } |
550 | | |
551 | | static gint |
552 | | param_float_values_cmp (GParamSpec *pspec, |
553 | | const GValue *value1, |
554 | | const GValue *value2) |
555 | 0 | { |
556 | 0 | gfloat epsilon = G_PARAM_SPEC_FLOAT (pspec)->epsilon; |
557 | | |
558 | 0 | if (value1->data[0].v_float < value2->data[0].v_float) |
559 | 0 | return - (value2->data[0].v_float - value1->data[0].v_float > epsilon); |
560 | 0 | else |
561 | 0 | return value1->data[0].v_float - value2->data[0].v_float > epsilon; |
562 | 0 | } |
563 | | |
564 | | static void |
565 | | param_double_init (GParamSpec *pspec) |
566 | 0 | { |
567 | 0 | GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec); |
568 | | |
569 | 0 | dspec->minimum = -G_MAXDOUBLE; |
570 | 0 | dspec->maximum = G_MAXDOUBLE; |
571 | 0 | dspec->default_value = 0; |
572 | 0 | dspec->epsilon = G_DOUBLE_EPSILON; |
573 | 0 | } |
574 | | |
575 | | static void |
576 | | param_double_set_default (GParamSpec *pspec, |
577 | | GValue *value) |
578 | 0 | { |
579 | 0 | value->data[0].v_double = G_PARAM_SPEC_DOUBLE (pspec)->default_value; |
580 | 0 | } |
581 | | |
582 | | static gboolean |
583 | | param_double_validate (GParamSpec *pspec, |
584 | | GValue *value) |
585 | 0 | { |
586 | 0 | GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec); |
587 | 0 | gdouble oval = value->data[0].v_double; |
588 | | |
589 | 0 | value->data[0].v_double = CLAMP (value->data[0].v_double, dspec->minimum, dspec->maximum); |
590 | | |
591 | 0 | return value->data[0].v_double != oval; |
592 | 0 | } |
593 | | |
594 | | static gint |
595 | | param_double_values_cmp (GParamSpec *pspec, |
596 | | const GValue *value1, |
597 | | const GValue *value2) |
598 | 0 | { |
599 | 0 | gdouble epsilon = G_PARAM_SPEC_DOUBLE (pspec)->epsilon; |
600 | | |
601 | 0 | if (value1->data[0].v_double < value2->data[0].v_double) |
602 | 0 | return - (value2->data[0].v_double - value1->data[0].v_double > epsilon); |
603 | 0 | else |
604 | 0 | return value1->data[0].v_double - value2->data[0].v_double > epsilon; |
605 | 0 | } |
606 | | |
607 | | static void |
608 | | param_string_init (GParamSpec *pspec) |
609 | 0 | { |
610 | 0 | GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec); |
611 | | |
612 | 0 | sspec->default_value = NULL; |
613 | 0 | sspec->cset_first = NULL; |
614 | 0 | sspec->cset_nth = NULL; |
615 | 0 | sspec->substitutor = '_'; |
616 | 0 | sspec->null_fold_if_empty = FALSE; |
617 | 0 | sspec->ensure_non_null = FALSE; |
618 | 0 | } |
619 | | |
620 | | static void |
621 | | param_string_finalize (GParamSpec *pspec) |
622 | 0 | { |
623 | 0 | GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec); |
624 | 0 | GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING)); |
625 | | |
626 | 0 | g_free (sspec->default_value); |
627 | 0 | g_free (sspec->cset_first); |
628 | 0 | g_free (sspec->cset_nth); |
629 | 0 | sspec->default_value = NULL; |
630 | 0 | sspec->cset_first = NULL; |
631 | 0 | sspec->cset_nth = NULL; |
632 | | |
633 | 0 | parent_class->finalize (pspec); |
634 | 0 | } |
635 | | |
636 | | static void |
637 | | param_string_set_default (GParamSpec *pspec, |
638 | | GValue *value) |
639 | 0 | { |
640 | 0 | value->data[0].v_pointer = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value); |
641 | 0 | } |
642 | | |
643 | | static gboolean |
644 | | param_string_validate (GParamSpec *pspec, |
645 | | GValue *value) |
646 | 0 | { |
647 | 0 | GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec); |
648 | 0 | gchar *string = value->data[0].v_pointer; |
649 | 0 | guint changed = 0; |
650 | | |
651 | 0 | if (string && string[0]) |
652 | 0 | { |
653 | 0 | gchar *s; |
654 | | |
655 | 0 | if (sspec->cset_first && !strchr (sspec->cset_first, string[0])) |
656 | 0 | { |
657 | 0 | if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) |
658 | 0 | { |
659 | 0 | value->data[0].v_pointer = g_strdup (string); |
660 | 0 | string = value->data[0].v_pointer; |
661 | 0 | value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; |
662 | 0 | } |
663 | 0 | string[0] = sspec->substitutor; |
664 | 0 | changed++; |
665 | 0 | } |
666 | 0 | if (sspec->cset_nth) |
667 | 0 | for (s = string + 1; *s; s++) |
668 | 0 | if (!strchr (sspec->cset_nth, *s)) |
669 | 0 | { |
670 | 0 | if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) |
671 | 0 | { |
672 | 0 | value->data[0].v_pointer = g_strdup (string); |
673 | 0 | s = (gchar*) value->data[0].v_pointer + (s - string); |
674 | 0 | string = value->data[0].v_pointer; |
675 | 0 | value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; |
676 | 0 | } |
677 | 0 | *s = sspec->substitutor; |
678 | 0 | changed++; |
679 | 0 | } |
680 | 0 | } |
681 | 0 | if (sspec->null_fold_if_empty && string && string[0] == 0) |
682 | 0 | { |
683 | 0 | if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)) |
684 | 0 | g_free (value->data[0].v_pointer); |
685 | 0 | else |
686 | 0 | value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; |
687 | 0 | value->data[0].v_pointer = NULL; |
688 | 0 | changed++; |
689 | 0 | string = value->data[0].v_pointer; |
690 | 0 | } |
691 | 0 | if (sspec->ensure_non_null && !string) |
692 | 0 | { |
693 | 0 | value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; |
694 | 0 | value->data[0].v_pointer = g_strdup (""); |
695 | 0 | changed++; |
696 | 0 | string = value->data[0].v_pointer; |
697 | 0 | } |
698 | |
|
699 | 0 | return changed; |
700 | 0 | } |
701 | | |
702 | | static gint |
703 | | param_string_values_cmp (GParamSpec *pspec, |
704 | | const GValue *value1, |
705 | | const GValue *value2) |
706 | 0 | { |
707 | 0 | if (!value1->data[0].v_pointer) |
708 | 0 | return value2->data[0].v_pointer != NULL ? -1 : 0; |
709 | 0 | else if (!value2->data[0].v_pointer) |
710 | 0 | return value1->data[0].v_pointer != NULL; |
711 | 0 | else |
712 | 0 | return strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer); |
713 | 0 | } |
714 | | |
715 | | static void |
716 | | param_param_init (GParamSpec *pspec) |
717 | 0 | { |
718 | | /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */ |
719 | 0 | } |
720 | | |
721 | | static void |
722 | | param_param_set_default (GParamSpec *pspec, |
723 | | GValue *value) |
724 | 0 | { |
725 | 0 | value->data[0].v_pointer = NULL; |
726 | 0 | } |
727 | | |
728 | | static gboolean |
729 | | param_param_validate (GParamSpec *pspec, |
730 | | GValue *value) |
731 | 0 | { |
732 | | /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */ |
733 | 0 | GParamSpec *param = value->data[0].v_pointer; |
734 | 0 | guint changed = 0; |
735 | | |
736 | 0 | if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec))) |
737 | 0 | { |
738 | 0 | g_param_spec_unref (param); |
739 | 0 | value->data[0].v_pointer = NULL; |
740 | 0 | changed++; |
741 | 0 | } |
742 | | |
743 | 0 | return changed; |
744 | 0 | } |
745 | | |
746 | | static void |
747 | | param_boxed_init (GParamSpec *pspec) |
748 | 0 | { |
749 | | /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */ |
750 | 0 | } |
751 | | |
752 | | static void |
753 | | param_boxed_set_default (GParamSpec *pspec, |
754 | | GValue *value) |
755 | 0 | { |
756 | 0 | value->data[0].v_pointer = NULL; |
757 | 0 | } |
758 | | |
759 | | static gboolean |
760 | | param_boxed_validate (GParamSpec *pspec, |
761 | | GValue *value) |
762 | 0 | { |
763 | | /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */ |
764 | 0 | guint changed = 0; |
765 | | |
766 | | /* can't do a whole lot here since we haven't even G_BOXED_TYPE() */ |
767 | | |
768 | 0 | return changed; |
769 | 0 | } |
770 | | |
771 | | static gint |
772 | | param_boxed_values_cmp (GParamSpec *pspec, |
773 | | const GValue *value1, |
774 | | const GValue *value2) |
775 | 0 | { |
776 | 0 | guint8 *p1 = value1->data[0].v_pointer; |
777 | 0 | guint8 *p2 = value2->data[0].v_pointer; |
778 | | |
779 | | /* not much to compare here, try to at least provide stable lesser/greater result */ |
780 | |
|
781 | 0 | return p1 < p2 ? -1 : p1 > p2; |
782 | 0 | } |
783 | | |
784 | | static void |
785 | | param_pointer_init (GParamSpec *pspec) |
786 | 0 | { |
787 | | /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */ |
788 | 0 | } |
789 | | |
790 | | static void |
791 | | param_pointer_set_default (GParamSpec *pspec, |
792 | | GValue *value) |
793 | 0 | { |
794 | 0 | value->data[0].v_pointer = NULL; |
795 | 0 | } |
796 | | |
797 | | static gboolean |
798 | | param_pointer_validate (GParamSpec *pspec, |
799 | | GValue *value) |
800 | 0 | { |
801 | | /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */ |
802 | 0 | guint changed = 0; |
803 | | |
804 | 0 | return changed; |
805 | 0 | } |
806 | | |
807 | | static gint |
808 | | param_pointer_values_cmp (GParamSpec *pspec, |
809 | | const GValue *value1, |
810 | | const GValue *value2) |
811 | 0 | { |
812 | 0 | guint8 *p1 = value1->data[0].v_pointer; |
813 | 0 | guint8 *p2 = value2->data[0].v_pointer; |
814 | | |
815 | | /* not much to compare here, try to at least provide stable lesser/greater result */ |
816 | |
|
817 | 0 | return p1 < p2 ? -1 : p1 > p2; |
818 | 0 | } |
819 | | |
820 | | static void |
821 | | param_value_array_init (GParamSpec *pspec) |
822 | 0 | { |
823 | 0 | GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); |
824 | |
|
825 | 0 | aspec->element_spec = NULL; |
826 | 0 | aspec->fixed_n_elements = 0; /* disable */ |
827 | 0 | } |
828 | | |
829 | | static inline guint |
830 | | value_array_ensure_size (GValueArray *value_array, |
831 | | guint fixed_n_elements) |
832 | 0 | { |
833 | 0 | guint changed = 0; |
834 | |
|
835 | 0 | if (fixed_n_elements) |
836 | 0 | { |
837 | 0 | while (value_array->n_values < fixed_n_elements) |
838 | 0 | { |
839 | 0 | g_value_array_append (value_array, NULL); |
840 | 0 | changed++; |
841 | 0 | } |
842 | 0 | while (value_array->n_values > fixed_n_elements) |
843 | 0 | { |
844 | 0 | g_value_array_remove (value_array, value_array->n_values - 1); |
845 | 0 | changed++; |
846 | 0 | } |
847 | 0 | } |
848 | 0 | return changed; |
849 | 0 | } |
850 | | |
851 | | static void |
852 | | param_value_array_finalize (GParamSpec *pspec) |
853 | 0 | { |
854 | 0 | GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); |
855 | 0 | GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VALUE_ARRAY)); |
856 | |
|
857 | 0 | if (aspec->element_spec) |
858 | 0 | { |
859 | 0 | g_param_spec_unref (aspec->element_spec); |
860 | 0 | aspec->element_spec = NULL; |
861 | 0 | } |
862 | |
|
863 | 0 | parent_class->finalize (pspec); |
864 | 0 | } |
865 | | |
866 | | static void |
867 | | param_value_array_set_default (GParamSpec *pspec, |
868 | | GValue *value) |
869 | 0 | { |
870 | 0 | GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); |
871 | |
|
872 | 0 | if (!value->data[0].v_pointer && aspec->fixed_n_elements) |
873 | 0 | value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements); |
874 | |
|
875 | 0 | if (value->data[0].v_pointer) |
876 | 0 | { |
877 | | /* g_value_reset (value); already done */ |
878 | 0 | value_array_ensure_size (value->data[0].v_pointer, aspec->fixed_n_elements); |
879 | 0 | } |
880 | 0 | } |
881 | | |
882 | | static gboolean |
883 | | param_value_array_validate (GParamSpec *pspec, |
884 | | GValue *value) |
885 | 0 | { |
886 | 0 | GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); |
887 | 0 | GValueArray *value_array = value->data[0].v_pointer; |
888 | 0 | guint changed = 0; |
889 | |
|
890 | 0 | if (!value->data[0].v_pointer && aspec->fixed_n_elements) |
891 | 0 | value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements); |
892 | |
|
893 | 0 | if (value->data[0].v_pointer) |
894 | 0 | { |
895 | | /* ensure array size validity */ |
896 | 0 | changed += value_array_ensure_size (value_array, aspec->fixed_n_elements); |
897 | | |
898 | | /* ensure array values validity against a present element spec */ |
899 | 0 | if (aspec->element_spec) |
900 | 0 | { |
901 | 0 | GParamSpec *element_spec = aspec->element_spec; |
902 | 0 | guint i; |
903 | | |
904 | 0 | for (i = 0; i < value_array->n_values; i++) |
905 | 0 | { |
906 | 0 | GValue *element = value_array->values + i; |
907 | | |
908 | | /* need to fixup value type, or ensure that the array value is initialized at all */ |
909 | 0 | if (!g_value_type_compatible (G_VALUE_TYPE (element), G_PARAM_SPEC_VALUE_TYPE (element_spec))) |
910 | 0 | { |
911 | 0 | if (G_VALUE_TYPE (element) != 0) |
912 | 0 | g_value_unset (element); |
913 | 0 | g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec)); |
914 | 0 | g_param_value_set_default (element_spec, element); |
915 | 0 | changed++; |
916 | 0 | } |
917 | 0 | else |
918 | 0 | { |
919 | | /* validate array value against element_spec */ |
920 | 0 | changed += g_param_value_validate (element_spec, element); |
921 | 0 | } |
922 | 0 | } |
923 | 0 | } |
924 | 0 | } |
925 | |
|
926 | 0 | return changed; |
927 | 0 | } |
928 | | |
929 | | static gint |
930 | | param_value_array_values_cmp (GParamSpec *pspec, |
931 | | const GValue *value1, |
932 | | const GValue *value2) |
933 | 0 | { |
934 | 0 | GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); |
935 | 0 | GValueArray *value_array1 = value1->data[0].v_pointer; |
936 | 0 | GValueArray *value_array2 = value2->data[0].v_pointer; |
937 | |
|
938 | 0 | if (!value_array1 || !value_array2) |
939 | 0 | return value_array2 ? -1 : value_array1 != value_array2; |
940 | | |
941 | 0 | if (value_array1->n_values != value_array2->n_values) |
942 | 0 | return value_array1->n_values < value_array2->n_values ? -1 : 1; |
943 | 0 | else if (!aspec->element_spec) |
944 | 0 | { |
945 | | /* we need an element specification for comparisons, so there's not much |
946 | | * to compare here, try to at least provide stable lesser/greater result |
947 | | */ |
948 | 0 | return value_array1->n_values < value_array2->n_values ? -1 : value_array1->n_values > value_array2->n_values; |
949 | 0 | } |
950 | 0 | else /* value_array1->n_values == value_array2->n_values */ |
951 | 0 | { |
952 | 0 | guint i; |
953 | |
|
954 | 0 | for (i = 0; i < value_array1->n_values; i++) |
955 | 0 | { |
956 | 0 | GValue *element1 = value_array1->values + i; |
957 | 0 | GValue *element2 = value_array2->values + i; |
958 | 0 | gint cmp; |
959 | | |
960 | | /* need corresponding element types, provide stable result otherwise */ |
961 | 0 | if (G_VALUE_TYPE (element1) != G_VALUE_TYPE (element2)) |
962 | 0 | return G_VALUE_TYPE (element1) < G_VALUE_TYPE (element2) ? -1 : 1; |
963 | 0 | cmp = g_param_values_cmp (aspec->element_spec, element1, element2); |
964 | 0 | if (cmp) |
965 | 0 | return cmp; |
966 | 0 | } |
967 | 0 | return 0; |
968 | 0 | } |
969 | 0 | } |
970 | | |
971 | | static void |
972 | | param_object_init (GParamSpec *pspec) |
973 | 36 | { |
974 | | /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */ |
975 | 36 | } |
976 | | |
977 | | static void |
978 | | param_object_set_default (GParamSpec *pspec, |
979 | | GValue *value) |
980 | 36 | { |
981 | 36 | value->data[0].v_pointer = NULL; |
982 | 36 | } |
983 | | |
984 | | static gboolean |
985 | | param_object_validate (GParamSpec *pspec, |
986 | | GValue *value) |
987 | 9.88M | { |
988 | 9.88M | GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); |
989 | 9.88M | GObject *object = value->data[0].v_pointer; |
990 | 9.88M | guint changed = 0; |
991 | | |
992 | 9.88M | if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec))) |
993 | 0 | { |
994 | 0 | g_object_unref (object); |
995 | 0 | value->data[0].v_pointer = NULL; |
996 | 0 | changed++; |
997 | 0 | } |
998 | | |
999 | 9.88M | return changed; |
1000 | 9.88M | } |
1001 | | |
1002 | | static gint |
1003 | | param_object_values_cmp (GParamSpec *pspec, |
1004 | | const GValue *value1, |
1005 | | const GValue *value2) |
1006 | 0 | { |
1007 | 0 | guint8 *p1 = value1->data[0].v_pointer; |
1008 | 0 | guint8 *p2 = value2->data[0].v_pointer; |
1009 | | |
1010 | | /* not much to compare here, try to at least provide stable lesser/greater result */ |
1011 | |
|
1012 | 0 | return p1 < p2 ? -1 : p1 > p2; |
1013 | 0 | } |
1014 | | |
1015 | | static void |
1016 | | param_override_init (GParamSpec *pspec) |
1017 | 0 | { |
1018 | | /* GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); */ |
1019 | 0 | } |
1020 | | |
1021 | | static void |
1022 | | param_override_finalize (GParamSpec *pspec) |
1023 | 0 | { |
1024 | 0 | GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); |
1025 | 0 | GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_OVERRIDE)); |
1026 | | |
1027 | 0 | if (ospec->overridden) |
1028 | 0 | { |
1029 | 0 | g_param_spec_unref (ospec->overridden); |
1030 | 0 | ospec->overridden = NULL; |
1031 | 0 | } |
1032 | | |
1033 | 0 | parent_class->finalize (pspec); |
1034 | 0 | } |
1035 | | |
1036 | | static void |
1037 | | param_override_set_default (GParamSpec *pspec, |
1038 | | GValue *value) |
1039 | 0 | { |
1040 | 0 | GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); |
1041 | |
|
1042 | 0 | g_param_value_set_default (ospec->overridden, value); |
1043 | 0 | } |
1044 | | |
1045 | | static gboolean |
1046 | | param_override_validate (GParamSpec *pspec, |
1047 | | GValue *value) |
1048 | 0 | { |
1049 | 0 | GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); |
1050 | | |
1051 | 0 | return g_param_value_validate (ospec->overridden, value); |
1052 | 0 | } |
1053 | | |
1054 | | static gint |
1055 | | param_override_values_cmp (GParamSpec *pspec, |
1056 | | const GValue *value1, |
1057 | | const GValue *value2) |
1058 | 0 | { |
1059 | 0 | GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); |
1060 | |
|
1061 | 0 | return g_param_values_cmp (ospec->overridden, value1, value2); |
1062 | 0 | } |
1063 | | |
1064 | | static void |
1065 | | param_gtype_init (GParamSpec *pspec) |
1066 | 0 | { |
1067 | 0 | } |
1068 | | |
1069 | | static void |
1070 | | param_gtype_set_default (GParamSpec *pspec, |
1071 | | GValue *value) |
1072 | 0 | { |
1073 | 0 | GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec); |
1074 | |
|
1075 | 0 | value->data[0].v_pointer = GSIZE_TO_POINTER (tspec->is_a_type); |
1076 | 0 | } |
1077 | | |
1078 | | static gboolean |
1079 | | param_gtype_validate (GParamSpec *pspec, |
1080 | | GValue *value) |
1081 | 0 | { |
1082 | 0 | GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec); |
1083 | 0 | GType gtype = GPOINTER_TO_SIZE (value->data[0].v_pointer); |
1084 | 0 | guint changed = 0; |
1085 | | |
1086 | 0 | if (tspec->is_a_type != G_TYPE_NONE && !g_type_is_a (gtype, tspec->is_a_type)) |
1087 | 0 | { |
1088 | 0 | value->data[0].v_pointer = GSIZE_TO_POINTER (tspec->is_a_type); |
1089 | 0 | changed++; |
1090 | 0 | } |
1091 | | |
1092 | 0 | return changed; |
1093 | 0 | } |
1094 | | |
1095 | | static gint |
1096 | | param_gtype_values_cmp (GParamSpec *pspec, |
1097 | | const GValue *value1, |
1098 | | const GValue *value2) |
1099 | 0 | { |
1100 | 0 | GType p1 = GPOINTER_TO_SIZE (value1->data[0].v_pointer); |
1101 | 0 | GType p2 = GPOINTER_TO_SIZE (value2->data[0].v_pointer); |
1102 | | |
1103 | | /* not much to compare here, try to at least provide stable lesser/greater result */ |
1104 | |
|
1105 | 0 | return p1 < p2 ? -1 : p1 > p2; |
1106 | 0 | } |
1107 | | |
1108 | | static void |
1109 | | param_variant_init (GParamSpec *pspec) |
1110 | 0 | { |
1111 | 0 | GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec); |
1112 | |
|
1113 | 0 | vspec->type = NULL; |
1114 | 0 | vspec->default_value = NULL; |
1115 | 0 | } |
1116 | | |
1117 | | static void |
1118 | | param_variant_finalize (GParamSpec *pspec) |
1119 | 0 | { |
1120 | 0 | GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec); |
1121 | 0 | GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VARIANT)); |
1122 | |
|
1123 | 0 | if (vspec->default_value) |
1124 | 0 | g_variant_unref (vspec->default_value); |
1125 | 0 | g_variant_type_free (vspec->type); |
1126 | |
|
1127 | 0 | parent_class->finalize (pspec); |
1128 | 0 | } |
1129 | | |
1130 | | static void |
1131 | | param_variant_set_default (GParamSpec *pspec, |
1132 | | GValue *value) |
1133 | 0 | { |
1134 | 0 | value->data[0].v_pointer = G_PARAM_SPEC_VARIANT (pspec)->default_value; |
1135 | 0 | value->data[1].v_uint |= G_VALUE_NOCOPY_CONTENTS; |
1136 | 0 | } |
1137 | | |
1138 | | static gboolean |
1139 | | param_variant_validate (GParamSpec *pspec, |
1140 | | GValue *value) |
1141 | 0 | { |
1142 | 0 | GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec); |
1143 | 0 | GVariant *variant = value->data[0].v_pointer; |
1144 | |
|
1145 | 0 | if ((variant == NULL && vspec->default_value != NULL) || |
1146 | 0 | (variant != NULL && !g_variant_is_of_type (variant, vspec->type))) |
1147 | 0 | { |
1148 | 0 | g_param_value_set_default (pspec, value); |
1149 | 0 | return TRUE; |
1150 | 0 | } |
1151 | | |
1152 | 0 | return FALSE; |
1153 | 0 | } |
1154 | | |
1155 | | /* g_variant_compare() can only be used with scalar types. */ |
1156 | | static gboolean |
1157 | | variant_is_incomparable (GVariant *v) |
1158 | 0 | { |
1159 | 0 | GVariantClass v_class = g_variant_classify (v); |
1160 | |
|
1161 | 0 | return (v_class == G_VARIANT_CLASS_HANDLE || |
1162 | 0 | v_class == G_VARIANT_CLASS_VARIANT || |
1163 | 0 | v_class == G_VARIANT_CLASS_MAYBE|| |
1164 | 0 | v_class == G_VARIANT_CLASS_ARRAY || |
1165 | 0 | v_class == G_VARIANT_CLASS_TUPLE || |
1166 | 0 | v_class == G_VARIANT_CLASS_DICT_ENTRY); |
1167 | 0 | } |
1168 | | |
1169 | | static gint |
1170 | | param_variant_values_cmp (GParamSpec *pspec, |
1171 | | const GValue *value1, |
1172 | | const GValue *value2) |
1173 | 0 | { |
1174 | 0 | GVariant *v1 = value1->data[0].v_pointer; |
1175 | 0 | GVariant *v2 = value2->data[0].v_pointer; |
1176 | |
|
1177 | 0 | if (v1 == NULL && v2 == NULL) |
1178 | 0 | return 0; |
1179 | 0 | else if (v1 == NULL && v2 != NULL) |
1180 | 0 | return -1; |
1181 | 0 | else if (v1 != NULL && v2 == NULL) |
1182 | 0 | return 1; |
1183 | | |
1184 | 0 | if (!g_variant_type_equal (g_variant_get_type (v1), g_variant_get_type (v2)) || |
1185 | 0 | variant_is_incomparable (v1) || |
1186 | 0 | variant_is_incomparable (v2)) |
1187 | 0 | return g_variant_equal (v1, v2) ? 0 : (v1 < v2 ? -1 : 1); |
1188 | | |
1189 | 0 | return g_variant_compare (v1, v2); |
1190 | 0 | } |
1191 | | |
1192 | | /* --- type initialization --- */ |
1193 | | GType *g_param_spec_types = NULL; |
1194 | | |
1195 | | void |
1196 | | _g_param_spec_types_init (void) |
1197 | 75 | { |
1198 | 75 | const guint n_types = 23; |
1199 | 75 | GType type, *spec_types; |
1200 | 75 | #ifndef G_DISABLE_ASSERT |
1201 | 75 | GType *spec_types_bound; |
1202 | 75 | #endif |
1203 | | |
1204 | 75 | g_param_spec_types = g_new0 (GType, n_types); |
1205 | 75 | spec_types = g_param_spec_types; |
1206 | 75 | #ifndef G_DISABLE_ASSERT |
1207 | 75 | spec_types_bound = g_param_spec_types + n_types; |
1208 | 75 | #endif |
1209 | | |
1210 | | /* G_TYPE_PARAM_CHAR |
1211 | | */ |
1212 | 75 | { |
1213 | 75 | const GParamSpecTypeInfo pspec_info = { |
1214 | 75 | sizeof (GParamSpecChar), /* instance_size */ |
1215 | 75 | 16, /* n_preallocs */ |
1216 | 75 | param_char_init, /* instance_init */ |
1217 | 75 | G_TYPE_CHAR, /* value_type */ |
1218 | 75 | NULL, /* finalize */ |
1219 | 75 | param_char_set_default, /* value_set_default */ |
1220 | 75 | param_char_validate, /* value_validate */ |
1221 | 75 | param_int_values_cmp, /* values_cmp */ |
1222 | 75 | }; |
1223 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamChar"), &pspec_info); |
1224 | 75 | *spec_types++ = type; |
1225 | 75 | g_assert (type == G_TYPE_PARAM_CHAR); |
1226 | 75 | } |
1227 | | |
1228 | | /* G_TYPE_PARAM_UCHAR |
1229 | | */ |
1230 | 75 | { |
1231 | 75 | const GParamSpecTypeInfo pspec_info = { |
1232 | 75 | sizeof (GParamSpecUChar), /* instance_size */ |
1233 | 75 | 16, /* n_preallocs */ |
1234 | 75 | param_uchar_init, /* instance_init */ |
1235 | 75 | G_TYPE_UCHAR, /* value_type */ |
1236 | 75 | NULL, /* finalize */ |
1237 | 75 | param_uchar_set_default, /* value_set_default */ |
1238 | 75 | param_uchar_validate, /* value_validate */ |
1239 | 75 | param_uint_values_cmp, /* values_cmp */ |
1240 | 75 | }; |
1241 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamUChar"), &pspec_info); |
1242 | 75 | *spec_types++ = type; |
1243 | 75 | g_assert (type == G_TYPE_PARAM_UCHAR); |
1244 | 75 | } |
1245 | | |
1246 | | /* G_TYPE_PARAM_BOOLEAN |
1247 | | */ |
1248 | 75 | { |
1249 | 75 | const GParamSpecTypeInfo pspec_info = { |
1250 | 75 | sizeof (GParamSpecBoolean), /* instance_size */ |
1251 | 75 | 16, /* n_preallocs */ |
1252 | 75 | NULL, /* instance_init */ |
1253 | 75 | G_TYPE_BOOLEAN, /* value_type */ |
1254 | 75 | NULL, /* finalize */ |
1255 | 75 | param_boolean_set_default, /* value_set_default */ |
1256 | 75 | param_boolean_validate, /* value_validate */ |
1257 | 75 | param_int_values_cmp, /* values_cmp */ |
1258 | 75 | }; |
1259 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamBoolean"), &pspec_info); |
1260 | 75 | *spec_types++ = type; |
1261 | 75 | g_assert (type == G_TYPE_PARAM_BOOLEAN); |
1262 | 75 | } |
1263 | | |
1264 | | /* G_TYPE_PARAM_INT |
1265 | | */ |
1266 | 75 | { |
1267 | 75 | const GParamSpecTypeInfo pspec_info = { |
1268 | 75 | sizeof (GParamSpecInt), /* instance_size */ |
1269 | 75 | 16, /* n_preallocs */ |
1270 | 75 | param_int_init, /* instance_init */ |
1271 | 75 | G_TYPE_INT, /* value_type */ |
1272 | 75 | NULL, /* finalize */ |
1273 | 75 | param_int_set_default, /* value_set_default */ |
1274 | 75 | param_int_validate, /* value_validate */ |
1275 | 75 | param_int_values_cmp, /* values_cmp */ |
1276 | 75 | }; |
1277 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamInt"), &pspec_info); |
1278 | 75 | *spec_types++ = type; |
1279 | 75 | g_assert (type == G_TYPE_PARAM_INT); |
1280 | 75 | } |
1281 | | |
1282 | | /* G_TYPE_PARAM_UINT |
1283 | | */ |
1284 | 75 | { |
1285 | 75 | const GParamSpecTypeInfo pspec_info = { |
1286 | 75 | sizeof (GParamSpecUInt), /* instance_size */ |
1287 | 75 | 16, /* n_preallocs */ |
1288 | 75 | param_uint_init, /* instance_init */ |
1289 | 75 | G_TYPE_UINT, /* value_type */ |
1290 | 75 | NULL, /* finalize */ |
1291 | 75 | param_uint_set_default, /* value_set_default */ |
1292 | 75 | param_uint_validate, /* value_validate */ |
1293 | 75 | param_uint_values_cmp, /* values_cmp */ |
1294 | 75 | }; |
1295 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamUInt"), &pspec_info); |
1296 | 75 | *spec_types++ = type; |
1297 | 75 | g_assert (type == G_TYPE_PARAM_UINT); |
1298 | 75 | } |
1299 | | |
1300 | | /* G_TYPE_PARAM_LONG |
1301 | | */ |
1302 | 75 | { |
1303 | 75 | const GParamSpecTypeInfo pspec_info = { |
1304 | 75 | sizeof (GParamSpecLong), /* instance_size */ |
1305 | 75 | 16, /* n_preallocs */ |
1306 | 75 | param_long_init, /* instance_init */ |
1307 | 75 | G_TYPE_LONG, /* value_type */ |
1308 | 75 | NULL, /* finalize */ |
1309 | 75 | param_long_set_default, /* value_set_default */ |
1310 | 75 | param_long_validate, /* value_validate */ |
1311 | 75 | param_long_values_cmp, /* values_cmp */ |
1312 | 75 | }; |
1313 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamLong"), &pspec_info); |
1314 | 75 | *spec_types++ = type; |
1315 | 75 | g_assert (type == G_TYPE_PARAM_LONG); |
1316 | 75 | } |
1317 | | |
1318 | | /* G_TYPE_PARAM_ULONG |
1319 | | */ |
1320 | 75 | { |
1321 | 75 | const GParamSpecTypeInfo pspec_info = { |
1322 | 75 | sizeof (GParamSpecULong), /* instance_size */ |
1323 | 75 | 16, /* n_preallocs */ |
1324 | 75 | param_ulong_init, /* instance_init */ |
1325 | 75 | G_TYPE_ULONG, /* value_type */ |
1326 | 75 | NULL, /* finalize */ |
1327 | 75 | param_ulong_set_default, /* value_set_default */ |
1328 | 75 | param_ulong_validate, /* value_validate */ |
1329 | 75 | param_ulong_values_cmp, /* values_cmp */ |
1330 | 75 | }; |
1331 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamULong"), &pspec_info); |
1332 | 75 | *spec_types++ = type; |
1333 | 75 | g_assert (type == G_TYPE_PARAM_ULONG); |
1334 | 75 | } |
1335 | | |
1336 | | /* G_TYPE_PARAM_INT64 |
1337 | | */ |
1338 | 75 | { |
1339 | 75 | const GParamSpecTypeInfo pspec_info = { |
1340 | 75 | sizeof (GParamSpecInt64), /* instance_size */ |
1341 | 75 | 16, /* n_preallocs */ |
1342 | 75 | param_int64_init, /* instance_init */ |
1343 | 75 | G_TYPE_INT64, /* value_type */ |
1344 | 75 | NULL, /* finalize */ |
1345 | 75 | param_int64_set_default, /* value_set_default */ |
1346 | 75 | param_int64_validate, /* value_validate */ |
1347 | 75 | param_int64_values_cmp, /* values_cmp */ |
1348 | 75 | }; |
1349 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamInt64"), &pspec_info); |
1350 | 75 | *spec_types++ = type; |
1351 | 75 | g_assert (type == G_TYPE_PARAM_INT64); |
1352 | 75 | } |
1353 | | |
1354 | | /* G_TYPE_PARAM_UINT64 |
1355 | | */ |
1356 | 75 | { |
1357 | 75 | const GParamSpecTypeInfo pspec_info = { |
1358 | 75 | sizeof (GParamSpecUInt64), /* instance_size */ |
1359 | 75 | 16, /* n_preallocs */ |
1360 | 75 | param_uint64_init, /* instance_init */ |
1361 | 75 | G_TYPE_UINT64, /* value_type */ |
1362 | 75 | NULL, /* finalize */ |
1363 | 75 | param_uint64_set_default, /* value_set_default */ |
1364 | 75 | param_uint64_validate, /* value_validate */ |
1365 | 75 | param_uint64_values_cmp, /* values_cmp */ |
1366 | 75 | }; |
1367 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamUInt64"), &pspec_info); |
1368 | 75 | *spec_types++ = type; |
1369 | 75 | g_assert (type == G_TYPE_PARAM_UINT64); |
1370 | 75 | } |
1371 | | |
1372 | | /* G_TYPE_PARAM_UNICHAR |
1373 | | */ |
1374 | 75 | { |
1375 | 75 | const GParamSpecTypeInfo pspec_info = { |
1376 | 75 | sizeof (GParamSpecUnichar), /* instance_size */ |
1377 | 75 | 16, /* n_preallocs */ |
1378 | 75 | param_unichar_init, /* instance_init */ |
1379 | 75 | G_TYPE_UINT, /* value_type */ |
1380 | 75 | NULL, /* finalize */ |
1381 | 75 | param_unichar_set_default, /* value_set_default */ |
1382 | 75 | param_unichar_validate, /* value_validate */ |
1383 | 75 | param_unichar_values_cmp, /* values_cmp */ |
1384 | 75 | }; |
1385 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamUnichar"), &pspec_info); |
1386 | 75 | *spec_types++ = type; |
1387 | 75 | g_assert (type == G_TYPE_PARAM_UNICHAR); |
1388 | 75 | } |
1389 | | |
1390 | | /* G_TYPE_PARAM_ENUM |
1391 | | */ |
1392 | 75 | { |
1393 | 75 | const GParamSpecTypeInfo pspec_info = { |
1394 | 75 | sizeof (GParamSpecEnum), /* instance_size */ |
1395 | 75 | 16, /* n_preallocs */ |
1396 | 75 | param_enum_init, /* instance_init */ |
1397 | 75 | G_TYPE_ENUM, /* value_type */ |
1398 | 75 | param_enum_finalize, /* finalize */ |
1399 | 75 | param_enum_set_default, /* value_set_default */ |
1400 | 75 | param_enum_validate, /* value_validate */ |
1401 | 75 | param_long_values_cmp, /* values_cmp */ |
1402 | 75 | }; |
1403 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamEnum"), &pspec_info); |
1404 | 75 | *spec_types++ = type; |
1405 | 75 | g_assert (type == G_TYPE_PARAM_ENUM); |
1406 | 75 | } |
1407 | | |
1408 | | /* G_TYPE_PARAM_FLAGS |
1409 | | */ |
1410 | 75 | { |
1411 | 75 | const GParamSpecTypeInfo pspec_info = { |
1412 | 75 | sizeof (GParamSpecFlags), /* instance_size */ |
1413 | 75 | 16, /* n_preallocs */ |
1414 | 75 | param_flags_init, /* instance_init */ |
1415 | 75 | G_TYPE_FLAGS, /* value_type */ |
1416 | 75 | param_flags_finalize, /* finalize */ |
1417 | 75 | param_flags_set_default, /* value_set_default */ |
1418 | 75 | param_flags_validate, /* value_validate */ |
1419 | 75 | param_ulong_values_cmp, /* values_cmp */ |
1420 | 75 | }; |
1421 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamFlags"), &pspec_info); |
1422 | 75 | *spec_types++ = type; |
1423 | 75 | g_assert (type == G_TYPE_PARAM_FLAGS); |
1424 | 75 | } |
1425 | | |
1426 | | /* G_TYPE_PARAM_FLOAT |
1427 | | */ |
1428 | 75 | { |
1429 | 75 | const GParamSpecTypeInfo pspec_info = { |
1430 | 75 | sizeof (GParamSpecFloat), /* instance_size */ |
1431 | 75 | 16, /* n_preallocs */ |
1432 | 75 | param_float_init, /* instance_init */ |
1433 | 75 | G_TYPE_FLOAT, /* value_type */ |
1434 | 75 | NULL, /* finalize */ |
1435 | 75 | param_float_set_default, /* value_set_default */ |
1436 | 75 | param_float_validate, /* value_validate */ |
1437 | 75 | param_float_values_cmp, /* values_cmp */ |
1438 | 75 | }; |
1439 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamFloat"), &pspec_info); |
1440 | 75 | *spec_types++ = type; |
1441 | 75 | g_assert (type == G_TYPE_PARAM_FLOAT); |
1442 | 75 | } |
1443 | | |
1444 | | /* G_TYPE_PARAM_DOUBLE |
1445 | | */ |
1446 | 75 | { |
1447 | 75 | const GParamSpecTypeInfo pspec_info = { |
1448 | 75 | sizeof (GParamSpecDouble), /* instance_size */ |
1449 | 75 | 16, /* n_preallocs */ |
1450 | 75 | param_double_init, /* instance_init */ |
1451 | 75 | G_TYPE_DOUBLE, /* value_type */ |
1452 | 75 | NULL, /* finalize */ |
1453 | 75 | param_double_set_default, /* value_set_default */ |
1454 | 75 | param_double_validate, /* value_validate */ |
1455 | 75 | param_double_values_cmp, /* values_cmp */ |
1456 | 75 | }; |
1457 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamDouble"), &pspec_info); |
1458 | 75 | *spec_types++ = type; |
1459 | 75 | g_assert (type == G_TYPE_PARAM_DOUBLE); |
1460 | 75 | } |
1461 | | |
1462 | | /* G_TYPE_PARAM_STRING |
1463 | | */ |
1464 | 75 | { |
1465 | 75 | const GParamSpecTypeInfo pspec_info = { |
1466 | 75 | sizeof (GParamSpecString), /* instance_size */ |
1467 | 75 | 16, /* n_preallocs */ |
1468 | 75 | param_string_init, /* instance_init */ |
1469 | 75 | G_TYPE_STRING, /* value_type */ |
1470 | 75 | param_string_finalize, /* finalize */ |
1471 | 75 | param_string_set_default, /* value_set_default */ |
1472 | 75 | param_string_validate, /* value_validate */ |
1473 | 75 | param_string_values_cmp, /* values_cmp */ |
1474 | 75 | }; |
1475 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamString"), &pspec_info); |
1476 | 75 | *spec_types++ = type; |
1477 | 75 | g_assert (type == G_TYPE_PARAM_STRING); |
1478 | 75 | } |
1479 | | |
1480 | | /* G_TYPE_PARAM_PARAM |
1481 | | */ |
1482 | 75 | { |
1483 | 75 | const GParamSpecTypeInfo pspec_info = { |
1484 | 75 | sizeof (GParamSpecParam), /* instance_size */ |
1485 | 75 | 16, /* n_preallocs */ |
1486 | 75 | param_param_init, /* instance_init */ |
1487 | 75 | G_TYPE_PARAM, /* value_type */ |
1488 | 75 | NULL, /* finalize */ |
1489 | 75 | param_param_set_default, /* value_set_default */ |
1490 | 75 | param_param_validate, /* value_validate */ |
1491 | 75 | param_pointer_values_cmp, /* values_cmp */ |
1492 | 75 | }; |
1493 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamParam"), &pspec_info); |
1494 | 75 | *spec_types++ = type; |
1495 | 75 | g_assert (type == G_TYPE_PARAM_PARAM); |
1496 | 75 | } |
1497 | | |
1498 | | /* G_TYPE_PARAM_BOXED |
1499 | | */ |
1500 | 75 | { |
1501 | 75 | const GParamSpecTypeInfo pspec_info = { |
1502 | 75 | sizeof (GParamSpecBoxed), /* instance_size */ |
1503 | 75 | 4, /* n_preallocs */ |
1504 | 75 | param_boxed_init, /* instance_init */ |
1505 | 75 | G_TYPE_BOXED, /* value_type */ |
1506 | 75 | NULL, /* finalize */ |
1507 | 75 | param_boxed_set_default, /* value_set_default */ |
1508 | 75 | param_boxed_validate, /* value_validate */ |
1509 | 75 | param_boxed_values_cmp, /* values_cmp */ |
1510 | 75 | }; |
1511 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamBoxed"), &pspec_info); |
1512 | 75 | *spec_types++ = type; |
1513 | 75 | g_assert (type == G_TYPE_PARAM_BOXED); |
1514 | 75 | } |
1515 | | |
1516 | | /* G_TYPE_PARAM_POINTER |
1517 | | */ |
1518 | 75 | { |
1519 | 75 | const GParamSpecTypeInfo pspec_info = { |
1520 | 75 | sizeof (GParamSpecPointer), /* instance_size */ |
1521 | 75 | 0, /* n_preallocs */ |
1522 | 75 | param_pointer_init, /* instance_init */ |
1523 | 75 | G_TYPE_POINTER, /* value_type */ |
1524 | 75 | NULL, /* finalize */ |
1525 | 75 | param_pointer_set_default, /* value_set_default */ |
1526 | 75 | param_pointer_validate, /* value_validate */ |
1527 | 75 | param_pointer_values_cmp, /* values_cmp */ |
1528 | 75 | }; |
1529 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamPointer"), &pspec_info); |
1530 | 75 | *spec_types++ = type; |
1531 | 75 | g_assert (type == G_TYPE_PARAM_POINTER); |
1532 | 75 | } |
1533 | | |
1534 | | /* G_TYPE_PARAM_VALUE_ARRAY |
1535 | | */ |
1536 | 75 | { |
1537 | 75 | /* const */ GParamSpecTypeInfo pspec_info = { |
1538 | 75 | sizeof (GParamSpecValueArray), /* instance_size */ |
1539 | 75 | 0, /* n_preallocs */ |
1540 | 75 | param_value_array_init, /* instance_init */ |
1541 | 75 | 0xdeadbeef, /* value_type, assigned further down */ |
1542 | 75 | param_value_array_finalize, /* finalize */ |
1543 | 75 | param_value_array_set_default, /* value_set_default */ |
1544 | 75 | param_value_array_validate, /* value_validate */ |
1545 | 75 | param_value_array_values_cmp, /* values_cmp */ |
1546 | 75 | }; |
1547 | 75 | pspec_info.value_type = G_TYPE_VALUE_ARRAY; |
1548 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamValueArray"), &pspec_info); |
1549 | 75 | *spec_types++ = type; |
1550 | 75 | g_assert (type == G_TYPE_PARAM_VALUE_ARRAY); |
1551 | 75 | } |
1552 | | |
1553 | | /* G_TYPE_PARAM_OBJECT |
1554 | | */ |
1555 | 75 | { |
1556 | 75 | const GParamSpecTypeInfo pspec_info = { |
1557 | 75 | sizeof (GParamSpecObject), /* instance_size */ |
1558 | 75 | 16, /* n_preallocs */ |
1559 | 75 | param_object_init, /* instance_init */ |
1560 | 75 | G_TYPE_OBJECT, /* value_type */ |
1561 | 75 | NULL, /* finalize */ |
1562 | 75 | param_object_set_default, /* value_set_default */ |
1563 | 75 | param_object_validate, /* value_validate */ |
1564 | 75 | param_object_values_cmp, /* values_cmp */ |
1565 | 75 | }; |
1566 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamObject"), &pspec_info); |
1567 | 75 | *spec_types++ = type; |
1568 | 75 | g_assert (type == G_TYPE_PARAM_OBJECT); |
1569 | 75 | } |
1570 | | |
1571 | | /* G_TYPE_PARAM_OVERRIDE |
1572 | | */ |
1573 | 75 | { |
1574 | 75 | const GParamSpecTypeInfo pspec_info = { |
1575 | 75 | sizeof (GParamSpecOverride), /* instance_size */ |
1576 | 75 | 16, /* n_preallocs */ |
1577 | 75 | param_override_init, /* instance_init */ |
1578 | 75 | G_TYPE_NONE, /* value_type */ |
1579 | 75 | param_override_finalize, /* finalize */ |
1580 | 75 | param_override_set_default, /* value_set_default */ |
1581 | 75 | param_override_validate, /* value_validate */ |
1582 | 75 | param_override_values_cmp, /* values_cmp */ |
1583 | 75 | }; |
1584 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamOverride"), &pspec_info); |
1585 | 75 | *spec_types++ = type; |
1586 | 75 | g_assert (type == G_TYPE_PARAM_OVERRIDE); |
1587 | 75 | } |
1588 | | |
1589 | | /* G_TYPE_PARAM_GTYPE |
1590 | | */ |
1591 | 75 | { |
1592 | 75 | GParamSpecTypeInfo pspec_info = { |
1593 | 75 | sizeof (GParamSpecGType), /* instance_size */ |
1594 | 75 | 0, /* n_preallocs */ |
1595 | 75 | param_gtype_init, /* instance_init */ |
1596 | 75 | 0xdeadbeef, /* value_type, assigned further down */ |
1597 | 75 | NULL, /* finalize */ |
1598 | 75 | param_gtype_set_default, /* value_set_default */ |
1599 | 75 | param_gtype_validate, /* value_validate */ |
1600 | 75 | param_gtype_values_cmp, /* values_cmp */ |
1601 | 75 | }; |
1602 | 75 | pspec_info.value_type = G_TYPE_GTYPE; |
1603 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamGType"), &pspec_info); |
1604 | 75 | *spec_types++ = type; |
1605 | 75 | g_assert (type == G_TYPE_PARAM_GTYPE); |
1606 | 75 | } |
1607 | | |
1608 | | /* G_TYPE_PARAM_VARIANT |
1609 | | */ |
1610 | 75 | { |
1611 | 75 | const GParamSpecTypeInfo pspec_info = { |
1612 | 75 | sizeof (GParamSpecVariant), /* instance_size */ |
1613 | 75 | 0, /* n_preallocs */ |
1614 | 75 | param_variant_init, /* instance_init */ |
1615 | 75 | G_TYPE_VARIANT, /* value_type */ |
1616 | 75 | param_variant_finalize, /* finalize */ |
1617 | 75 | param_variant_set_default, /* value_set_default */ |
1618 | 75 | param_variant_validate, /* value_validate */ |
1619 | 75 | param_variant_values_cmp, /* values_cmp */ |
1620 | 75 | }; |
1621 | 75 | type = g_param_type_register_static (g_intern_static_string ("GParamVariant"), &pspec_info); |
1622 | 75 | *spec_types++ = type; |
1623 | 75 | g_assert (type == G_TYPE_PARAM_VARIANT); |
1624 | 75 | } |
1625 | | |
1626 | 75 | g_assert (spec_types == spec_types_bound); |
1627 | 75 | } |
1628 | | |
1629 | | /* --- GParamSpec initialization --- */ |
1630 | | |
1631 | | /** |
1632 | | * g_param_spec_char: |
1633 | | * @name: canonical name of the property specified |
1634 | | * @nick: nick name for the property specified |
1635 | | * @blurb: description of the property specified |
1636 | | * @minimum: minimum value for the property specified |
1637 | | * @maximum: maximum value for the property specified |
1638 | | * @default_value: default value for the property specified |
1639 | | * @flags: flags for the property specified |
1640 | | * |
1641 | | * Creates a new #GParamSpecChar instance specifying a %G_TYPE_CHAR property. |
1642 | | * |
1643 | | * Returns: (transfer full): a newly created parameter specification |
1644 | | */ |
1645 | | GParamSpec* |
1646 | | g_param_spec_char (const gchar *name, |
1647 | | const gchar *nick, |
1648 | | const gchar *blurb, |
1649 | | gint8 minimum, |
1650 | | gint8 maximum, |
1651 | | gint8 default_value, |
1652 | | GParamFlags flags) |
1653 | 0 | { |
1654 | 0 | GParamSpecChar *cspec; |
1655 | |
|
1656 | 0 | g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL); |
1657 | | |
1658 | 0 | cspec = g_param_spec_internal (G_TYPE_PARAM_CHAR, |
1659 | 0 | name, |
1660 | 0 | nick, |
1661 | 0 | blurb, |
1662 | 0 | flags); |
1663 | 0 | if (cspec == NULL) |
1664 | 0 | return NULL; |
1665 | | |
1666 | 0 | cspec->minimum = minimum; |
1667 | 0 | cspec->maximum = maximum; |
1668 | 0 | cspec->default_value = default_value; |
1669 | | |
1670 | 0 | return G_PARAM_SPEC (cspec); |
1671 | 0 | } |
1672 | | |
1673 | | /** |
1674 | | * g_param_spec_uchar: |
1675 | | * @name: canonical name of the property specified |
1676 | | * @nick: nick name for the property specified |
1677 | | * @blurb: description of the property specified |
1678 | | * @minimum: minimum value for the property specified |
1679 | | * @maximum: maximum value for the property specified |
1680 | | * @default_value: default value for the property specified |
1681 | | * @flags: flags for the property specified |
1682 | | * |
1683 | | * Creates a new #GParamSpecUChar instance specifying a %G_TYPE_UCHAR property. |
1684 | | * |
1685 | | * Returns: (transfer full): a newly created parameter specification |
1686 | | */ |
1687 | | GParamSpec* |
1688 | | g_param_spec_uchar (const gchar *name, |
1689 | | const gchar *nick, |
1690 | | const gchar *blurb, |
1691 | | guint8 minimum, |
1692 | | guint8 maximum, |
1693 | | guint8 default_value, |
1694 | | GParamFlags flags) |
1695 | 0 | { |
1696 | 0 | GParamSpecUChar *uspec; |
1697 | |
|
1698 | 0 | g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL); |
1699 | | |
1700 | 0 | uspec = g_param_spec_internal (G_TYPE_PARAM_UCHAR, |
1701 | 0 | name, |
1702 | 0 | nick, |
1703 | 0 | blurb, |
1704 | 0 | flags); |
1705 | 0 | if (uspec == NULL) |
1706 | 0 | return NULL; |
1707 | | |
1708 | 0 | uspec->minimum = minimum; |
1709 | 0 | uspec->maximum = maximum; |
1710 | 0 | uspec->default_value = default_value; |
1711 | | |
1712 | 0 | return G_PARAM_SPEC (uspec); |
1713 | 0 | } |
1714 | | |
1715 | | /** |
1716 | | * g_param_spec_boolean: |
1717 | | * @name: canonical name of the property specified |
1718 | | * @nick: nick name for the property specified |
1719 | | * @blurb: description of the property specified |
1720 | | * @default_value: default value for the property specified |
1721 | | * @flags: flags for the property specified |
1722 | | * |
1723 | | * Creates a new #GParamSpecBoolean instance specifying a %G_TYPE_BOOLEAN |
1724 | | * property. In many cases, it may be more appropriate to use an enum with |
1725 | | * g_param_spec_enum(), both to improve code clarity by using explicitly named |
1726 | | * values, and to allow for more values to be added in future without breaking |
1727 | | * API. |
1728 | | * |
1729 | | * See g_param_spec_internal() for details on property names. |
1730 | | * |
1731 | | * Returns: (transfer full): a newly created parameter specification |
1732 | | */ |
1733 | | GParamSpec* |
1734 | | g_param_spec_boolean (const gchar *name, |
1735 | | const gchar *nick, |
1736 | | const gchar *blurb, |
1737 | | gboolean default_value, |
1738 | | GParamFlags flags) |
1739 | 0 | { |
1740 | 0 | GParamSpecBoolean *bspec; |
1741 | |
|
1742 | 0 | g_return_val_if_fail (default_value == TRUE || default_value == FALSE, NULL); |
1743 | | |
1744 | 0 | bspec = g_param_spec_internal (G_TYPE_PARAM_BOOLEAN, |
1745 | 0 | name, |
1746 | 0 | nick, |
1747 | 0 | blurb, |
1748 | 0 | flags); |
1749 | 0 | if (bspec == NULL) |
1750 | 0 | return NULL; |
1751 | | |
1752 | 0 | bspec->default_value = default_value; |
1753 | | |
1754 | 0 | return G_PARAM_SPEC (bspec); |
1755 | 0 | } |
1756 | | |
1757 | | /** |
1758 | | * g_param_spec_int: |
1759 | | * @name: canonical name of the property specified |
1760 | | * @nick: nick name for the property specified |
1761 | | * @blurb: description of the property specified |
1762 | | * @minimum: minimum value for the property specified |
1763 | | * @maximum: maximum value for the property specified |
1764 | | * @default_value: default value for the property specified |
1765 | | * @flags: flags for the property specified |
1766 | | * |
1767 | | * Creates a new #GParamSpecInt instance specifying a %G_TYPE_INT property. |
1768 | | * |
1769 | | * See g_param_spec_internal() for details on property names. |
1770 | | * |
1771 | | * Returns: (transfer full): a newly created parameter specification |
1772 | | */ |
1773 | | GParamSpec* |
1774 | | g_param_spec_int (const gchar *name, |
1775 | | const gchar *nick, |
1776 | | const gchar *blurb, |
1777 | | gint minimum, |
1778 | | gint maximum, |
1779 | | gint default_value, |
1780 | | GParamFlags flags) |
1781 | 0 | { |
1782 | 0 | GParamSpecInt *ispec; |
1783 | |
|
1784 | 0 | g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL); |
1785 | | |
1786 | 0 | ispec = g_param_spec_internal (G_TYPE_PARAM_INT, |
1787 | 0 | name, |
1788 | 0 | nick, |
1789 | 0 | blurb, |
1790 | 0 | flags); |
1791 | 0 | if (ispec == NULL) |
1792 | 0 | return NULL; |
1793 | | |
1794 | 0 | ispec->minimum = minimum; |
1795 | 0 | ispec->maximum = maximum; |
1796 | 0 | ispec->default_value = default_value; |
1797 | | |
1798 | 0 | return G_PARAM_SPEC (ispec); |
1799 | 0 | } |
1800 | | |
1801 | | /** |
1802 | | * g_param_spec_uint: |
1803 | | * @name: canonical name of the property specified |
1804 | | * @nick: nick name for the property specified |
1805 | | * @blurb: description of the property specified |
1806 | | * @minimum: minimum value for the property specified |
1807 | | * @maximum: maximum value for the property specified |
1808 | | * @default_value: default value for the property specified |
1809 | | * @flags: flags for the property specified |
1810 | | * |
1811 | | * Creates a new #GParamSpecUInt instance specifying a %G_TYPE_UINT property. |
1812 | | * |
1813 | | * See g_param_spec_internal() for details on property names. |
1814 | | * |
1815 | | * Returns: (transfer full): a newly created parameter specification |
1816 | | */ |
1817 | | GParamSpec* |
1818 | | g_param_spec_uint (const gchar *name, |
1819 | | const gchar *nick, |
1820 | | const gchar *blurb, |
1821 | | guint minimum, |
1822 | | guint maximum, |
1823 | | guint default_value, |
1824 | | GParamFlags flags) |
1825 | 0 | { |
1826 | 0 | GParamSpecUInt *uspec; |
1827 | |
|
1828 | 0 | g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL); |
1829 | | |
1830 | 0 | uspec = g_param_spec_internal (G_TYPE_PARAM_UINT, |
1831 | 0 | name, |
1832 | 0 | nick, |
1833 | 0 | blurb, |
1834 | 0 | flags); |
1835 | 0 | if (uspec == NULL) |
1836 | 0 | return NULL; |
1837 | | |
1838 | 0 | uspec->minimum = minimum; |
1839 | 0 | uspec->maximum = maximum; |
1840 | 0 | uspec->default_value = default_value; |
1841 | | |
1842 | 0 | return G_PARAM_SPEC (uspec); |
1843 | 0 | } |
1844 | | |
1845 | | /** |
1846 | | * g_param_spec_long: |
1847 | | * @name: canonical name of the property specified |
1848 | | * @nick: nick name for the property specified |
1849 | | * @blurb: description of the property specified |
1850 | | * @minimum: minimum value for the property specified |
1851 | | * @maximum: maximum value for the property specified |
1852 | | * @default_value: default value for the property specified |
1853 | | * @flags: flags for the property specified |
1854 | | * |
1855 | | * Creates a new #GParamSpecLong instance specifying a %G_TYPE_LONG property. |
1856 | | * |
1857 | | * See g_param_spec_internal() for details on property names. |
1858 | | * |
1859 | | * Returns: (transfer full): a newly created parameter specification |
1860 | | */ |
1861 | | GParamSpec* |
1862 | | g_param_spec_long (const gchar *name, |
1863 | | const gchar *nick, |
1864 | | const gchar *blurb, |
1865 | | glong minimum, |
1866 | | glong maximum, |
1867 | | glong default_value, |
1868 | | GParamFlags flags) |
1869 | 0 | { |
1870 | 0 | GParamSpecLong *lspec; |
1871 | |
|
1872 | 0 | g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL); |
1873 | | |
1874 | 0 | lspec = g_param_spec_internal (G_TYPE_PARAM_LONG, |
1875 | 0 | name, |
1876 | 0 | nick, |
1877 | 0 | blurb, |
1878 | 0 | flags); |
1879 | 0 | if (lspec == NULL) |
1880 | 0 | return NULL; |
1881 | | |
1882 | 0 | lspec->minimum = minimum; |
1883 | 0 | lspec->maximum = maximum; |
1884 | 0 | lspec->default_value = default_value; |
1885 | | |
1886 | 0 | return G_PARAM_SPEC (lspec); |
1887 | 0 | } |
1888 | | |
1889 | | /** |
1890 | | * g_param_spec_ulong: |
1891 | | * @name: canonical name of the property specified |
1892 | | * @nick: nick name for the property specified |
1893 | | * @blurb: description of the property specified |
1894 | | * @minimum: minimum value for the property specified |
1895 | | * @maximum: maximum value for the property specified |
1896 | | * @default_value: default value for the property specified |
1897 | | * @flags: flags for the property specified |
1898 | | * |
1899 | | * Creates a new #GParamSpecULong instance specifying a %G_TYPE_ULONG |
1900 | | * property. |
1901 | | * |
1902 | | * See g_param_spec_internal() for details on property names. |
1903 | | * |
1904 | | * Returns: (transfer full): a newly created parameter specification |
1905 | | */ |
1906 | | GParamSpec* |
1907 | | g_param_spec_ulong (const gchar *name, |
1908 | | const gchar *nick, |
1909 | | const gchar *blurb, |
1910 | | gulong minimum, |
1911 | | gulong maximum, |
1912 | | gulong default_value, |
1913 | | GParamFlags flags) |
1914 | 0 | { |
1915 | 0 | GParamSpecULong *uspec; |
1916 | |
|
1917 | 0 | g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL); |
1918 | | |
1919 | 0 | uspec = g_param_spec_internal (G_TYPE_PARAM_ULONG, |
1920 | 0 | name, |
1921 | 0 | nick, |
1922 | 0 | blurb, |
1923 | 0 | flags); |
1924 | 0 | if (uspec == NULL) |
1925 | 0 | return NULL; |
1926 | | |
1927 | 0 | uspec->minimum = minimum; |
1928 | 0 | uspec->maximum = maximum; |
1929 | 0 | uspec->default_value = default_value; |
1930 | | |
1931 | 0 | return G_PARAM_SPEC (uspec); |
1932 | 0 | } |
1933 | | |
1934 | | /** |
1935 | | * g_param_spec_int64: |
1936 | | * @name: canonical name of the property specified |
1937 | | * @nick: nick name for the property specified |
1938 | | * @blurb: description of the property specified |
1939 | | * @minimum: minimum value for the property specified |
1940 | | * @maximum: maximum value for the property specified |
1941 | | * @default_value: default value for the property specified |
1942 | | * @flags: flags for the property specified |
1943 | | * |
1944 | | * Creates a new #GParamSpecInt64 instance specifying a %G_TYPE_INT64 property. |
1945 | | * |
1946 | | * See g_param_spec_internal() for details on property names. |
1947 | | * |
1948 | | * Returns: (transfer full): a newly created parameter specification |
1949 | | */ |
1950 | | GParamSpec* |
1951 | | g_param_spec_int64 (const gchar *name, |
1952 | | const gchar *nick, |
1953 | | const gchar *blurb, |
1954 | | gint64 minimum, |
1955 | | gint64 maximum, |
1956 | | gint64 default_value, |
1957 | | GParamFlags flags) |
1958 | 0 | { |
1959 | 0 | GParamSpecInt64 *lspec; |
1960 | | |
1961 | 0 | g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL); |
1962 | | |
1963 | 0 | lspec = g_param_spec_internal (G_TYPE_PARAM_INT64, |
1964 | 0 | name, |
1965 | 0 | nick, |
1966 | 0 | blurb, |
1967 | 0 | flags); |
1968 | 0 | if (lspec == NULL) |
1969 | 0 | return NULL; |
1970 | | |
1971 | 0 | lspec->minimum = minimum; |
1972 | 0 | lspec->maximum = maximum; |
1973 | 0 | lspec->default_value = default_value; |
1974 | | |
1975 | 0 | return G_PARAM_SPEC (lspec); |
1976 | 0 | } |
1977 | | |
1978 | | /** |
1979 | | * g_param_spec_uint64: |
1980 | | * @name: canonical name of the property specified |
1981 | | * @nick: nick name for the property specified |
1982 | | * @blurb: description of the property specified |
1983 | | * @minimum: minimum value for the property specified |
1984 | | * @maximum: maximum value for the property specified |
1985 | | * @default_value: default value for the property specified |
1986 | | * @flags: flags for the property specified |
1987 | | * |
1988 | | * Creates a new #GParamSpecUInt64 instance specifying a %G_TYPE_UINT64 |
1989 | | * property. |
1990 | | * |
1991 | | * See g_param_spec_internal() for details on property names. |
1992 | | * |
1993 | | * Returns: (transfer full): a newly created parameter specification |
1994 | | */ |
1995 | | GParamSpec* |
1996 | | g_param_spec_uint64 (const gchar *name, |
1997 | | const gchar *nick, |
1998 | | const gchar *blurb, |
1999 | | guint64 minimum, |
2000 | | guint64 maximum, |
2001 | | guint64 default_value, |
2002 | | GParamFlags flags) |
2003 | 0 | { |
2004 | 0 | GParamSpecUInt64 *uspec; |
2005 | | |
2006 | 0 | g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL); |
2007 | | |
2008 | 0 | uspec = g_param_spec_internal (G_TYPE_PARAM_UINT64, |
2009 | 0 | name, |
2010 | 0 | nick, |
2011 | 0 | blurb, |
2012 | 0 | flags); |
2013 | 0 | if (uspec == NULL) |
2014 | 0 | return NULL; |
2015 | | |
2016 | 0 | uspec->minimum = minimum; |
2017 | 0 | uspec->maximum = maximum; |
2018 | 0 | uspec->default_value = default_value; |
2019 | | |
2020 | 0 | return G_PARAM_SPEC (uspec); |
2021 | 0 | } |
2022 | | |
2023 | | /** |
2024 | | * g_param_spec_unichar: |
2025 | | * @name: canonical name of the property specified |
2026 | | * @nick: nick name for the property specified |
2027 | | * @blurb: description of the property specified |
2028 | | * @default_value: default value for the property specified |
2029 | | * @flags: flags for the property specified |
2030 | | * |
2031 | | * Creates a new #GParamSpecUnichar instance specifying a %G_TYPE_UINT |
2032 | | * property. #GValue structures for this property can be accessed with |
2033 | | * g_value_set_uint() and g_value_get_uint(). |
2034 | | * |
2035 | | * See g_param_spec_internal() for details on property names. |
2036 | | * |
2037 | | * Returns: (transfer full): a newly created parameter specification |
2038 | | */ |
2039 | | GParamSpec* |
2040 | | g_param_spec_unichar (const gchar *name, |
2041 | | const gchar *nick, |
2042 | | const gchar *blurb, |
2043 | | gunichar default_value, |
2044 | | GParamFlags flags) |
2045 | 0 | { |
2046 | 0 | GParamSpecUnichar *uspec; |
2047 | |
|
2048 | 0 | uspec = g_param_spec_internal (G_TYPE_PARAM_UNICHAR, |
2049 | 0 | name, |
2050 | 0 | nick, |
2051 | 0 | blurb, |
2052 | 0 | flags); |
2053 | 0 | if (uspec == NULL) |
2054 | 0 | return NULL; |
2055 | | |
2056 | 0 | uspec->default_value = default_value; |
2057 | | |
2058 | 0 | return G_PARAM_SPEC (uspec); |
2059 | 0 | } |
2060 | | |
2061 | | /** |
2062 | | * g_param_spec_enum: |
2063 | | * @name: canonical name of the property specified |
2064 | | * @nick: nick name for the property specified |
2065 | | * @blurb: description of the property specified |
2066 | | * @enum_type: a #GType derived from %G_TYPE_ENUM |
2067 | | * @default_value: default value for the property specified |
2068 | | * @flags: flags for the property specified |
2069 | | * |
2070 | | * Creates a new #GParamSpecEnum instance specifying a %G_TYPE_ENUM |
2071 | | * property. |
2072 | | * |
2073 | | * See g_param_spec_internal() for details on property names. |
2074 | | * |
2075 | | * Returns: (transfer full): a newly created parameter specification |
2076 | | */ |
2077 | | GParamSpec* |
2078 | | g_param_spec_enum (const gchar *name, |
2079 | | const gchar *nick, |
2080 | | const gchar *blurb, |
2081 | | GType enum_type, |
2082 | | gint default_value, |
2083 | | GParamFlags flags) |
2084 | 0 | { |
2085 | 0 | GParamSpecEnum *espec; |
2086 | 0 | GEnumClass *enum_class; |
2087 | | |
2088 | 0 | g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL); |
2089 | | |
2090 | 0 | enum_class = g_type_class_ref (enum_type); |
2091 | |
|
2092 | 0 | g_return_val_if_fail (g_enum_get_value (enum_class, default_value) != NULL, NULL); |
2093 | | |
2094 | 0 | espec = g_param_spec_internal (G_TYPE_PARAM_ENUM, |
2095 | 0 | name, |
2096 | 0 | nick, |
2097 | 0 | blurb, |
2098 | 0 | flags); |
2099 | 0 | if (espec == NULL) |
2100 | 0 | { |
2101 | 0 | g_type_class_unref (enum_class); |
2102 | 0 | return NULL; |
2103 | 0 | } |
2104 | | |
2105 | 0 | espec->enum_class = enum_class; |
2106 | 0 | espec->default_value = default_value; |
2107 | 0 | G_PARAM_SPEC (espec)->value_type = enum_type; |
2108 | | |
2109 | 0 | return G_PARAM_SPEC (espec); |
2110 | 0 | } |
2111 | | |
2112 | | /** |
2113 | | * g_param_spec_flags: |
2114 | | * @name: canonical name of the property specified |
2115 | | * @nick: nick name for the property specified |
2116 | | * @blurb: description of the property specified |
2117 | | * @flags_type: a #GType derived from %G_TYPE_FLAGS |
2118 | | * @default_value: default value for the property specified |
2119 | | * @flags: flags for the property specified |
2120 | | * |
2121 | | * Creates a new #GParamSpecFlags instance specifying a %G_TYPE_FLAGS |
2122 | | * property. |
2123 | | * |
2124 | | * See g_param_spec_internal() for details on property names. |
2125 | | * |
2126 | | * Returns: (transfer full): a newly created parameter specification |
2127 | | */ |
2128 | | GParamSpec* |
2129 | | g_param_spec_flags (const gchar *name, |
2130 | | const gchar *nick, |
2131 | | const gchar *blurb, |
2132 | | GType flags_type, |
2133 | | guint default_value, |
2134 | | GParamFlags flags) |
2135 | 0 | { |
2136 | 0 | GParamSpecFlags *fspec; |
2137 | 0 | GFlagsClass *flags_class; |
2138 | | |
2139 | 0 | g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL); |
2140 | | |
2141 | 0 | flags_class = g_type_class_ref (flags_type); |
2142 | |
|
2143 | 0 | g_return_val_if_fail ((default_value & flags_class->mask) == default_value, NULL); |
2144 | | |
2145 | 0 | fspec = g_param_spec_internal (G_TYPE_PARAM_FLAGS, |
2146 | 0 | name, |
2147 | 0 | nick, |
2148 | 0 | blurb, |
2149 | 0 | flags); |
2150 | 0 | if (fspec == NULL) |
2151 | 0 | { |
2152 | 0 | g_type_class_unref (flags_class); |
2153 | 0 | return NULL; |
2154 | 0 | } |
2155 | | |
2156 | 0 | fspec->flags_class = flags_class; |
2157 | 0 | fspec->default_value = default_value; |
2158 | 0 | G_PARAM_SPEC (fspec)->value_type = flags_type; |
2159 | | |
2160 | 0 | return G_PARAM_SPEC (fspec); |
2161 | 0 | } |
2162 | | |
2163 | | /** |
2164 | | * g_param_spec_float: |
2165 | | * @name: canonical name of the property specified |
2166 | | * @nick: nick name for the property specified |
2167 | | * @blurb: description of the property specified |
2168 | | * @minimum: minimum value for the property specified |
2169 | | * @maximum: maximum value for the property specified |
2170 | | * @default_value: default value for the property specified |
2171 | | * @flags: flags for the property specified |
2172 | | * |
2173 | | * Creates a new #GParamSpecFloat instance specifying a %G_TYPE_FLOAT property. |
2174 | | * |
2175 | | * See g_param_spec_internal() for details on property names. |
2176 | | * |
2177 | | * Returns: (transfer full): a newly created parameter specification |
2178 | | */ |
2179 | | GParamSpec* |
2180 | | g_param_spec_float (const gchar *name, |
2181 | | const gchar *nick, |
2182 | | const gchar *blurb, |
2183 | | gfloat minimum, |
2184 | | gfloat maximum, |
2185 | | gfloat default_value, |
2186 | | GParamFlags flags) |
2187 | 0 | { |
2188 | 0 | GParamSpecFloat *fspec; |
2189 | |
|
2190 | 0 | g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL); |
2191 | | |
2192 | 0 | fspec = g_param_spec_internal (G_TYPE_PARAM_FLOAT, |
2193 | 0 | name, |
2194 | 0 | nick, |
2195 | 0 | blurb, |
2196 | 0 | flags); |
2197 | 0 | if (fspec == NULL) |
2198 | 0 | return NULL; |
2199 | | |
2200 | 0 | fspec->minimum = minimum; |
2201 | 0 | fspec->maximum = maximum; |
2202 | 0 | fspec->default_value = default_value; |
2203 | | |
2204 | 0 | return G_PARAM_SPEC (fspec); |
2205 | 0 | } |
2206 | | |
2207 | | /** |
2208 | | * g_param_spec_double: |
2209 | | * @name: canonical name of the property specified |
2210 | | * @nick: nick name for the property specified |
2211 | | * @blurb: description of the property specified |
2212 | | * @minimum: minimum value for the property specified |
2213 | | * @maximum: maximum value for the property specified |
2214 | | * @default_value: default value for the property specified |
2215 | | * @flags: flags for the property specified |
2216 | | * |
2217 | | * Creates a new #GParamSpecDouble instance specifying a %G_TYPE_DOUBLE |
2218 | | * property. |
2219 | | * |
2220 | | * See g_param_spec_internal() for details on property names. |
2221 | | * |
2222 | | * Returns: (transfer full): a newly created parameter specification |
2223 | | */ |
2224 | | GParamSpec* |
2225 | | g_param_spec_double (const gchar *name, |
2226 | | const gchar *nick, |
2227 | | const gchar *blurb, |
2228 | | gdouble minimum, |
2229 | | gdouble maximum, |
2230 | | gdouble default_value, |
2231 | | GParamFlags flags) |
2232 | 0 | { |
2233 | 0 | GParamSpecDouble *dspec; |
2234 | |
|
2235 | 0 | g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL); |
2236 | | |
2237 | 0 | dspec = g_param_spec_internal (G_TYPE_PARAM_DOUBLE, |
2238 | 0 | name, |
2239 | 0 | nick, |
2240 | 0 | blurb, |
2241 | 0 | flags); |
2242 | 0 | if (dspec == NULL) |
2243 | 0 | return NULL; |
2244 | | |
2245 | 0 | dspec->minimum = minimum; |
2246 | 0 | dspec->maximum = maximum; |
2247 | 0 | dspec->default_value = default_value; |
2248 | | |
2249 | 0 | return G_PARAM_SPEC (dspec); |
2250 | 0 | } |
2251 | | |
2252 | | /** |
2253 | | * g_param_spec_string: |
2254 | | * @name: canonical name of the property specified |
2255 | | * @nick: nick name for the property specified |
2256 | | * @blurb: description of the property specified |
2257 | | * @default_value: (nullable): default value for the property specified |
2258 | | * @flags: flags for the property specified |
2259 | | * |
2260 | | * Creates a new #GParamSpecString instance. |
2261 | | * |
2262 | | * See g_param_spec_internal() for details on property names. |
2263 | | * |
2264 | | * Returns: (transfer full): a newly created parameter specification |
2265 | | */ |
2266 | | GParamSpec* |
2267 | | g_param_spec_string (const gchar *name, |
2268 | | const gchar *nick, |
2269 | | const gchar *blurb, |
2270 | | const gchar *default_value, |
2271 | | GParamFlags flags) |
2272 | 0 | { |
2273 | 0 | GParamSpecString *sspec = g_param_spec_internal (G_TYPE_PARAM_STRING, |
2274 | 0 | name, |
2275 | 0 | nick, |
2276 | 0 | blurb, |
2277 | 0 | flags); |
2278 | 0 | if (sspec == NULL) |
2279 | 0 | return NULL; |
2280 | | |
2281 | 0 | g_free (sspec->default_value); |
2282 | 0 | sspec->default_value = g_strdup (default_value); |
2283 | | |
2284 | 0 | return G_PARAM_SPEC (sspec); |
2285 | 0 | } |
2286 | | |
2287 | | /** |
2288 | | * g_param_spec_param: |
2289 | | * @name: canonical name of the property specified |
2290 | | * @nick: nick name for the property specified |
2291 | | * @blurb: description of the property specified |
2292 | | * @param_type: a #GType derived from %G_TYPE_PARAM |
2293 | | * @flags: flags for the property specified |
2294 | | * |
2295 | | * Creates a new #GParamSpecParam instance specifying a %G_TYPE_PARAM |
2296 | | * property. |
2297 | | * |
2298 | | * See g_param_spec_internal() for details on property names. |
2299 | | * |
2300 | | * Returns: (transfer full): a newly created parameter specification |
2301 | | */ |
2302 | | GParamSpec* |
2303 | | g_param_spec_param (const gchar *name, |
2304 | | const gchar *nick, |
2305 | | const gchar *blurb, |
2306 | | GType param_type, |
2307 | | GParamFlags flags) |
2308 | 0 | { |
2309 | 0 | GParamSpecParam *pspec; |
2310 | | |
2311 | 0 | g_return_val_if_fail (G_TYPE_IS_PARAM (param_type), NULL); |
2312 | | |
2313 | 0 | pspec = g_param_spec_internal (G_TYPE_PARAM_PARAM, |
2314 | 0 | name, |
2315 | 0 | nick, |
2316 | 0 | blurb, |
2317 | 0 | flags); |
2318 | 0 | if (pspec == NULL) |
2319 | 0 | return NULL; |
2320 | | |
2321 | 0 | G_PARAM_SPEC (pspec)->value_type = param_type; |
2322 | | |
2323 | 0 | return G_PARAM_SPEC (pspec); |
2324 | 0 | } |
2325 | | |
2326 | | /** |
2327 | | * g_param_spec_boxed: |
2328 | | * @name: canonical name of the property specified |
2329 | | * @nick: nick name for the property specified |
2330 | | * @blurb: description of the property specified |
2331 | | * @boxed_type: %G_TYPE_BOXED derived type of this property |
2332 | | * @flags: flags for the property specified |
2333 | | * |
2334 | | * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_BOXED |
2335 | | * derived property. |
2336 | | * |
2337 | | * See g_param_spec_internal() for details on property names. |
2338 | | * |
2339 | | * Returns: (transfer full): a newly created parameter specification |
2340 | | */ |
2341 | | GParamSpec* |
2342 | | g_param_spec_boxed (const gchar *name, |
2343 | | const gchar *nick, |
2344 | | const gchar *blurb, |
2345 | | GType boxed_type, |
2346 | | GParamFlags flags) |
2347 | 0 | { |
2348 | 0 | GParamSpecBoxed *bspec; |
2349 | | |
2350 | 0 | g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL); |
2351 | 0 | g_return_val_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type), NULL); |
2352 | | |
2353 | 0 | bspec = g_param_spec_internal (G_TYPE_PARAM_BOXED, |
2354 | 0 | name, |
2355 | 0 | nick, |
2356 | 0 | blurb, |
2357 | 0 | flags); |
2358 | 0 | if (bspec == NULL) |
2359 | 0 | return NULL; |
2360 | | |
2361 | 0 | G_PARAM_SPEC (bspec)->value_type = boxed_type; |
2362 | | |
2363 | 0 | return G_PARAM_SPEC (bspec); |
2364 | 0 | } |
2365 | | |
2366 | | /** |
2367 | | * g_param_spec_pointer: |
2368 | | * @name: canonical name of the property specified |
2369 | | * @nick: nick name for the property specified |
2370 | | * @blurb: description of the property specified |
2371 | | * @flags: flags for the property specified |
2372 | | * |
2373 | | * Creates a new #GParamSpecPointer instance specifying a pointer property. |
2374 | | * Where possible, it is better to use g_param_spec_object() or |
2375 | | * g_param_spec_boxed() to expose memory management information. |
2376 | | * |
2377 | | * See g_param_spec_internal() for details on property names. |
2378 | | * |
2379 | | * Returns: (transfer full): a newly created parameter specification |
2380 | | */ |
2381 | | GParamSpec* |
2382 | | g_param_spec_pointer (const gchar *name, |
2383 | | const gchar *nick, |
2384 | | const gchar *blurb, |
2385 | | GParamFlags flags) |
2386 | 0 | { |
2387 | 0 | GParamSpecPointer *pspec; |
2388 | | |
2389 | 0 | pspec = g_param_spec_internal (G_TYPE_PARAM_POINTER, |
2390 | 0 | name, |
2391 | 0 | nick, |
2392 | 0 | blurb, |
2393 | 0 | flags); |
2394 | 0 | if (pspec == NULL) |
2395 | 0 | return NULL; |
2396 | | |
2397 | 0 | return G_PARAM_SPEC (pspec); |
2398 | 0 | } |
2399 | | |
2400 | | /** |
2401 | | * g_param_spec_gtype: |
2402 | | * @name: canonical name of the property specified |
2403 | | * @nick: nick name for the property specified |
2404 | | * @blurb: description of the property specified |
2405 | | * @is_a_type: a #GType whose subtypes are allowed as values |
2406 | | * of the property (use %G_TYPE_NONE for any type) |
2407 | | * @flags: flags for the property specified |
2408 | | * |
2409 | | * Creates a new #GParamSpecGType instance specifying a |
2410 | | * %G_TYPE_GTYPE property. |
2411 | | * |
2412 | | * See g_param_spec_internal() for details on property names. |
2413 | | * |
2414 | | * Since: 2.10 |
2415 | | * |
2416 | | * Returns: (transfer full): a newly created parameter specification |
2417 | | */ |
2418 | | GParamSpec* |
2419 | | g_param_spec_gtype (const gchar *name, |
2420 | | const gchar *nick, |
2421 | | const gchar *blurb, |
2422 | | GType is_a_type, |
2423 | | GParamFlags flags) |
2424 | 0 | { |
2425 | 0 | GParamSpecGType *tspec; |
2426 | | |
2427 | 0 | tspec = g_param_spec_internal (G_TYPE_PARAM_GTYPE, |
2428 | 0 | name, |
2429 | 0 | nick, |
2430 | 0 | blurb, |
2431 | 0 | flags); |
2432 | 0 | if (tspec == NULL) |
2433 | 0 | return NULL; |
2434 | | |
2435 | 0 | tspec->is_a_type = is_a_type; |
2436 | |
|
2437 | 0 | return G_PARAM_SPEC (tspec); |
2438 | 0 | } |
2439 | | |
2440 | | /** |
2441 | | * g_param_spec_value_array: (skip) |
2442 | | * @name: canonical name of the property specified |
2443 | | * @nick: nick name for the property specified |
2444 | | * @blurb: description of the property specified |
2445 | | * @element_spec: a #GParamSpec describing the elements contained in |
2446 | | * arrays of this property, may be %NULL |
2447 | | * @flags: flags for the property specified |
2448 | | * |
2449 | | * Creates a new #GParamSpecValueArray instance specifying a |
2450 | | * %G_TYPE_VALUE_ARRAY property. %G_TYPE_VALUE_ARRAY is a |
2451 | | * %G_TYPE_BOXED type, as such, #GValue structures for this property |
2452 | | * can be accessed with g_value_set_boxed() and g_value_get_boxed(). |
2453 | | * |
2454 | | * See g_param_spec_internal() for details on property names. |
2455 | | * |
2456 | | * Returns: a newly created parameter specification |
2457 | | */ |
2458 | | GParamSpec* |
2459 | | g_param_spec_value_array (const gchar *name, |
2460 | | const gchar *nick, |
2461 | | const gchar *blurb, |
2462 | | GParamSpec *element_spec, |
2463 | | GParamFlags flags) |
2464 | 0 | { |
2465 | 0 | GParamSpecValueArray *aspec; |
2466 | | |
2467 | 0 | if (element_spec) |
2468 | 0 | g_return_val_if_fail (G_IS_PARAM_SPEC (element_spec), NULL); |
2469 | | |
2470 | 0 | aspec = g_param_spec_internal (G_TYPE_PARAM_VALUE_ARRAY, |
2471 | 0 | name, |
2472 | 0 | nick, |
2473 | 0 | blurb, |
2474 | 0 | flags); |
2475 | 0 | if (aspec == NULL) |
2476 | 0 | return NULL; |
2477 | | |
2478 | 0 | if (element_spec) |
2479 | 0 | { |
2480 | 0 | aspec->element_spec = g_param_spec_ref (element_spec); |
2481 | 0 | g_param_spec_sink (element_spec); |
2482 | 0 | } |
2483 | |
|
2484 | 0 | return G_PARAM_SPEC (aspec); |
2485 | 0 | } |
2486 | | |
2487 | | /** |
2488 | | * g_param_spec_object: |
2489 | | * @name: canonical name of the property specified |
2490 | | * @nick: nick name for the property specified |
2491 | | * @blurb: description of the property specified |
2492 | | * @object_type: %G_TYPE_OBJECT derived type of this property |
2493 | | * @flags: flags for the property specified |
2494 | | * |
2495 | | * Creates a new #GParamSpecBoxed instance specifying a %G_TYPE_OBJECT |
2496 | | * derived property. |
2497 | | * |
2498 | | * See g_param_spec_internal() for details on property names. |
2499 | | * |
2500 | | * Returns: (transfer full): a newly created parameter specification |
2501 | | */ |
2502 | | GParamSpec* |
2503 | | g_param_spec_object (const gchar *name, |
2504 | | const gchar *nick, |
2505 | | const gchar *blurb, |
2506 | | GType object_type, |
2507 | | GParamFlags flags) |
2508 | 36 | { |
2509 | 36 | GParamSpecObject *ospec; |
2510 | | |
2511 | 36 | g_return_val_if_fail (g_type_is_a (object_type, G_TYPE_OBJECT), NULL); |
2512 | | |
2513 | 36 | ospec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, |
2514 | 36 | name, |
2515 | 36 | nick, |
2516 | 36 | blurb, |
2517 | 36 | flags); |
2518 | 36 | if (ospec == NULL) |
2519 | 0 | return NULL; |
2520 | | |
2521 | 36 | G_PARAM_SPEC (ospec)->value_type = object_type; |
2522 | | |
2523 | 36 | return G_PARAM_SPEC (ospec); |
2524 | 36 | } |
2525 | | |
2526 | | /** |
2527 | | * g_param_spec_override: (skip) |
2528 | | * @name: the name of the property. |
2529 | | * @overridden: The property that is being overridden |
2530 | | * |
2531 | | * Creates a new property of type #GParamSpecOverride. This is used |
2532 | | * to direct operations to another paramspec, and will not be directly |
2533 | | * useful unless you are implementing a new base type similar to GObject. |
2534 | | * |
2535 | | * Since: 2.4 |
2536 | | * |
2537 | | * Returns: the newly created #GParamSpec |
2538 | | */ |
2539 | | GParamSpec* |
2540 | | g_param_spec_override (const gchar *name, |
2541 | | GParamSpec *overridden) |
2542 | 0 | { |
2543 | 0 | GParamSpec *pspec; |
2544 | | |
2545 | 0 | g_return_val_if_fail (name != NULL, NULL); |
2546 | 0 | g_return_val_if_fail (G_IS_PARAM_SPEC (overridden), NULL); |
2547 | | |
2548 | | /* Dereference further redirections for property that was passed in |
2549 | | */ |
2550 | 0 | while (TRUE) |
2551 | 0 | { |
2552 | 0 | GParamSpec *indirect = g_param_spec_get_redirect_target (overridden); |
2553 | 0 | if (indirect) |
2554 | 0 | overridden = indirect; |
2555 | 0 | else |
2556 | 0 | break; |
2557 | 0 | } |
2558 | |
|
2559 | 0 | pspec = g_param_spec_internal (G_TYPE_PARAM_OVERRIDE, |
2560 | 0 | name, NULL, NULL, |
2561 | 0 | overridden->flags); |
2562 | 0 | if (pspec == NULL) |
2563 | 0 | return NULL; |
2564 | | |
2565 | 0 | pspec->value_type = G_PARAM_SPEC_VALUE_TYPE (overridden); |
2566 | 0 | G_PARAM_SPEC_OVERRIDE (pspec)->overridden = g_param_spec_ref (overridden); |
2567 | |
|
2568 | 0 | return pspec; |
2569 | 0 | } |
2570 | | |
2571 | | /** |
2572 | | * g_param_spec_variant: |
2573 | | * @name: canonical name of the property specified |
2574 | | * @nick: nick name for the property specified |
2575 | | * @blurb: description of the property specified |
2576 | | * @type: a #GVariantType |
2577 | | * @default_value: (nullable) (transfer full): a #GVariant of type @type to |
2578 | | * use as the default value, or %NULL |
2579 | | * @flags: flags for the property specified |
2580 | | * |
2581 | | * Creates a new #GParamSpecVariant instance specifying a #GVariant |
2582 | | * property. |
2583 | | * |
2584 | | * If @default_value is floating, it is consumed. |
2585 | | * |
2586 | | * See g_param_spec_internal() for details on property names. |
2587 | | * |
2588 | | * Returns: (transfer full): the newly created #GParamSpec |
2589 | | * |
2590 | | * Since: 2.26 |
2591 | | */ |
2592 | | GParamSpec* |
2593 | | g_param_spec_variant (const gchar *name, |
2594 | | const gchar *nick, |
2595 | | const gchar *blurb, |
2596 | | const GVariantType *type, |
2597 | | GVariant *default_value, |
2598 | | GParamFlags flags) |
2599 | 0 | { |
2600 | 0 | GParamSpecVariant *vspec; |
2601 | |
|
2602 | 0 | g_return_val_if_fail (type != NULL, NULL); |
2603 | 0 | g_return_val_if_fail (default_value == NULL || |
2604 | 0 | g_variant_is_of_type (default_value, type), NULL); |
2605 | | |
2606 | 0 | vspec = g_param_spec_internal (G_TYPE_PARAM_VARIANT, |
2607 | 0 | name, |
2608 | 0 | nick, |
2609 | 0 | blurb, |
2610 | 0 | flags); |
2611 | 0 | if (vspec == NULL) |
2612 | 0 | return NULL; |
2613 | | |
2614 | 0 | vspec->type = g_variant_type_copy (type); |
2615 | 0 | if (default_value) |
2616 | 0 | vspec->default_value = g_variant_ref_sink (default_value); |
2617 | |
|
2618 | 0 | return G_PARAM_SPEC (vspec); |
2619 | 0 | } |