Coverage Report

Created: 2025-06-13 06:55

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