Branch data Line data Source code
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 : : #define G_FLOAT_EPSILON (1e-30f)
41 : : #define G_DOUBLE_EPSILON (1e-90)
42 : :
43 : :
44 : : /* --- param spec functions --- */
45 : : static void
46 : 6 : param_char_init (GParamSpec *pspec)
47 : : {
48 : 6 : GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
49 : :
50 : 6 : cspec->minimum = CHAR_MIN;
51 : 6 : cspec->maximum = CHAR_MAX;
52 : 6 : cspec->default_value = 0;
53 : 6 : }
54 : :
55 : : static void
56 : 2 : param_char_set_default (GParamSpec *pspec,
57 : : GValue *value)
58 : : {
59 : 2 : value->data[0].v_int = G_PARAM_SPEC_CHAR (pspec)->default_value;
60 : 2 : }
61 : :
62 : : static gboolean
63 : 15 : param_char_is_valid (GParamSpec *pspec,
64 : : const GValue *value)
65 : : {
66 : 15 : GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
67 : 15 : gint oval = value->data[0].v_int;
68 : :
69 : 15 : return cspec->minimum <= oval && oval <= cspec->maximum;
70 : : }
71 : :
72 : : static gboolean
73 : 12 : param_char_validate (GParamSpec *pspec,
74 : : GValue *value)
75 : : {
76 : 12 : GParamSpecChar *cspec = G_PARAM_SPEC_CHAR (pspec);
77 : 12 : gint oval = value->data[0].v_int;
78 : :
79 : 12 : value->data[0].v_int = CLAMP (value->data[0].v_int, cspec->minimum, cspec->maximum);
80 : :
81 : 12 : return value->data[0].v_int != oval;
82 : : }
83 : :
84 : : static void
85 : 4 : param_uchar_init (GParamSpec *pspec)
86 : : {
87 : 4 : GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
88 : :
89 : 4 : uspec->minimum = 0;
90 : 4 : uspec->maximum = UCHAR_MAX;
91 : 4 : uspec->default_value = 0;
92 : 4 : }
93 : :
94 : : static void
95 : 0 : param_uchar_set_default (GParamSpec *pspec,
96 : : GValue *value)
97 : : {
98 : 0 : value->data[0].v_uint = G_PARAM_SPEC_UCHAR (pspec)->default_value;
99 : 0 : }
100 : :
101 : : static gboolean
102 : 14 : param_uchar_is_valid (GParamSpec *pspec,
103 : : const GValue *value)
104 : : {
105 : 14 : GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
106 : 14 : guint oval = value->data[0].v_uint;
107 : :
108 : 14 : return uspec->minimum <= oval && oval <= uspec->maximum;
109 : : }
110 : :
111 : : static gboolean
112 : 2 : param_uchar_validate (GParamSpec *pspec,
113 : : GValue *value)
114 : : {
115 : 2 : GParamSpecUChar *uspec = G_PARAM_SPEC_UCHAR (pspec);
116 : 2 : guint oval = value->data[0].v_uint;
117 : :
118 : 2 : value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
119 : :
120 : 2 : return value->data[0].v_uint != oval;
121 : : }
122 : :
123 : : static void
124 : 584 : param_boolean_set_default (GParamSpec *pspec,
125 : : GValue *value)
126 : : {
127 : 584 : value->data[0].v_int = G_PARAM_SPEC_BOOLEAN (pspec)->default_value;
128 : 584 : }
129 : :
130 : : static gboolean
131 : 19358 : param_boolean_is_valid (GParamSpec *pspec,
132 : : const GValue *value)
133 : : {
134 : 19358 : int oval = value->data[0].v_int;
135 : :
136 : 19358 : return oval == FALSE || oval == TRUE;
137 : : }
138 : :
139 : : static gboolean
140 : 2 : param_boolean_validate (GParamSpec *pspec,
141 : : GValue *value)
142 : : {
143 : 2 : gint oval = value->data[0].v_int;
144 : :
145 : 2 : value->data[0].v_int = value->data[0].v_int != FALSE;
146 : :
147 : 2 : return value->data[0].v_int != oval;
148 : : }
149 : :
150 : : static void
151 : 623 : param_int_init (GParamSpec *pspec)
152 : : {
153 : 623 : GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
154 : :
155 : 623 : ispec->minimum = INT_MIN;
156 : 623 : ispec->maximum = INT_MAX;
157 : 623 : ispec->default_value = 0;
158 : 623 : }
159 : :
160 : : static void
161 : 216 : param_int_set_default (GParamSpec *pspec,
162 : : GValue *value)
163 : : {
164 : 216 : value->data[0].v_int = G_PARAM_SPEC_INT (pspec)->default_value;
165 : 216 : }
166 : :
167 : : static gboolean
168 : 12102530 : param_int_is_valid (GParamSpec *pspec,
169 : : const GValue *value)
170 : : {
171 : 12102530 : GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
172 : 12102530 : int oval = value->data[0].v_int;
173 : :
174 : 12102530 : return ispec->minimum <= oval && oval <= ispec->maximum;
175 : : }
176 : :
177 : : static gboolean
178 : 53 : param_int_validate (GParamSpec *pspec,
179 : : GValue *value)
180 : : {
181 : 53 : GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec);
182 : 53 : gint oval = value->data[0].v_int;
183 : :
184 : 53 : value->data[0].v_int = CLAMP (value->data[0].v_int, ispec->minimum, ispec->maximum);
185 : :
186 : 53 : return value->data[0].v_int != oval;
187 : : }
188 : :
189 : : static gint
190 : 26 : param_int_values_cmp (GParamSpec *pspec,
191 : : const GValue *value1,
192 : : const GValue *value2)
193 : : {
194 : 26 : if (value1->data[0].v_int < value2->data[0].v_int)
195 : 2 : return -1;
196 : : else
197 : 24 : return value1->data[0].v_int > value2->data[0].v_int;
198 : : }
199 : :
200 : : static void
201 : 876 : param_uint_init (GParamSpec *pspec)
202 : : {
203 : 876 : GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
204 : :
205 : 876 : uspec->minimum = 0;
206 : 876 : uspec->maximum = UINT_MAX;
207 : 876 : uspec->default_value = 0;
208 : 876 : }
209 : :
210 : : static void
211 : 365 : param_uint_set_default (GParamSpec *pspec,
212 : : GValue *value)
213 : : {
214 : 365 : value->data[0].v_uint = G_PARAM_SPEC_UINT (pspec)->default_value;
215 : 365 : }
216 : :
217 : : static gboolean
218 : 10905 : param_uint_is_valid (GParamSpec *pspec,
219 : : const GValue *value)
220 : : {
221 : 10905 : GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
222 : 10905 : guint oval = value->data[0].v_uint;
223 : :
224 : 10905 : return uspec->minimum <= oval && oval <= uspec->maximum;
225 : : }
226 : :
227 : : static gboolean
228 : 1 : param_uint_validate (GParamSpec *pspec,
229 : : GValue *value)
230 : : {
231 : 1 : GParamSpecUInt *uspec = G_PARAM_SPEC_UINT (pspec);
232 : 1 : guint oval = value->data[0].v_uint;
233 : :
234 : 1 : value->data[0].v_uint = CLAMP (value->data[0].v_uint, uspec->minimum, uspec->maximum);
235 : :
236 : 1 : return value->data[0].v_uint != oval;
237 : : }
238 : :
239 : : static gint
240 : 7 : param_uint_values_cmp (GParamSpec *pspec,
241 : : const GValue *value1,
242 : : const GValue *value2)
243 : : {
244 : 7 : if (value1->data[0].v_uint < value2->data[0].v_uint)
245 : 0 : return -1;
246 : : else
247 : 7 : return value1->data[0].v_uint > value2->data[0].v_uint;
248 : : }
249 : :
250 : : static void
251 : 3 : param_long_init (GParamSpec *pspec)
252 : : {
253 : 3 : GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
254 : :
255 : 3 : lspec->minimum = LONG_MIN;
256 : 3 : lspec->maximum = LONG_MAX;
257 : 3 : lspec->default_value = 0;
258 : 3 : }
259 : :
260 : : static void
261 : 2 : param_long_set_default (GParamSpec *pspec,
262 : : GValue *value)
263 : : {
264 : 2 : value->data[0].v_long = G_PARAM_SPEC_LONG (pspec)->default_value;
265 : 2 : }
266 : :
267 : : static gboolean
268 : 1 : param_long_is_valid (GParamSpec *pspec,
269 : : const GValue *value)
270 : : {
271 : 1 : GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
272 : 1 : glong oval = value->data[0].v_long;
273 : :
274 : 1 : return lspec->minimum <= oval && oval <= lspec->maximum;
275 : : }
276 : :
277 : : static gboolean
278 : 1 : param_long_validate (GParamSpec *pspec,
279 : : GValue *value)
280 : : {
281 : 1 : GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec);
282 : 1 : glong oval = value->data[0].v_long;
283 : :
284 : 1 : value->data[0].v_long = CLAMP (value->data[0].v_long, lspec->minimum, lspec->maximum);
285 : :
286 : 1 : return value->data[0].v_long != oval;
287 : : }
288 : :
289 : : static gint
290 : 8 : param_long_values_cmp (GParamSpec *pspec,
291 : : const GValue *value1,
292 : : const GValue *value2)
293 : : {
294 : 8 : if (value1->data[0].v_long < value2->data[0].v_long)
295 : 0 : return -1;
296 : : else
297 : 8 : return value1->data[0].v_long > value2->data[0].v_long;
298 : : }
299 : :
300 : : static void
301 : 31 : param_ulong_init (GParamSpec *pspec)
302 : : {
303 : 31 : GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
304 : :
305 : 31 : uspec->minimum = 0;
306 : 31 : uspec->maximum = ULONG_MAX;
307 : 31 : uspec->default_value = 0;
308 : 31 : }
309 : :
310 : : static void
311 : 8 : param_ulong_set_default (GParamSpec *pspec,
312 : : GValue *value)
313 : : {
314 : 8 : value->data[0].v_ulong = G_PARAM_SPEC_ULONG (pspec)->default_value;
315 : 8 : }
316 : :
317 : : static gboolean
318 : 1163 : param_ulong_is_valid (GParamSpec *pspec,
319 : : const GValue *value)
320 : : {
321 : 1163 : GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
322 : 1163 : gulong oval = value->data[0].v_ulong;
323 : :
324 : 1163 : return uspec->minimum <= oval && oval <= uspec->maximum;
325 : : }
326 : :
327 : : static gboolean
328 : 1 : param_ulong_validate (GParamSpec *pspec,
329 : : GValue *value)
330 : : {
331 : 1 : GParamSpecULong *uspec = G_PARAM_SPEC_ULONG (pspec);
332 : 1 : gulong oval = value->data[0].v_ulong;
333 : :
334 : 1 : value->data[0].v_ulong = CLAMP (value->data[0].v_ulong, uspec->minimum, uspec->maximum);
335 : :
336 : 1 : return value->data[0].v_ulong != oval;
337 : : }
338 : :
339 : : static gint
340 : 7 : param_ulong_values_cmp (GParamSpec *pspec,
341 : : const GValue *value1,
342 : : const GValue *value2)
343 : : {
344 : 7 : if (value1->data[0].v_ulong < value2->data[0].v_ulong)
345 : 0 : return -1;
346 : : else
347 : 7 : return value1->data[0].v_ulong > value2->data[0].v_ulong;
348 : : }
349 : :
350 : : static void
351 : 8 : param_int64_init (GParamSpec *pspec)
352 : : {
353 : 8 : GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
354 : :
355 : 8 : lspec->minimum = G_MININT64;
356 : 8 : lspec->maximum = G_MAXINT64;
357 : 8 : lspec->default_value = 0;
358 : 8 : }
359 : :
360 : : static void
361 : 2 : param_int64_set_default (GParamSpec *pspec,
362 : : GValue *value)
363 : : {
364 : 2 : value->data[0].v_int64 = G_PARAM_SPEC_INT64 (pspec)->default_value;
365 : 2 : }
366 : :
367 : : static gboolean
368 : 4 : param_int64_is_valid (GParamSpec *pspec,
369 : : const GValue *value)
370 : : {
371 : 4 : GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
372 : 4 : gint64 oval = value->data[0].v_int64;
373 : :
374 : 4 : return lspec->minimum <= oval && oval <= lspec->maximum;
375 : : }
376 : :
377 : : static gboolean
378 : 1 : param_int64_validate (GParamSpec *pspec,
379 : : GValue *value)
380 : : {
381 : 1 : GParamSpecInt64 *lspec = G_PARAM_SPEC_INT64 (pspec);
382 : 1 : gint64 oval = value->data[0].v_int64;
383 : :
384 : 1 : value->data[0].v_int64 = CLAMP (value->data[0].v_int64, lspec->minimum, lspec->maximum);
385 : :
386 : 1 : return value->data[0].v_int64 != oval;
387 : : }
388 : :
389 : : static gint
390 : 1 : param_int64_values_cmp (GParamSpec *pspec,
391 : : const GValue *value1,
392 : : const GValue *value2)
393 : : {
394 : 1 : if (value1->data[0].v_int64 < value2->data[0].v_int64)
395 : 0 : return -1;
396 : : else
397 : 1 : return value1->data[0].v_int64 > value2->data[0].v_int64;
398 : : }
399 : :
400 : : static void
401 : 8 : param_uint64_init (GParamSpec *pspec)
402 : : {
403 : 8 : GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
404 : :
405 : 8 : uspec->minimum = 0;
406 : 8 : uspec->maximum = G_MAXUINT64;
407 : 8 : uspec->default_value = 0;
408 : 8 : }
409 : :
410 : : static void
411 : 2 : param_uint64_set_default (GParamSpec *pspec,
412 : : GValue *value)
413 : : {
414 : 2 : value->data[0].v_uint64 = G_PARAM_SPEC_UINT64 (pspec)->default_value;
415 : 2 : }
416 : :
417 : : static gboolean
418 : 7 : param_uint64_is_valid (GParamSpec *pspec,
419 : : const GValue *value)
420 : : {
421 : 7 : GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
422 : 7 : guint64 oval = value->data[0].v_uint64;
423 : :
424 : 7 : return uspec->minimum <= oval && oval <= uspec->maximum;
425 : : }
426 : :
427 : : static gboolean
428 : 1 : param_uint64_validate (GParamSpec *pspec,
429 : : GValue *value)
430 : : {
431 : 1 : GParamSpecUInt64 *uspec = G_PARAM_SPEC_UINT64 (pspec);
432 : 1 : guint64 oval = value->data[0].v_uint64;
433 : :
434 : 1 : value->data[0].v_uint64 = CLAMP (value->data[0].v_uint64, uspec->minimum, uspec->maximum);
435 : :
436 : 1 : return value->data[0].v_uint64 != oval;
437 : : }
438 : :
439 : : static gint
440 : 1 : param_uint64_values_cmp (GParamSpec *pspec,
441 : : const GValue *value1,
442 : : const GValue *value2)
443 : : {
444 : 1 : if (value1->data[0].v_uint64 < value2->data[0].v_uint64)
445 : 0 : return -1;
446 : : else
447 : 1 : return value1->data[0].v_uint64 > value2->data[0].v_uint64;
448 : : }
449 : :
450 : : static void
451 : 1 : param_unichar_init (GParamSpec *pspec)
452 : : {
453 : 1 : GParamSpecUnichar *uspec = G_PARAM_SPEC_UNICHAR (pspec);
454 : :
455 : 1 : uspec->default_value = 0;
456 : 1 : }
457 : :
458 : : static void
459 : 0 : param_unichar_set_default (GParamSpec *pspec,
460 : : GValue *value)
461 : : {
462 : 0 : value->data[0].v_uint = G_PARAM_SPEC_UNICHAR (pspec)->default_value;
463 : 0 : }
464 : :
465 : : static gboolean
466 : 2 : param_unichar_is_valid (GParamSpec *pspec,
467 : : const GValue *value)
468 : : {
469 : 2 : return g_unichar_validate (value->data[0].v_uint);
470 : : }
471 : :
472 : : static gboolean
473 : 2 : param_unichar_validate (GParamSpec *pspec,
474 : : GValue *value)
475 : : {
476 : 2 : gunichar oval = value->data[0].v_uint;
477 : 2 : gboolean changed = FALSE;
478 : :
479 : 2 : if (!g_unichar_validate (oval))
480 : : {
481 : 1 : value->data[0].v_uint = 0;
482 : 1 : changed = TRUE;
483 : : }
484 : :
485 : 2 : return changed;
486 : : }
487 : :
488 : : static gint
489 : 0 : param_unichar_values_cmp (GParamSpec *pspec,
490 : : const GValue *value1,
491 : : const GValue *value2)
492 : : {
493 : 0 : if (value1->data[0].v_uint < value2->data[0].v_uint)
494 : 0 : return -1;
495 : : else
496 : 0 : return value1->data[0].v_uint > value2->data[0].v_uint;
497 : : }
498 : :
499 : : static void
500 : 1642 : param_enum_init (GParamSpec *pspec)
501 : : {
502 : 1642 : GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
503 : :
504 : 1642 : espec->enum_class = NULL;
505 : 1642 : espec->default_value = 0;
506 : 1642 : }
507 : :
508 : : static void
509 : 0 : param_enum_finalize (GParamSpec *pspec)
510 : : {
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 : : {
516 : 0 : g_type_class_unref (espec->enum_class);
517 : 0 : espec->enum_class = NULL;
518 : : }
519 : :
520 : 0 : parent_class->finalize (pspec);
521 : 0 : }
522 : :
523 : : static void
524 : 670 : param_enum_set_default (GParamSpec *pspec,
525 : : GValue *value)
526 : : {
527 : 670 : value->data[0].v_long = G_PARAM_SPEC_ENUM (pspec)->default_value;
528 : 670 : }
529 : :
530 : : static gboolean
531 : 22285 : param_enum_is_valid (GParamSpec *pspec,
532 : : const GValue *value)
533 : : {
534 : 22285 : GParamSpecEnum *espec = G_PARAM_SPEC_ENUM (pspec);
535 : 22285 : glong oval = value->data[0].v_long;
536 : :
537 : 22285 : return g_enum_get_value (espec->enum_class, oval) != NULL;
538 : : }
539 : :
540 : : static gboolean
541 : 0 : param_enum_validate (GParamSpec *pspec,
542 : : GValue *value)
543 : : {
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 : : }
553 : :
554 : : static void
555 : 627 : param_flags_init (GParamSpec *pspec)
556 : : {
557 : 627 : GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
558 : :
559 : 627 : fspec->flags_class = NULL;
560 : 627 : fspec->default_value = 0;
561 : 627 : }
562 : :
563 : : static void
564 : 0 : param_flags_finalize (GParamSpec *pspec)
565 : : {
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 : : {
571 : 0 : g_type_class_unref (fspec->flags_class);
572 : 0 : fspec->flags_class = NULL;
573 : : }
574 : :
575 : 0 : parent_class->finalize (pspec);
576 : 0 : }
577 : :
578 : : static void
579 : 152 : param_flags_set_default (GParamSpec *pspec,
580 : : GValue *value)
581 : : {
582 : 152 : value->data[0].v_ulong = G_PARAM_SPEC_FLAGS (pspec)->default_value;
583 : 152 : }
584 : :
585 : : static gboolean
586 : 7069 : param_flags_is_valid (GParamSpec *pspec,
587 : : const GValue *value)
588 : : {
589 : 7069 : GParamSpecFlags *fspec = G_PARAM_SPEC_FLAGS (pspec);
590 : 7069 : gulong oval = value->data[0].v_ulong;
591 : :
592 : 7069 : return (oval & ~fspec->flags_class->mask) == 0;
593 : : }
594 : : static gboolean
595 : 0 : param_flags_validate (GParamSpec *pspec,
596 : : GValue *value)
597 : : {
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 : : else
604 : 0 : value->data[0].v_ulong = fspec->default_value;
605 : :
606 : 0 : return value->data[0].v_ulong != oval;
607 : : }
608 : :
609 : : static void
610 : 1 : param_float_init (GParamSpec *pspec)
611 : : {
612 : 1 : GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
613 : :
614 : 1 : fspec->minimum = -G_MAXFLOAT;
615 : 1 : fspec->maximum = G_MAXFLOAT;
616 : 1 : fspec->default_value = 0;
617 : 1 : fspec->epsilon = G_FLOAT_EPSILON;
618 : 1 : }
619 : :
620 : : static void
621 : 2 : param_float_set_default (GParamSpec *pspec,
622 : : GValue *value)
623 : : {
624 : 2 : value->data[0].v_float = G_PARAM_SPEC_FLOAT (pspec)->default_value;
625 : 2 : }
626 : :
627 : : static gboolean
628 : 1 : param_float_is_valid (GParamSpec *pspec,
629 : : const GValue *value)
630 : : {
631 : 1 : GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
632 : 1 : gfloat oval = value->data[0].v_float;
633 : :
634 : 1 : return fspec->minimum <= oval && oval <= fspec->maximum;
635 : : }
636 : :
637 : : static gboolean
638 : 1 : param_float_validate (GParamSpec *pspec,
639 : : GValue *value)
640 : : {
641 : 1 : GParamSpecFloat *fspec = G_PARAM_SPEC_FLOAT (pspec);
642 : 1 : gfloat oval = value->data[0].v_float;
643 : :
644 : 1 : value->data[0].v_float = CLAMP (value->data[0].v_float, fspec->minimum, fspec->maximum);
645 : :
646 : 1 : return value->data[0].v_float != oval;
647 : : }
648 : :
649 : : static gint
650 : 1 : param_float_values_cmp (GParamSpec *pspec,
651 : : const GValue *value1,
652 : : const GValue *value2)
653 : : {
654 : 1 : gfloat epsilon = G_PARAM_SPEC_FLOAT (pspec)->epsilon;
655 : :
656 : 1 : 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 : : else
659 : 1 : return value1->data[0].v_float - value2->data[0].v_float > epsilon;
660 : : }
661 : :
662 : : static void
663 : 17 : param_double_init (GParamSpec *pspec)
664 : : {
665 : 17 : GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
666 : :
667 : 17 : dspec->minimum = -G_MAXDOUBLE;
668 : 17 : dspec->maximum = G_MAXDOUBLE;
669 : 17 : dspec->default_value = 0;
670 : 17 : dspec->epsilon = G_DOUBLE_EPSILON;
671 : 17 : }
672 : :
673 : : static void
674 : 4 : param_double_set_default (GParamSpec *pspec,
675 : : GValue *value)
676 : : {
677 : 4 : value->data[0].v_double = G_PARAM_SPEC_DOUBLE (pspec)->default_value;
678 : 4 : }
679 : :
680 : : static gboolean
681 : 91 : param_double_is_valid (GParamSpec *pspec,
682 : : const GValue *value)
683 : : {
684 : 91 : GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
685 : 91 : gdouble oval = value->data[0].v_double;
686 : :
687 : 91 : return dspec->minimum <= oval && oval <= dspec->maximum;
688 : : }
689 : :
690 : : static gboolean
691 : 53 : param_double_validate (GParamSpec *pspec,
692 : : GValue *value)
693 : : {
694 : 53 : GParamSpecDouble *dspec = G_PARAM_SPEC_DOUBLE (pspec);
695 : 53 : gdouble oval = value->data[0].v_double;
696 : :
697 : 53 : value->data[0].v_double = CLAMP (value->data[0].v_double, dspec->minimum, dspec->maximum);
698 : :
699 : 53 : return value->data[0].v_double != oval;
700 : : }
701 : :
702 : : static gint
703 : 1 : param_double_values_cmp (GParamSpec *pspec,
704 : : const GValue *value1,
705 : : const GValue *value2)
706 : : {
707 : 1 : gdouble epsilon = G_PARAM_SPEC_DOUBLE (pspec)->epsilon;
708 : :
709 : 1 : 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 : : else
712 : 1 : return value1->data[0].v_double - value2->data[0].v_double > epsilon;
713 : : }
714 : :
715 : : static void
716 : 1413 : param_string_init (GParamSpec *pspec)
717 : : {
718 : 1413 : GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
719 : :
720 : 1413 : sspec->default_value = NULL;
721 : 1413 : sspec->cset_first = NULL;
722 : 1413 : sspec->cset_nth = NULL;
723 : 1413 : sspec->substitutor = '_';
724 : 1413 : sspec->null_fold_if_empty = FALSE;
725 : 1413 : sspec->ensure_non_null = FALSE;
726 : 1413 : }
727 : :
728 : : static void
729 : 1 : param_string_finalize (GParamSpec *pspec)
730 : : {
731 : 1 : GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
732 : 1 : GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING));
733 : :
734 : 1 : g_free (sspec->default_value);
735 : 1 : g_free (sspec->cset_first);
736 : 1 : g_free (sspec->cset_nth);
737 : 1 : sspec->default_value = NULL;
738 : 1 : sspec->cset_first = NULL;
739 : 1 : sspec->cset_nth = NULL;
740 : :
741 : 1 : parent_class->finalize (pspec);
742 : 1 : }
743 : :
744 : : static void
745 : 252 : param_string_set_default (GParamSpec *pspec,
746 : : GValue *value)
747 : : {
748 : 252 : value->data[0].v_pointer = g_strdup (G_PARAM_SPEC_STRING (pspec)->default_value);
749 : 252 : }
750 : :
751 : : static gboolean
752 : 16 : param_string_validate (GParamSpec *pspec,
753 : : GValue *value)
754 : : {
755 : 16 : GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
756 : 16 : gchar *string = value->data[0].v_pointer;
757 : 16 : guint n_changed = 0;
758 : :
759 : 16 : if (string && string[0])
760 : : {
761 : : gchar *s;
762 : :
763 : 9 : if (sspec->cset_first && !strchr (sspec->cset_first, string[0]))
764 : : {
765 : 4 : if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
766 : : {
767 : 1 : value->data[0].v_pointer = g_strdup (string);
768 : 1 : string = value->data[0].v_pointer;
769 : 1 : value->data[1].v_uint &= (unsigned) ~G_VALUE_NOCOPY_CONTENTS;
770 : : }
771 : 4 : string[0] = sspec->substitutor;
772 : 4 : n_changed++;
773 : : }
774 : 9 : if (sspec->cset_nth)
775 : 12 : for (s = string + 1; *s; s++)
776 : 8 : if (!strchr (sspec->cset_nth, *s))
777 : : {
778 : 8 : if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
779 : : {
780 : 1 : value->data[0].v_pointer = g_strdup (string);
781 : 1 : s = (gchar*) value->data[0].v_pointer + (s - string);
782 : 1 : string = value->data[0].v_pointer;
783 : 1 : value->data[1].v_uint &= (unsigned) ~G_VALUE_NOCOPY_CONTENTS;
784 : : }
785 : 8 : *s = sspec->substitutor;
786 : 8 : n_changed++;
787 : : }
788 : : }
789 : 16 : if (sspec->null_fold_if_empty && string && string[0] == 0)
790 : : {
791 : 4 : if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS))
792 : 3 : g_free (value->data[0].v_pointer);
793 : : else
794 : 1 : value->data[1].v_uint &= (unsigned) ~G_VALUE_NOCOPY_CONTENTS;
795 : 4 : value->data[0].v_pointer = NULL;
796 : 4 : n_changed++;
797 : 4 : string = value->data[0].v_pointer;
798 : : }
799 : 16 : if (sspec->ensure_non_null && !string)
800 : : {
801 : 2 : value->data[1].v_uint &= (unsigned) ~G_VALUE_NOCOPY_CONTENTS;
802 : 2 : value->data[0].v_pointer = g_strdup ("");
803 : 2 : n_changed++;
804 : 2 : string = value->data[0].v_pointer;
805 : : }
806 : :
807 : 16 : return (n_changed > 0);
808 : : }
809 : :
810 : : static gboolean
811 : 682474 : param_string_is_valid (GParamSpec *pspec,
812 : : const GValue *value)
813 : : {
814 : 682474 : GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
815 : 682474 : gboolean ret = TRUE;
816 : :
817 : 682474 : if (sspec->cset_first != NULL || sspec->cset_nth != NULL ||
818 : 682469 : sspec->ensure_non_null || sspec->null_fold_if_empty)
819 : : {
820 : 7 : GValue tmp_value = G_VALUE_INIT;
821 : :
822 : 7 : g_value_init (&tmp_value, G_VALUE_TYPE (value));
823 : 7 : g_value_copy (value, &tmp_value);
824 : :
825 : 7 : ret = !param_string_validate (pspec, &tmp_value);
826 : :
827 : 7 : g_value_unset (&tmp_value);
828 : : }
829 : :
830 : 682474 : return ret;
831 : : }
832 : :
833 : : static gint
834 : 19 : param_string_values_cmp (GParamSpec *pspec,
835 : : const GValue *value1,
836 : : const GValue *value2)
837 : : {
838 : 19 : if (!value1->data[0].v_pointer)
839 : 19 : 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 : : else
843 : 0 : return strcmp (value1->data[0].v_pointer, value2->data[0].v_pointer);
844 : : }
845 : :
846 : : static void
847 : 2 : param_param_init (GParamSpec *pspec)
848 : : {
849 : : /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
850 : 2 : }
851 : :
852 : : static void
853 : 0 : param_param_set_default (GParamSpec *pspec,
854 : : GValue *value)
855 : : {
856 : 0 : value->data[0].v_pointer = NULL;
857 : 0 : }
858 : :
859 : : static gboolean
860 : 2 : param_param_is_valid (GParamSpec *pspec,
861 : : const GValue *value)
862 : : {
863 : 2 : GParamSpec *param = value->data[0].v_pointer;
864 : :
865 : 2 : if (param == NULL)
866 : 1 : return FALSE;
867 : :
868 : 1 : return g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec));
869 : : }
870 : :
871 : : static gboolean
872 : 2 : param_param_validate (GParamSpec *pspec,
873 : : GValue *value)
874 : : {
875 : : /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
876 : 2 : GParamSpec *param = value->data[0].v_pointer;
877 : 2 : guint n_changed = 0;
878 : :
879 : 2 : if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec)))
880 : : {
881 : 0 : g_param_spec_unref (param);
882 : 0 : value->data[0].v_pointer = NULL;
883 : 0 : n_changed++;
884 : : }
885 : :
886 : 2 : return (n_changed > 0);
887 : : }
888 : :
889 : : static void
890 : 376 : param_boxed_init (GParamSpec *pspec)
891 : : {
892 : : /* GParamSpecBoxed *bspec = G_PARAM_SPEC_BOXED (pspec); */
893 : 376 : }
894 : :
895 : : static void
896 : 180 : param_boxed_set_default (GParamSpec *pspec,
897 : : GValue *value)
898 : : {
899 : 180 : value->data[0].v_pointer = NULL;
900 : 180 : }
901 : :
902 : : static gint
903 : 4 : param_boxed_values_cmp (GParamSpec *pspec,
904 : : const GValue *value1,
905 : : const GValue *value2)
906 : : {
907 : 4 : guint8 *p1 = value1->data[0].v_pointer;
908 : 4 : 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 : 4 : return p1 < p2 ? -1 : p1 > p2;
913 : : }
914 : :
915 : : static void
916 : 100 : param_pointer_init (GParamSpec *pspec)
917 : : {
918 : : /* GParamSpecPointer *spec = G_PARAM_SPEC_POINTER (pspec); */
919 : 100 : }
920 : :
921 : : static void
922 : 22 : param_pointer_set_default (GParamSpec *pspec,
923 : : GValue *value)
924 : : {
925 : 22 : value->data[0].v_pointer = NULL;
926 : 22 : }
927 : :
928 : : static gint
929 : 3 : param_pointer_values_cmp (GParamSpec *pspec,
930 : : const GValue *value1,
931 : : const GValue *value2)
932 : : {
933 : 3 : guint8 *p1 = value1->data[0].v_pointer;
934 : 3 : 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 : 3 : return p1 < p2 ? -1 : p1 > p2;
939 : : }
940 : :
941 : : static void
942 : 0 : param_value_array_init (GParamSpec *pspec)
943 : : {
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 : 0 : value_array_ensure_size (GValueArray *value_array,
952 : : guint fixed_n_elements)
953 : : {
954 : 0 : guint changed = 0;
955 : :
956 : 0 : if (fixed_n_elements)
957 : : {
958 : 0 : while (value_array->n_values < fixed_n_elements)
959 : : {
960 : 0 : g_value_array_append (value_array, NULL);
961 : 0 : changed++;
962 : : }
963 : 0 : while (value_array->n_values > fixed_n_elements)
964 : : {
965 : 0 : g_value_array_remove (value_array, value_array->n_values - 1);
966 : 0 : changed++;
967 : : }
968 : : }
969 : 0 : return changed;
970 : : }
971 : :
972 : : static void
973 : 0 : param_value_array_finalize (GParamSpec *pspec)
974 : : {
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 : : {
980 : 0 : g_param_spec_unref (aspec->element_spec);
981 : 0 : aspec->element_spec = NULL;
982 : : }
983 : :
984 : 0 : parent_class->finalize (pspec);
985 : 0 : }
986 : :
987 : : static void
988 : 0 : param_value_array_set_default (GParamSpec *pspec,
989 : : GValue *value)
990 : : {
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 : : {
998 : : /* g_value_reset (value); already done */
999 : 0 : value_array_ensure_size (value->data[0].v_pointer, aspec->fixed_n_elements);
1000 : : }
1001 : 0 : }
1002 : :
1003 : : static gboolean
1004 : 0 : param_value_array_validate (GParamSpec *pspec,
1005 : : GValue *value)
1006 : : {
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 : : {
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 : : {
1022 : 0 : GParamSpec *element_spec = aspec->element_spec;
1023 : : guint i;
1024 : :
1025 : 0 : for (i = 0; i < value_array->n_values; i++)
1026 : : {
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 : : {
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 : : }
1038 : : else
1039 : : {
1040 : : /* validate array value against element_spec */
1041 : 0 : n_changed += g_param_value_validate (element_spec, element) ? 1 : 0;
1042 : : }
1043 : : }
1044 : : }
1045 : : }
1046 : :
1047 : 0 : return (n_changed > 0);
1048 : : }
1049 : :
1050 : : static gint
1051 : 0 : param_value_array_values_cmp (GParamSpec *pspec,
1052 : : const GValue *value1,
1053 : : const GValue *value2)
1054 : : {
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 : : {
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 : : }
1071 : : else /* value_array1->n_values == value_array2->n_values */
1072 : : {
1073 : : guint i;
1074 : :
1075 : 0 : for (i = 0; i < value_array1->n_values; i++)
1076 : : {
1077 : 0 : GValue *element1 = value_array1->values + i;
1078 : 0 : GValue *element2 = value_array2->values + i;
1079 : : 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 : : }
1088 : 0 : return 0;
1089 : : }
1090 : : }
1091 : :
1092 : : static void
1093 : 2408 : param_object_init (GParamSpec *pspec)
1094 : : {
1095 : : /* GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); */
1096 : 2408 : }
1097 : :
1098 : : static void
1099 : 601 : param_object_set_default (GParamSpec *pspec,
1100 : : GValue *value)
1101 : : {
1102 : 601 : value->data[0].v_pointer = NULL;
1103 : 601 : }
1104 : :
1105 : : static gboolean
1106 : 44835 : param_object_is_valid (GParamSpec *pspec,
1107 : : const GValue *value)
1108 : : {
1109 : 44835 : GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
1110 : 44835 : GObject *object = value->data[0].v_pointer;
1111 : :
1112 : 76806 : return object &&
1113 : 31971 : g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec));
1114 : : }
1115 : :
1116 : : static gboolean
1117 : 12866 : param_object_validate (GParamSpec *pspec,
1118 : : GValue *value)
1119 : : {
1120 : 12866 : GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
1121 : 12866 : GObject *object = value->data[0].v_pointer;
1122 : 12866 : guint n_changed = 0;
1123 : :
1124 : 12866 : if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec)))
1125 : : {
1126 : 0 : g_object_unref (object);
1127 : 0 : value->data[0].v_pointer = NULL;
1128 : 0 : n_changed++;
1129 : : }
1130 : :
1131 : 12866 : return (n_changed > 0);
1132 : : }
1133 : :
1134 : : static gint
1135 : 9 : param_object_values_cmp (GParamSpec *pspec,
1136 : : const GValue *value1,
1137 : : const GValue *value2)
1138 : : {
1139 : 9 : guint8 *p1 = value1->data[0].v_pointer;
1140 : 9 : 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 : 9 : return p1 < p2 ? -1 : p1 > p2;
1145 : : }
1146 : :
1147 : : static void
1148 : 669 : param_override_init (GParamSpec *pspec)
1149 : : {
1150 : : /* GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec); */
1151 : 669 : }
1152 : :
1153 : : static void
1154 : 1 : param_override_finalize (GParamSpec *pspec)
1155 : : {
1156 : 1 : GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1157 : 1 : GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_OVERRIDE));
1158 : :
1159 : 1 : if (ospec->overridden)
1160 : : {
1161 : 1 : g_param_spec_unref (ospec->overridden);
1162 : 1 : ospec->overridden = NULL;
1163 : : }
1164 : :
1165 : 1 : parent_class->finalize (pspec);
1166 : 1 : }
1167 : :
1168 : : static void
1169 : 30 : param_override_set_default (GParamSpec *pspec,
1170 : : GValue *value)
1171 : : {
1172 : 30 : GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1173 : :
1174 : 30 : g_param_value_set_default (ospec->overridden, value);
1175 : 30 : }
1176 : :
1177 : : static gboolean
1178 : 4 : param_override_is_valid (GParamSpec *pspec,
1179 : : const GValue *value)
1180 : : {
1181 : 4 : GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1182 : :
1183 : 4 : return g_param_value_is_valid (ospec->overridden, value);
1184 : : }
1185 : :
1186 : : static gboolean
1187 : 8 : param_override_validate (GParamSpec *pspec,
1188 : : GValue *value)
1189 : : {
1190 : 8 : GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1191 : :
1192 : 8 : return g_param_value_validate (ospec->overridden, value);
1193 : : }
1194 : :
1195 : : static gint
1196 : 5 : param_override_values_cmp (GParamSpec *pspec,
1197 : : const GValue *value1,
1198 : : const GValue *value2)
1199 : : {
1200 : 5 : GParamSpecOverride *ospec = G_PARAM_SPEC_OVERRIDE (pspec);
1201 : :
1202 : 5 : return g_param_values_cmp (ospec->overridden, value1, value2);
1203 : : }
1204 : :
1205 : : static void
1206 : 8 : param_gtype_init (GParamSpec *pspec)
1207 : : {
1208 : 8 : }
1209 : :
1210 : : static void
1211 : 7 : param_gtype_set_default (GParamSpec *pspec,
1212 : : GValue *value)
1213 : : {
1214 : 7 : GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1215 : :
1216 : 7 : value->data[0].v_pointer = GTYPE_TO_POINTER (tspec->is_a_type);
1217 : 7 : }
1218 : :
1219 : : static gboolean
1220 : 34 : param_gtype_is_valid (GParamSpec *pspec,
1221 : : const GValue *value)
1222 : : {
1223 : 34 : GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1224 : 34 : GType gtype = GPOINTER_TO_TYPE (value->data[0].v_pointer);
1225 : :
1226 : 68 : return tspec->is_a_type == G_TYPE_NONE ||
1227 : 34 : g_type_is_a (gtype, tspec->is_a_type);
1228 : : }
1229 : :
1230 : : static gboolean
1231 : 2 : param_gtype_validate (GParamSpec *pspec,
1232 : : GValue *value)
1233 : : {
1234 : 2 : GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
1235 : 2 : GType gtype = GPOINTER_TO_TYPE (value->data[0].v_pointer);
1236 : 2 : guint n_changed = 0;
1237 : :
1238 : 2 : if (tspec->is_a_type != G_TYPE_NONE && !g_type_is_a (gtype, tspec->is_a_type))
1239 : : {
1240 : 1 : value->data[0].v_pointer = GTYPE_TO_POINTER (tspec->is_a_type);
1241 : 1 : n_changed++;
1242 : : }
1243 : :
1244 : 2 : return (n_changed > 0);
1245 : : }
1246 : :
1247 : : static gint
1248 : 3 : param_gtype_values_cmp (GParamSpec *pspec,
1249 : : const GValue *value1,
1250 : : const GValue *value2)
1251 : : {
1252 : 3 : GType p1 = GPOINTER_TO_TYPE (value1->data[0].v_pointer);
1253 : 3 : 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 : 3 : return p1 < p2 ? -1 : p1 > p2;
1258 : : }
1259 : :
1260 : : static void
1261 : 63 : param_variant_init (GParamSpec *pspec)
1262 : : {
1263 : 63 : GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1264 : :
1265 : 63 : vspec->type = NULL;
1266 : 63 : vspec->default_value = NULL;
1267 : 63 : }
1268 : :
1269 : : static void
1270 : 11 : param_variant_finalize (GParamSpec *pspec)
1271 : : {
1272 : 11 : GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1273 : 11 : GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_VARIANT));
1274 : :
1275 : 11 : if (vspec->default_value)
1276 : 1 : g_variant_unref (vspec->default_value);
1277 : 11 : g_variant_type_free (vspec->type);
1278 : :
1279 : 11 : parent_class->finalize (pspec);
1280 : 11 : }
1281 : :
1282 : : static void
1283 : 24 : param_variant_set_default (GParamSpec *pspec,
1284 : : GValue *value)
1285 : : {
1286 : 24 : value->data[0].v_pointer = G_PARAM_SPEC_VARIANT (pspec)->default_value;
1287 : 24 : value->data[1].v_uint |= G_VALUE_NOCOPY_CONTENTS;
1288 : 24 : }
1289 : :
1290 : : static gboolean
1291 : 218 : param_variant_is_valid (GParamSpec *pspec,
1292 : : const GValue *value)
1293 : : {
1294 : 218 : GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1295 : 218 : GVariant *variant = value->data[0].v_pointer;
1296 : :
1297 : 218 : if (variant == NULL)
1298 : 149 : return vspec->default_value == NULL;
1299 : : else
1300 : 69 : return g_variant_is_of_type (variant, vspec->type);
1301 : : }
1302 : :
1303 : : static gboolean
1304 : 2 : param_variant_validate (GParamSpec *pspec,
1305 : : GValue *value)
1306 : : {
1307 : 2 : GParamSpecVariant *vspec = G_PARAM_SPEC_VARIANT (pspec);
1308 : 2 : GVariant *variant = value->data[0].v_pointer;
1309 : :
1310 : 2 : if ((variant == NULL && vspec->default_value != NULL) ||
1311 : 2 : (variant != NULL && !g_variant_is_of_type (variant, vspec->type)))
1312 : : {
1313 : 1 : g_param_value_set_default (pspec, value);
1314 : 1 : return TRUE;
1315 : : }
1316 : :
1317 : 1 : return FALSE;
1318 : : }
1319 : :
1320 : : /* g_variant_compare() can only be used with scalar types. */
1321 : : static gboolean
1322 : 14 : variant_is_incomparable (GVariant *v)
1323 : : {
1324 : 14 : GVariantClass v_class = g_variant_classify (v);
1325 : :
1326 : 14 : return (v_class == G_VARIANT_CLASS_HANDLE ||
1327 : 14 : v_class == G_VARIANT_CLASS_VARIANT ||
1328 : 14 : v_class == G_VARIANT_CLASS_MAYBE||
1329 : 12 : v_class == G_VARIANT_CLASS_ARRAY ||
1330 : 28 : v_class == G_VARIANT_CLASS_TUPLE ||
1331 : : v_class == G_VARIANT_CLASS_DICT_ENTRY);
1332 : : }
1333 : :
1334 : : static gint
1335 : 16 : param_variant_values_cmp (GParamSpec *pspec,
1336 : : const GValue *value1,
1337 : : const GValue *value2)
1338 : : {
1339 : 16 : GVariant *v1 = value1->data[0].v_pointer;
1340 : 16 : GVariant *v2 = value2->data[0].v_pointer;
1341 : :
1342 : 16 : if (v1 == NULL && v2 == NULL)
1343 : 2 : return 0;
1344 : 14 : else if (v1 == NULL && v2 != NULL)
1345 : 2 : return -1;
1346 : 12 : else if (v1 != NULL && v2 == NULL)
1347 : 1 : return 1;
1348 : :
1349 : 19 : if (!g_variant_type_equal (g_variant_get_type (v1), g_variant_get_type (v2)) ||
1350 : 14 : variant_is_incomparable (v1) ||
1351 : 6 : variant_is_incomparable (v2))
1352 : 5 : return g_variant_equal (v1, v2) ? 0 : (v1 < v2 ? -1 : 1);
1353 : :
1354 : 6 : return g_variant_compare (v1, v2);
1355 : : }
1356 : :
1357 : : /* --- type initialization --- */
1358 : :
1359 : : #define set_is_valid_vfunc(type,func) { \
1360 : : GParamSpecClass *class = g_type_class_ref (type); \
1361 : : class->value_is_valid = func; \
1362 : : g_type_class_unref (class); \
1363 : : }
1364 : :
1365 : : GType *g_param_spec_types = NULL;
1366 : :
1367 : : void
1368 : 580 : _g_param_spec_types_init (void)
1369 : : {
1370 : 580 : const guint n_types = 23;
1371 : : GType type, *spec_types;
1372 : : #ifndef G_DISABLE_ASSERT
1373 : : GType *spec_types_bound;
1374 : : #endif
1375 : :
1376 : 580 : g_param_spec_types = g_new0 (GType, n_types);
1377 : 580 : spec_types = g_param_spec_types;
1378 : : #ifndef G_DISABLE_ASSERT
1379 : 580 : spec_types_bound = g_param_spec_types + n_types;
1380 : : #endif
1381 : :
1382 : : /* G_TYPE_PARAM_CHAR
1383 : : */
1384 : : {
1385 : 580 : const GParamSpecTypeInfo pspec_info = {
1386 : : sizeof (GParamSpecChar), /* instance_size */
1387 : : 16, /* n_preallocs */
1388 : : param_char_init, /* instance_init */
1389 : : G_TYPE_CHAR, /* value_type */
1390 : : NULL, /* finalize */
1391 : : param_char_set_default, /* value_set_default */
1392 : : param_char_validate, /* value_validate */
1393 : : param_int_values_cmp, /* values_cmp */
1394 : : };
1395 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamChar"), &pspec_info);
1396 : 580 : set_is_valid_vfunc (type, param_char_is_valid);
1397 : 580 : *spec_types++ = type;
1398 : 580 : g_assert (type == G_TYPE_PARAM_CHAR);
1399 : : }
1400 : :
1401 : : /* G_TYPE_PARAM_UCHAR
1402 : : */
1403 : : {
1404 : 580 : const GParamSpecTypeInfo pspec_info = {
1405 : : sizeof (GParamSpecUChar), /* instance_size */
1406 : : 16, /* n_preallocs */
1407 : : param_uchar_init, /* instance_init */
1408 : : G_TYPE_UCHAR, /* value_type */
1409 : : NULL, /* finalize */
1410 : : param_uchar_set_default, /* value_set_default */
1411 : : param_uchar_validate, /* value_validate */
1412 : : param_uint_values_cmp, /* values_cmp */
1413 : : };
1414 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamUChar"), &pspec_info);
1415 : 580 : set_is_valid_vfunc (type, param_uchar_is_valid);
1416 : 580 : *spec_types++ = type;
1417 : 580 : g_assert (type == G_TYPE_PARAM_UCHAR);
1418 : : }
1419 : :
1420 : : /* G_TYPE_PARAM_BOOLEAN
1421 : : */
1422 : : {
1423 : 580 : const GParamSpecTypeInfo pspec_info = {
1424 : : sizeof (GParamSpecBoolean), /* instance_size */
1425 : : 16, /* n_preallocs */
1426 : : NULL, /* instance_init */
1427 : : G_TYPE_BOOLEAN, /* value_type */
1428 : : NULL, /* finalize */
1429 : : param_boolean_set_default, /* value_set_default */
1430 : : param_boolean_validate, /* value_validate */
1431 : : param_int_values_cmp, /* values_cmp */
1432 : : };
1433 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamBoolean"), &pspec_info);
1434 : 580 : set_is_valid_vfunc (type, param_boolean_is_valid);
1435 : 580 : *spec_types++ = type;
1436 : 580 : g_assert (type == G_TYPE_PARAM_BOOLEAN);
1437 : : }
1438 : :
1439 : : /* G_TYPE_PARAM_INT
1440 : : */
1441 : : {
1442 : 580 : const GParamSpecTypeInfo pspec_info = {
1443 : : sizeof (GParamSpecInt), /* instance_size */
1444 : : 16, /* n_preallocs */
1445 : : param_int_init, /* instance_init */
1446 : : G_TYPE_INT, /* value_type */
1447 : : NULL, /* finalize */
1448 : : param_int_set_default, /* value_set_default */
1449 : : param_int_validate, /* value_validate */
1450 : : param_int_values_cmp, /* values_cmp */
1451 : : };
1452 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamInt"), &pspec_info);
1453 : 580 : set_is_valid_vfunc (type, param_int_is_valid);
1454 : 580 : *spec_types++ = type;
1455 : 580 : g_assert (type == G_TYPE_PARAM_INT);
1456 : : }
1457 : :
1458 : : /* G_TYPE_PARAM_UINT
1459 : : */
1460 : : {
1461 : 580 : const GParamSpecTypeInfo pspec_info = {
1462 : : sizeof (GParamSpecUInt), /* instance_size */
1463 : : 16, /* n_preallocs */
1464 : : param_uint_init, /* instance_init */
1465 : : G_TYPE_UINT, /* value_type */
1466 : : NULL, /* finalize */
1467 : : param_uint_set_default, /* value_set_default */
1468 : : param_uint_validate, /* value_validate */
1469 : : param_uint_values_cmp, /* values_cmp */
1470 : : };
1471 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamUInt"), &pspec_info);
1472 : 580 : set_is_valid_vfunc (type, param_uint_is_valid);
1473 : 580 : *spec_types++ = type;
1474 : 580 : g_assert (type == G_TYPE_PARAM_UINT);
1475 : : }
1476 : :
1477 : : /* G_TYPE_PARAM_LONG
1478 : : */
1479 : : {
1480 : 580 : const GParamSpecTypeInfo pspec_info = {
1481 : : sizeof (GParamSpecLong), /* instance_size */
1482 : : 16, /* n_preallocs */
1483 : : param_long_init, /* instance_init */
1484 : : G_TYPE_LONG, /* value_type */
1485 : : NULL, /* finalize */
1486 : : param_long_set_default, /* value_set_default */
1487 : : param_long_validate, /* value_validate */
1488 : : param_long_values_cmp, /* values_cmp */
1489 : : };
1490 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamLong"), &pspec_info);
1491 : 580 : set_is_valid_vfunc (type, param_long_is_valid);
1492 : 580 : *spec_types++ = type;
1493 : 580 : g_assert (type == G_TYPE_PARAM_LONG);
1494 : : }
1495 : :
1496 : : /* G_TYPE_PARAM_ULONG
1497 : : */
1498 : : {
1499 : 580 : const GParamSpecTypeInfo pspec_info = {
1500 : : sizeof (GParamSpecULong), /* instance_size */
1501 : : 16, /* n_preallocs */
1502 : : param_ulong_init, /* instance_init */
1503 : : G_TYPE_ULONG, /* value_type */
1504 : : NULL, /* finalize */
1505 : : param_ulong_set_default, /* value_set_default */
1506 : : param_ulong_validate, /* value_validate */
1507 : : param_ulong_values_cmp, /* values_cmp */
1508 : : };
1509 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamULong"), &pspec_info);
1510 : 580 : set_is_valid_vfunc (type, param_ulong_is_valid);
1511 : 580 : *spec_types++ = type;
1512 : 580 : g_assert (type == G_TYPE_PARAM_ULONG);
1513 : : }
1514 : :
1515 : : /* G_TYPE_PARAM_INT64
1516 : : */
1517 : : {
1518 : 580 : const GParamSpecTypeInfo pspec_info = {
1519 : : sizeof (GParamSpecInt64), /* instance_size */
1520 : : 16, /* n_preallocs */
1521 : : param_int64_init, /* instance_init */
1522 : : G_TYPE_INT64, /* value_type */
1523 : : NULL, /* finalize */
1524 : : param_int64_set_default, /* value_set_default */
1525 : : param_int64_validate, /* value_validate */
1526 : : param_int64_values_cmp, /* values_cmp */
1527 : : };
1528 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamInt64"), &pspec_info);
1529 : 580 : set_is_valid_vfunc (type, param_int64_is_valid);
1530 : 580 : *spec_types++ = type;
1531 : 580 : g_assert (type == G_TYPE_PARAM_INT64);
1532 : : }
1533 : :
1534 : : /* G_TYPE_PARAM_UINT64
1535 : : */
1536 : : {
1537 : 580 : const GParamSpecTypeInfo pspec_info = {
1538 : : sizeof (GParamSpecUInt64), /* instance_size */
1539 : : 16, /* n_preallocs */
1540 : : param_uint64_init, /* instance_init */
1541 : : G_TYPE_UINT64, /* value_type */
1542 : : NULL, /* finalize */
1543 : : param_uint64_set_default, /* value_set_default */
1544 : : param_uint64_validate, /* value_validate */
1545 : : param_uint64_values_cmp, /* values_cmp */
1546 : : };
1547 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamUInt64"), &pspec_info);
1548 : 580 : set_is_valid_vfunc (type, param_uint64_is_valid);
1549 : 580 : *spec_types++ = type;
1550 : 580 : g_assert (type == G_TYPE_PARAM_UINT64);
1551 : : }
1552 : :
1553 : : /* G_TYPE_PARAM_UNICHAR
1554 : : */
1555 : : {
1556 : 580 : const GParamSpecTypeInfo pspec_info = {
1557 : : sizeof (GParamSpecUnichar), /* instance_size */
1558 : : 16, /* n_preallocs */
1559 : : param_unichar_init, /* instance_init */
1560 : : G_TYPE_UINT, /* value_type */
1561 : : NULL, /* finalize */
1562 : : param_unichar_set_default, /* value_set_default */
1563 : : param_unichar_validate, /* value_validate */
1564 : : param_unichar_values_cmp, /* values_cmp */
1565 : : };
1566 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamUnichar"), &pspec_info);
1567 : 580 : set_is_valid_vfunc (type, param_unichar_is_valid);
1568 : 580 : *spec_types++ = type;
1569 : 580 : g_assert (type == G_TYPE_PARAM_UNICHAR);
1570 : : }
1571 : :
1572 : : /* G_TYPE_PARAM_ENUM
1573 : : */
1574 : : {
1575 : 580 : const GParamSpecTypeInfo pspec_info = {
1576 : : sizeof (GParamSpecEnum), /* instance_size */
1577 : : 16, /* n_preallocs */
1578 : : param_enum_init, /* instance_init */
1579 : : G_TYPE_ENUM, /* value_type */
1580 : : param_enum_finalize, /* finalize */
1581 : : param_enum_set_default, /* value_set_default */
1582 : : param_enum_validate, /* value_validate */
1583 : : param_long_values_cmp, /* values_cmp */
1584 : : };
1585 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamEnum"), &pspec_info);
1586 : 580 : set_is_valid_vfunc (type, param_enum_is_valid);
1587 : 580 : *spec_types++ = type;
1588 : 580 : g_assert (type == G_TYPE_PARAM_ENUM);
1589 : : }
1590 : :
1591 : : /* G_TYPE_PARAM_FLAGS
1592 : : */
1593 : : {
1594 : 580 : const GParamSpecTypeInfo pspec_info = {
1595 : : sizeof (GParamSpecFlags), /* instance_size */
1596 : : 16, /* n_preallocs */
1597 : : param_flags_init, /* instance_init */
1598 : : G_TYPE_FLAGS, /* value_type */
1599 : : param_flags_finalize, /* finalize */
1600 : : param_flags_set_default, /* value_set_default */
1601 : : param_flags_validate, /* value_validate */
1602 : : param_ulong_values_cmp, /* values_cmp */
1603 : : };
1604 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamFlags"), &pspec_info);
1605 : 580 : set_is_valid_vfunc (type, param_flags_is_valid);
1606 : 580 : *spec_types++ = type;
1607 : 580 : g_assert (type == G_TYPE_PARAM_FLAGS);
1608 : : }
1609 : :
1610 : : /* G_TYPE_PARAM_FLOAT
1611 : : */
1612 : : {
1613 : 580 : const GParamSpecTypeInfo pspec_info = {
1614 : : sizeof (GParamSpecFloat), /* instance_size */
1615 : : 16, /* n_preallocs */
1616 : : param_float_init, /* instance_init */
1617 : : G_TYPE_FLOAT, /* value_type */
1618 : : NULL, /* finalize */
1619 : : param_float_set_default, /* value_set_default */
1620 : : param_float_validate, /* value_validate */
1621 : : param_float_values_cmp, /* values_cmp */
1622 : : };
1623 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamFloat"), &pspec_info);
1624 : 580 : set_is_valid_vfunc (type, param_float_is_valid);
1625 : 580 : *spec_types++ = type;
1626 : 580 : g_assert (type == G_TYPE_PARAM_FLOAT);
1627 : : }
1628 : :
1629 : : /* G_TYPE_PARAM_DOUBLE
1630 : : */
1631 : : {
1632 : 580 : const GParamSpecTypeInfo pspec_info = {
1633 : : sizeof (GParamSpecDouble), /* instance_size */
1634 : : 16, /* n_preallocs */
1635 : : param_double_init, /* instance_init */
1636 : : G_TYPE_DOUBLE, /* value_type */
1637 : : NULL, /* finalize */
1638 : : param_double_set_default, /* value_set_default */
1639 : : param_double_validate, /* value_validate */
1640 : : param_double_values_cmp, /* values_cmp */
1641 : : };
1642 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamDouble"), &pspec_info);
1643 : 580 : set_is_valid_vfunc (type, param_double_is_valid);
1644 : 580 : *spec_types++ = type;
1645 : 580 : g_assert (type == G_TYPE_PARAM_DOUBLE);
1646 : : }
1647 : :
1648 : : /* G_TYPE_PARAM_STRING
1649 : : */
1650 : : {
1651 : 580 : const GParamSpecTypeInfo pspec_info = {
1652 : : sizeof (GParamSpecString), /* instance_size */
1653 : : 16, /* n_preallocs */
1654 : : param_string_init, /* instance_init */
1655 : : G_TYPE_STRING, /* value_type */
1656 : : param_string_finalize, /* finalize */
1657 : : param_string_set_default, /* value_set_default */
1658 : : param_string_validate, /* value_validate */
1659 : : param_string_values_cmp, /* values_cmp */
1660 : : };
1661 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamString"), &pspec_info);
1662 : 580 : set_is_valid_vfunc (type, param_string_is_valid);
1663 : 580 : *spec_types++ = type;
1664 : 580 : g_assert (type == G_TYPE_PARAM_STRING);
1665 : : }
1666 : :
1667 : : /* G_TYPE_PARAM_PARAM
1668 : : */
1669 : : {
1670 : 580 : const GParamSpecTypeInfo pspec_info = {
1671 : : sizeof (GParamSpecParam), /* instance_size */
1672 : : 16, /* n_preallocs */
1673 : : param_param_init, /* instance_init */
1674 : : G_TYPE_PARAM, /* value_type */
1675 : : NULL, /* finalize */
1676 : : param_param_set_default, /* value_set_default */
1677 : : param_param_validate, /* value_validate */
1678 : : param_pointer_values_cmp, /* values_cmp */
1679 : : };
1680 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamParam"), &pspec_info);
1681 : 580 : set_is_valid_vfunc (type, param_param_is_valid);
1682 : 580 : *spec_types++ = type;
1683 : 580 : g_assert (type == G_TYPE_PARAM_PARAM);
1684 : : }
1685 : :
1686 : : /* G_TYPE_PARAM_BOXED
1687 : : */
1688 : : {
1689 : 580 : const GParamSpecTypeInfo pspec_info = {
1690 : : sizeof (GParamSpecBoxed), /* instance_size */
1691 : : 4, /* n_preallocs */
1692 : : param_boxed_init, /* instance_init */
1693 : : G_TYPE_BOXED, /* value_type */
1694 : : NULL, /* finalize */
1695 : : param_boxed_set_default, /* value_set_default */
1696 : : NULL, /* value_validate */
1697 : : param_boxed_values_cmp, /* values_cmp */
1698 : : };
1699 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamBoxed"), &pspec_info);
1700 : 580 : *spec_types++ = type;
1701 : 580 : g_assert (type == G_TYPE_PARAM_BOXED);
1702 : : }
1703 : :
1704 : : /* G_TYPE_PARAM_POINTER
1705 : : */
1706 : : {
1707 : 580 : const GParamSpecTypeInfo pspec_info = {
1708 : : sizeof (GParamSpecPointer), /* instance_size */
1709 : : 0, /* n_preallocs */
1710 : : param_pointer_init, /* instance_init */
1711 : : G_TYPE_POINTER, /* value_type */
1712 : : NULL, /* finalize */
1713 : : param_pointer_set_default, /* value_set_default */
1714 : : NULL,
1715 : : param_pointer_values_cmp, /* values_cmp */
1716 : : };
1717 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamPointer"), &pspec_info);
1718 : 580 : *spec_types++ = type;
1719 : 580 : g_assert (type == G_TYPE_PARAM_POINTER);
1720 : : }
1721 : :
1722 : : /* G_TYPE_PARAM_VALUE_ARRAY
1723 : : */
1724 : : {
1725 : 580 : /* const */ GParamSpecTypeInfo pspec_info = {
1726 : : sizeof (GParamSpecValueArray), /* instance_size */
1727 : : 0, /* n_preallocs */
1728 : : param_value_array_init, /* instance_init */
1729 : : 0xdeadbeef, /* value_type, assigned further down */
1730 : : param_value_array_finalize, /* finalize */
1731 : : param_value_array_set_default, /* value_set_default */
1732 : : param_value_array_validate, /* value_validate */
1733 : : param_value_array_values_cmp, /* values_cmp */
1734 : : };
1735 : 580 : pspec_info.value_type = G_TYPE_VALUE_ARRAY;
1736 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamValueArray"), &pspec_info);
1737 : 580 : *spec_types++ = type;
1738 : 580 : g_assert (type == G_TYPE_PARAM_VALUE_ARRAY);
1739 : : }
1740 : :
1741 : : /* G_TYPE_PARAM_OBJECT
1742 : : */
1743 : : {
1744 : 580 : const GParamSpecTypeInfo pspec_info = {
1745 : : sizeof (GParamSpecObject), /* instance_size */
1746 : : 16, /* n_preallocs */
1747 : : param_object_init, /* instance_init */
1748 : : G_TYPE_OBJECT, /* value_type */
1749 : : NULL, /* finalize */
1750 : : param_object_set_default, /* value_set_default */
1751 : : param_object_validate, /* value_validate */
1752 : : param_object_values_cmp, /* values_cmp */
1753 : : };
1754 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamObject"), &pspec_info);
1755 : 580 : set_is_valid_vfunc (type, param_object_is_valid);
1756 : 580 : *spec_types++ = type;
1757 : 580 : g_assert (type == G_TYPE_PARAM_OBJECT);
1758 : : }
1759 : :
1760 : : /* G_TYPE_PARAM_OVERRIDE
1761 : : */
1762 : : {
1763 : 580 : const GParamSpecTypeInfo pspec_info = {
1764 : : sizeof (GParamSpecOverride), /* instance_size */
1765 : : 16, /* n_preallocs */
1766 : : param_override_init, /* instance_init */
1767 : : G_TYPE_NONE, /* value_type */
1768 : : param_override_finalize, /* finalize */
1769 : : param_override_set_default, /* value_set_default */
1770 : : param_override_validate, /* value_validate */
1771 : : param_override_values_cmp, /* values_cmp */
1772 : : };
1773 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamOverride"), &pspec_info);
1774 : 580 : set_is_valid_vfunc (type, param_override_is_valid);
1775 : 580 : *spec_types++ = type;
1776 : 580 : g_assert (type == G_TYPE_PARAM_OVERRIDE);
1777 : : }
1778 : :
1779 : : /* G_TYPE_PARAM_GTYPE
1780 : : */
1781 : : {
1782 : 580 : GParamSpecTypeInfo pspec_info = {
1783 : : sizeof (GParamSpecGType), /* instance_size */
1784 : : 0, /* n_preallocs */
1785 : : param_gtype_init, /* instance_init */
1786 : : 0xdeadbeef, /* value_type, assigned further down */
1787 : : NULL, /* finalize */
1788 : : param_gtype_set_default, /* value_set_default */
1789 : : param_gtype_validate, /* value_validate */
1790 : : param_gtype_values_cmp, /* values_cmp */
1791 : : };
1792 : 580 : pspec_info.value_type = G_TYPE_GTYPE;
1793 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamGType"), &pspec_info);
1794 : 580 : set_is_valid_vfunc (type, param_gtype_is_valid);
1795 : 580 : *spec_types++ = type;
1796 : 580 : g_assert (type == G_TYPE_PARAM_GTYPE);
1797 : : }
1798 : :
1799 : : /* G_TYPE_PARAM_VARIANT
1800 : : */
1801 : : {
1802 : 580 : const GParamSpecTypeInfo pspec_info = {
1803 : : sizeof (GParamSpecVariant), /* instance_size */
1804 : : 0, /* n_preallocs */
1805 : : param_variant_init, /* instance_init */
1806 : : G_TYPE_VARIANT, /* value_type */
1807 : : param_variant_finalize, /* finalize */
1808 : : param_variant_set_default, /* value_set_default */
1809 : : param_variant_validate, /* value_validate */
1810 : : param_variant_values_cmp, /* values_cmp */
1811 : : };
1812 : 580 : type = g_param_type_register_static (g_intern_static_string ("GParamVariant"), &pspec_info);
1813 : 580 : set_is_valid_vfunc (type, param_variant_is_valid);
1814 : 580 : *spec_types++ = type;
1815 : 580 : g_assert (type == G_TYPE_PARAM_VARIANT);
1816 : : }
1817 : :
1818 : 580 : g_assert (spec_types == spec_types_bound);
1819 : 580 : }
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 : 6 : 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 : : {
1846 : : GParamSpecChar *cspec;
1847 : :
1848 : 6 : g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1849 : :
1850 : 6 : cspec = g_param_spec_internal (G_TYPE_PARAM_CHAR,
1851 : : name,
1852 : : nick,
1853 : : blurb,
1854 : : flags);
1855 : :
1856 : 6 : cspec->minimum = minimum;
1857 : 6 : cspec->maximum = maximum;
1858 : 6 : cspec->default_value = default_value;
1859 : :
1860 : 6 : return G_PARAM_SPEC (cspec);
1861 : : }
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 : 4 : 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 : : {
1886 : : GParamSpecUChar *uspec;
1887 : :
1888 : 4 : g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1889 : :
1890 : 4 : uspec = g_param_spec_internal (G_TYPE_PARAM_UCHAR,
1891 : : name,
1892 : : nick,
1893 : : blurb,
1894 : : flags);
1895 : :
1896 : 4 : uspec->minimum = minimum;
1897 : 4 : uspec->maximum = maximum;
1898 : 4 : uspec->default_value = default_value;
1899 : :
1900 : 4 : return G_PARAM_SPEC (uspec);
1901 : : }
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 : 2517 : g_param_spec_boolean (const gchar *name,
1923 : : const gchar *nick,
1924 : : const gchar *blurb,
1925 : : gboolean default_value,
1926 : : GParamFlags flags)
1927 : : {
1928 : : GParamSpecBoolean *bspec;
1929 : :
1930 : 2517 : g_return_val_if_fail (default_value == TRUE || default_value == FALSE, NULL);
1931 : :
1932 : 2517 : bspec = g_param_spec_internal (G_TYPE_PARAM_BOOLEAN,
1933 : : name,
1934 : : nick,
1935 : : blurb,
1936 : : flags);
1937 : :
1938 : 2517 : bspec->default_value = default_value;
1939 : :
1940 : 2517 : return G_PARAM_SPEC (bspec);
1941 : : }
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 : 623 : 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 : : {
1968 : : GParamSpecInt *ispec;
1969 : :
1970 : 623 : g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
1971 : :
1972 : 623 : ispec = g_param_spec_internal (G_TYPE_PARAM_INT,
1973 : : name,
1974 : : nick,
1975 : : blurb,
1976 : : flags);
1977 : :
1978 : 623 : ispec->minimum = minimum;
1979 : 623 : ispec->maximum = maximum;
1980 : 623 : ispec->default_value = default_value;
1981 : :
1982 : 623 : return G_PARAM_SPEC (ispec);
1983 : : }
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 : 876 : 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 : : {
2010 : : GParamSpecUInt *uspec;
2011 : :
2012 : 876 : g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2013 : :
2014 : 876 : uspec = g_param_spec_internal (G_TYPE_PARAM_UINT,
2015 : : name,
2016 : : nick,
2017 : : blurb,
2018 : : flags);
2019 : :
2020 : 876 : uspec->minimum = minimum;
2021 : 876 : uspec->maximum = maximum;
2022 : 876 : uspec->default_value = default_value;
2023 : :
2024 : 876 : return G_PARAM_SPEC (uspec);
2025 : : }
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 : 3 : 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 : : {
2052 : : GParamSpecLong *lspec;
2053 : :
2054 : 3 : g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2055 : :
2056 : 3 : lspec = g_param_spec_internal (G_TYPE_PARAM_LONG,
2057 : : name,
2058 : : nick,
2059 : : blurb,
2060 : : flags);
2061 : :
2062 : 3 : lspec->minimum = minimum;
2063 : 3 : lspec->maximum = maximum;
2064 : 3 : lspec->default_value = default_value;
2065 : :
2066 : 3 : return G_PARAM_SPEC (lspec);
2067 : : }
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 : 31 : 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 : : {
2095 : : GParamSpecULong *uspec;
2096 : :
2097 : 31 : g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2098 : :
2099 : 31 : uspec = g_param_spec_internal (G_TYPE_PARAM_ULONG,
2100 : : name,
2101 : : nick,
2102 : : blurb,
2103 : : flags);
2104 : :
2105 : 31 : uspec->minimum = minimum;
2106 : 31 : uspec->maximum = maximum;
2107 : 31 : uspec->default_value = default_value;
2108 : :
2109 : 31 : return G_PARAM_SPEC (uspec);
2110 : : }
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 : 8 : 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 : : {
2137 : : GParamSpecInt64 *lspec;
2138 : :
2139 : 8 : g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2140 : :
2141 : 8 : lspec = g_param_spec_internal (G_TYPE_PARAM_INT64,
2142 : : name,
2143 : : nick,
2144 : : blurb,
2145 : : flags);
2146 : :
2147 : 8 : lspec->minimum = minimum;
2148 : 8 : lspec->maximum = maximum;
2149 : 8 : lspec->default_value = default_value;
2150 : :
2151 : 8 : return G_PARAM_SPEC (lspec);
2152 : : }
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 : 8 : 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 : : {
2180 : : GParamSpecUInt64 *uspec;
2181 : :
2182 : 8 : g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2183 : :
2184 : 8 : uspec = g_param_spec_internal (G_TYPE_PARAM_UINT64,
2185 : : name,
2186 : : nick,
2187 : : blurb,
2188 : : flags);
2189 : :
2190 : 8 : uspec->minimum = minimum;
2191 : 8 : uspec->maximum = maximum;
2192 : 8 : uspec->default_value = default_value;
2193 : :
2194 : 8 : return G_PARAM_SPEC (uspec);
2195 : : }
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 : 1 : g_param_spec_unichar (const gchar *name,
2215 : : const gchar *nick,
2216 : : const gchar *blurb,
2217 : : gunichar default_value,
2218 : : GParamFlags flags)
2219 : : {
2220 : : GParamSpecUnichar *uspec;
2221 : :
2222 : 1 : uspec = g_param_spec_internal (G_TYPE_PARAM_UNICHAR,
2223 : : name,
2224 : : nick,
2225 : : blurb,
2226 : : flags);
2227 : :
2228 : 1 : uspec->default_value = default_value;
2229 : :
2230 : 1 : return G_PARAM_SPEC (uspec);
2231 : : }
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 : 1642 : 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 : : {
2257 : : GParamSpecEnum *espec;
2258 : : GEnumClass *enum_class;
2259 : :
2260 : 1642 : g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
2261 : :
2262 : 1642 : enum_class = g_type_class_ref (enum_type);
2263 : :
2264 : 1642 : g_return_val_if_fail (g_enum_get_value (enum_class, default_value) != NULL, NULL);
2265 : :
2266 : 1642 : espec = g_param_spec_internal (G_TYPE_PARAM_ENUM,
2267 : : name,
2268 : : nick,
2269 : : blurb,
2270 : : flags);
2271 : :
2272 : 1642 : espec->enum_class = enum_class;
2273 : 1642 : espec->default_value = default_value;
2274 : 1642 : G_PARAM_SPEC (espec)->value_type = enum_type;
2275 : :
2276 : 1642 : return G_PARAM_SPEC (espec);
2277 : : }
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 : 627 : 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 : : {
2303 : : GParamSpecFlags *fspec;
2304 : : GFlagsClass *flags_class;
2305 : :
2306 : 627 : g_return_val_if_fail (G_TYPE_IS_FLAGS (flags_type), NULL);
2307 : :
2308 : 627 : flags_class = g_type_class_ref (flags_type);
2309 : :
2310 : 627 : g_return_val_if_fail ((default_value & flags_class->mask) == default_value, NULL);
2311 : :
2312 : 627 : fspec = g_param_spec_internal (G_TYPE_PARAM_FLAGS,
2313 : : name,
2314 : : nick,
2315 : : blurb,
2316 : : flags);
2317 : :
2318 : 627 : fspec->flags_class = flags_class;
2319 : 627 : fspec->default_value = default_value;
2320 : 627 : G_PARAM_SPEC (fspec)->value_type = flags_type;
2321 : :
2322 : 627 : return G_PARAM_SPEC (fspec);
2323 : : }
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 : 1 : 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 : : {
2350 : : GParamSpecFloat *fspec;
2351 : :
2352 : 1 : g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2353 : :
2354 : 1 : fspec = g_param_spec_internal (G_TYPE_PARAM_FLOAT,
2355 : : name,
2356 : : nick,
2357 : : blurb,
2358 : : flags);
2359 : :
2360 : 1 : fspec->minimum = minimum;
2361 : 1 : fspec->maximum = maximum;
2362 : 1 : fspec->default_value = default_value;
2363 : :
2364 : 1 : return G_PARAM_SPEC (fspec);
2365 : : }
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 : 17 : 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 : : {
2393 : : GParamSpecDouble *dspec;
2394 : :
2395 : 17 : g_return_val_if_fail (default_value >= minimum && default_value <= maximum, NULL);
2396 : :
2397 : 17 : dspec = g_param_spec_internal (G_TYPE_PARAM_DOUBLE,
2398 : : name,
2399 : : nick,
2400 : : blurb,
2401 : : flags);
2402 : :
2403 : 17 : dspec->minimum = minimum;
2404 : 17 : dspec->maximum = maximum;
2405 : 17 : dspec->default_value = default_value;
2406 : :
2407 : 17 : return G_PARAM_SPEC (dspec);
2408 : : }
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 : 1413 : g_param_spec_string (const gchar *name,
2426 : : const gchar *nick,
2427 : : const gchar *blurb,
2428 : : const gchar *default_value,
2429 : : GParamFlags flags)
2430 : : {
2431 : 1413 : GParamSpecString *sspec = g_param_spec_internal (G_TYPE_PARAM_STRING,
2432 : : name,
2433 : : nick,
2434 : : blurb,
2435 : : flags);
2436 : :
2437 : 1413 : g_free (sspec->default_value);
2438 : 1413 : sspec->default_value = g_strdup (default_value);
2439 : :
2440 : 1413 : return G_PARAM_SPEC (sspec);
2441 : : }
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 : 2 : g_param_spec_param (const gchar *name,
2460 : : const gchar *nick,
2461 : : const gchar *blurb,
2462 : : GType param_type,
2463 : : GParamFlags flags)
2464 : : {
2465 : : GParamSpecParam *pspec;
2466 : :
2467 : 2 : g_return_val_if_fail (G_TYPE_IS_PARAM (param_type), NULL);
2468 : :
2469 : 2 : pspec = g_param_spec_internal (G_TYPE_PARAM_PARAM,
2470 : : name,
2471 : : nick,
2472 : : blurb,
2473 : : flags);
2474 : :
2475 : 2 : G_PARAM_SPEC (pspec)->value_type = param_type;
2476 : :
2477 : 2 : return G_PARAM_SPEC (pspec);
2478 : : }
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 : 376 : g_param_spec_boxed (const gchar *name,
2497 : : const gchar *nick,
2498 : : const gchar *blurb,
2499 : : GType boxed_type,
2500 : : GParamFlags flags)
2501 : : {
2502 : : GParamSpecBoxed *bspec;
2503 : :
2504 : 376 : g_return_val_if_fail (G_TYPE_IS_BOXED (boxed_type), NULL);
2505 : 376 : g_return_val_if_fail (G_TYPE_IS_VALUE_TYPE (boxed_type), NULL);
2506 : :
2507 : 376 : bspec = g_param_spec_internal (G_TYPE_PARAM_BOXED,
2508 : : name,
2509 : : nick,
2510 : : blurb,
2511 : : flags);
2512 : :
2513 : 376 : G_PARAM_SPEC (bspec)->value_type = boxed_type;
2514 : :
2515 : 376 : return G_PARAM_SPEC (bspec);
2516 : : }
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 : 100 : g_param_spec_pointer (const gchar *name,
2535 : : const gchar *nick,
2536 : : const gchar *blurb,
2537 : : GParamFlags flags)
2538 : : {
2539 : : GParamSpecPointer *pspec;
2540 : :
2541 : 100 : pspec = g_param_spec_internal (G_TYPE_PARAM_POINTER,
2542 : : name,
2543 : : nick,
2544 : : blurb,
2545 : : flags);
2546 : :
2547 : 100 : return G_PARAM_SPEC (pspec);
2548 : : }
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 : 8 : g_param_spec_gtype (const gchar *name,
2570 : : const gchar *nick,
2571 : : const gchar *blurb,
2572 : : GType is_a_type,
2573 : : GParamFlags flags)
2574 : : {
2575 : : GParamSpecGType *tspec;
2576 : :
2577 : 8 : tspec = g_param_spec_internal (G_TYPE_PARAM_GTYPE,
2578 : : name,
2579 : : nick,
2580 : : blurb,
2581 : : flags);
2582 : :
2583 : 8 : tspec->is_a_type = is_a_type;
2584 : :
2585 : 8 : return G_PARAM_SPEC (tspec);
2586 : : }
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 : 0 : g_param_spec_value_array (const gchar *name,
2608 : : const gchar *nick,
2609 : : const gchar *blurb,
2610 : : GParamSpec *element_spec,
2611 : : GParamFlags flags)
2612 : : {
2613 : : 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 : : name,
2619 : : nick,
2620 : : blurb,
2621 : : flags);
2622 : :
2623 : 0 : if (element_spec)
2624 : : {
2625 : 0 : aspec->element_spec = g_param_spec_ref (element_spec);
2626 : 0 : g_param_spec_sink (element_spec);
2627 : : }
2628 : :
2629 : 0 : return G_PARAM_SPEC (aspec);
2630 : : }
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 : 2408 : g_param_spec_object (const gchar *name,
2649 : : const gchar *nick,
2650 : : const gchar *blurb,
2651 : : GType object_type,
2652 : : GParamFlags flags)
2653 : : {
2654 : : GParamSpecObject *ospec;
2655 : :
2656 : 2408 : g_return_val_if_fail (g_type_is_a (object_type, G_TYPE_OBJECT), NULL);
2657 : :
2658 : 2408 : ospec = g_param_spec_internal (G_TYPE_PARAM_OBJECT,
2659 : : name,
2660 : : nick,
2661 : : blurb,
2662 : : flags);
2663 : :
2664 : 2408 : G_PARAM_SPEC (ospec)->value_type = object_type;
2665 : :
2666 : 2408 : return G_PARAM_SPEC (ospec);
2667 : : }
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 : 669 : g_param_spec_override (const gchar *name,
2684 : : GParamSpec *overridden)
2685 : : {
2686 : : GParamSpec *pspec;
2687 : :
2688 : 669 : g_return_val_if_fail (name != NULL, NULL);
2689 : 669 : g_return_val_if_fail (G_IS_PARAM_SPEC (overridden), NULL);
2690 : :
2691 : : /* Dereference further redirections for property that was passed in
2692 : : */
2693 : : while (TRUE)
2694 : 133 : {
2695 : 802 : GParamSpec *indirect = g_param_spec_get_redirect_target (overridden);
2696 : 802 : if (indirect)
2697 : 133 : overridden = indirect;
2698 : : else
2699 : 669 : break;
2700 : : }
2701 : :
2702 : 669 : pspec = g_param_spec_internal (G_TYPE_PARAM_OVERRIDE,
2703 : : name, NULL, NULL,
2704 : : overridden->flags);
2705 : :
2706 : 669 : pspec->value_type = G_PARAM_SPEC_VALUE_TYPE (overridden);
2707 : 669 : G_PARAM_SPEC_OVERRIDE (pspec)->overridden = g_param_spec_ref (overridden);
2708 : :
2709 : 669 : return pspec;
2710 : : }
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 : 63 : 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 : : {
2741 : : GParamSpecVariant *vspec;
2742 : :
2743 : 63 : g_return_val_if_fail (type != NULL, NULL);
2744 : 63 : g_return_val_if_fail (default_value == NULL ||
2745 : : g_variant_is_of_type (default_value, type), NULL);
2746 : :
2747 : 63 : vspec = g_param_spec_internal (G_TYPE_PARAM_VARIANT,
2748 : : name,
2749 : : nick,
2750 : : blurb,
2751 : : flags);
2752 : :
2753 : 63 : vspec->type = g_variant_type_copy (type);
2754 : 63 : if (default_value)
2755 : 1 : vspec->default_value = g_variant_ref_sink (default_value);
2756 : :
2757 : 63 : return G_PARAM_SPEC (vspec);
2758 : : }
|