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