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