1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 Metadata for parameter specifications
7 <!-- ##### SECTION Long_Description ##### -->
9 #GParamSpec is an object structure that encapsulates the metadata
10 required to specify parameters, such as e.g. #GObject properties.
12 <para id="canonical-parameter-name">
13 Parameter names need to start with a letter (a-z or A-Z). Subsequent
14 characters can be letters, numbers or a '-'.
15 All other characters are replaced by a '-' during construction.
16 The result of this replacement is called the canonical name of the
20 <!-- ##### SECTION See_Also ##### -->
22 g_object_class_install_property(), g_object_set(), g_object_get(),
23 g_object_set_property(), g_object_get_property(), g_value_register_transform_func()
26 <!-- ##### SECTION Stability_Level ##### -->
29 <!-- ##### MACRO G_TYPE_IS_PARAM ##### -->
31 Returns whether @type "is a" %G_TYPE_PARAM.
37 <!-- ##### MACRO G_PARAM_SPEC ##### -->
39 Casts a derived #GParamSpec object (e.g. of type #GParamSpecInt) into
43 @pspec: a valid #GParamSpec
46 <!-- ##### MACRO G_IS_PARAM_SPEC ##### -->
48 Checks whether @pspec "is a" valid #GParamSpec structure of type %G_TYPE_PARAM
55 <!-- ##### MACRO G_PARAM_SPEC_CLASS ##### -->
57 Casts a derived #GParamSpecClass structure into a #GParamSpecClass structure.
60 @pclass: a valid #GParamSpecClass
63 <!-- ##### MACRO G_IS_PARAM_SPEC_CLASS ##### -->
65 Checks whether @pclass "is a" valid #GParamSpecClass structure of type
66 %G_TYPE_PARAM or derived.
69 @pclass: a #GParamSpecClass
72 <!-- ##### MACRO G_PARAM_SPEC_GET_CLASS ##### -->
74 Retrieves the #GParamSpecClass of a #GParamSpec.
77 @pspec: a valid #GParamSpec
80 <!-- ##### MACRO G_PARAM_SPEC_TYPE ##### -->
82 Retrieves the #GType of this @pspec.
85 @pspec: a valid #GParamSpec
88 <!-- ##### MACRO G_PARAM_SPEC_TYPE_NAME ##### -->
90 Retrieves the #GType name of this @pspec.
93 @pspec: a valid #GParamSpec
96 <!-- ##### MACRO G_PARAM_SPEC_VALUE_TYPE ##### -->
98 Retrieves the #GType to initialize a #GValue for this parameter.
101 @pspec: a valid #GParamSpec
104 <!-- ##### STRUCT GParamSpec ##### -->
106 All fields of the <structname>GParamSpec</structname> struct are private and
107 should not be used directly, except for the following:
110 @g_type_instance: private #GTypeInstance portion
111 @name: name of this parameter
112 @flags: #GParamFlags flags for this parameter
113 @value_type: the #GValue type for this parameter
114 @owner_type: #GType type that uses (introduces) this paremeter
116 <!-- ##### STRUCT GParamSpecClass ##### -->
118 The class structure for the <structname>GParamSpec</structname> type.
119 Normally, <structname>GParamSpec</structname> classes are filled by
120 g_param_type_register_static().
123 @g_type_class: the parent class
124 @value_type: the #GValue type for this parameter
125 @finalize: The instance finalization function (optional), should chain
126 up to the finalize method of the parent class.
127 @value_set_default: Resets a @value to the default value for this type
128 (recommended, the default is g_value_reset()), see
129 g_param_value_set_default().
130 @value_validate: Ensures that the contents of @value comply with the
131 specifications set out by this type (optional), see
132 g_param_value_set_validate().
133 @values_cmp: Compares @value1 with @value2 according to this type
134 (recommended, the default is memcmp()), see g_param_values_cmp().
136 <!-- ##### ENUM GParamFlags ##### -->
138 Through the #GParamFlags flag values, certain aspects of parameters
142 @G_PARAM_READABLE: the parameter is readable
143 @G_PARAM_WRITABLE: the parameter is writable
144 @G_PARAM_CONSTRUCT: the parameter will be set upon object construction
145 @G_PARAM_CONSTRUCT_ONLY: the parameter will only be set upon object construction
146 @G_PARAM_LAX_VALIDATION: upon parameter conversion (see g_param_value_convert())
147 strict validation is not required
148 @G_PARAM_STATIC_NAME: the string used as name when constructing the
149 parameter is guaranteed to remain valid and
150 unmodified for the lifetime of the parameter.
153 @G_PARAM_STATIC_NICK: the string used as nick when constructing the
154 parameter is guaranteed to remain valid and
155 unmmodified for the lifetime of the parameter.
157 @G_PARAM_STATIC_BLURB: the string used as blurb when constructing the
158 parameter is guaranteed to remain valid and
159 unmodified for the lifetime of the parameter.
162 <!-- ##### MACRO G_PARAM_READWRITE ##### -->
164 #GParamFlags value alias for %G_PARAM_READABLE | %G_PARAM_WRITABLE.
169 <!-- ##### MACRO G_PARAM_STATIC_STRINGS ##### -->
171 #GParamFlags value alias for %G_PARAM_STATIC_NAME | %G_PARAM_STATIC_NICK | %G_PARAM_STATIC_BLURB.
178 <!-- ##### MACRO G_PARAM_MASK ##### -->
180 Mask containing the bits of #GParamSpec.flags which are reserved for GLib.
185 <!-- ##### MACRO G_PARAM_USER_SHIFT ##### -->
187 Minimum shift count to be used for user defined flags, to be stored in
193 <!-- ##### FUNCTION g_param_spec_ref ##### -->
195 Increments the reference count of @pspec.
198 @pspec: a valid #GParamSpec
199 @Returns: the #GParamSpec that was passed into this function
202 <!-- ##### FUNCTION g_param_spec_unref ##### -->
204 Decrements the reference count of a @pspec.
207 @pspec: a valid #GParamSpec
210 <!-- ##### FUNCTION g_param_spec_sink ##### -->
212 The initial reference count of a newly created #GParamSpec is 1, even
213 though no one has explicitly called g_param_spec_ref() on it yet. So the
214 initial reference count is flagged as "floating", until someone calls
215 <literal>g_param_spec_ref (pspec); g_param_spec_sink (pspec);</literal>
216 in sequence on it, taking over the initial reference count (thus
217 ending up with a @pspec that has a reference count of 1 still, but is
218 not flagged "floating" anymore).
221 @pspec: a valid #GParamSpec
224 <!-- ##### FUNCTION g_param_spec_ref_sink ##### -->
226 Convenience function to ref and sink a #GParamSpec.
229 @pspec: a valid #GParamSpec
230 @Returns: the #GParamSpec that was passed into this function
234 <!-- ##### FUNCTION g_param_value_set_default ##### -->
236 Sets @value to its default value as specified in @pspec.
239 @pspec: a valid #GParamSpec
240 @value: a #GValue of correct type for @pspec
243 <!-- ##### FUNCTION g_param_value_defaults ##### -->
245 Checks whether @value contains the default value as specified in @pspec.
248 @pspec: a valid #GParamSpec
249 @value: a #GValue of correct type for @pspec
250 @Returns: whether @value contains the canonical default for this @pspec
253 <!-- ##### FUNCTION g_param_value_validate ##### -->
255 Ensures that the contents of @value comply with the specifications
256 set out by @pspec. For example, a #GParamSpecInt might require
257 that integers stored in @value may not be smaller than -42 and not be
258 greater than +42. If @value contains an integer outside of this range,
259 it is modified accordingly, so the resulting value will fit into the
263 @pspec: a valid #GParamSpec
264 @value: a #GValue of correct type for @pspec
265 @Returns: whether modifying @value was necessary to ensure validity
268 <!-- ##### FUNCTION g_param_value_convert ##### -->
270 Transforms @src_value into @dest_value if possible, and then validates
271 @dest_value, in order for it to conform to @pspec.
272 If @strict_validation is %TRUE this function will only succeed if
273 the transformed @dest_value complied to @pspec without modifications.
275 See also g_value_type_transformable(), g_value_transform() and
276 g_param_value_validate().
279 @pspec: a valid #GParamSpec
280 @src_value: souce #GValue
281 @dest_value: destination #GValue of correct type for @pspec
282 @strict_validation: %TRUE requires @dest_value to conform to @pspec without modifications
283 @Returns: %TRUE if transformation and validation were successful,
284 %FALSE otherwise and @dest_value is left untouched.
287 <!-- ##### FUNCTION g_param_values_cmp ##### -->
289 Compares @value1 with @value2 according to @pspec, and return -1, 0 or +1,
290 if @value1 is found to be less than, equal to or greater than @value2,
294 @pspec: a valid #GParamSpec
295 @value1: a #GValue of correct type for @pspec
296 @value2: a #GValue of correct type for @pspec
297 @Returns: -1, 0 or +1, for a less than, equal to or greater than result
300 <!-- ##### FUNCTION g_param_spec_get_name ##### -->
302 Returns the name of a #GParamSpec.
305 @pspec: a valid #GParamSpec
306 @Returns: the name of @pspec.
309 <!-- ##### FUNCTION g_param_spec_get_nick ##### -->
311 Returns the nickname of a #GParamSpec.
314 @pspec: a valid #GParamSpec
315 @Returns: the nickname of @pspec.
318 <!-- ##### FUNCTION g_param_spec_get_blurb ##### -->
320 Returns the short description of a #GParamSpec.
323 @pspec: a valid #GParamSpec
324 @Returns: the short description of @pspec.
327 <!-- ##### FUNCTION g_param_spec_get_qdata ##### -->
329 Gets back user data pointers stored via g_param_spec_set_qdata().
332 @pspec: a valid #GParamSpec
333 @quark: a #GQuark, naming the user data pointer
334 @Returns: the user data pointer set, or %NULL
337 <!-- ##### FUNCTION g_param_spec_set_qdata ##### -->
339 Sets an opaque, named pointer on a #GParamSpec. The name is specified
340 through a #GQuark (retrieved e.g. via g_quark_from_static_string()), and
341 the pointer can be gotten back from the @pspec with g_param_spec_get_qdata().
342 Setting a previously set user data pointer, overrides (frees)
343 the old pointer set, using %NULL as pointer essentially
344 removes the data stored.
347 @pspec: the #GParamSpec to set store a user data pointer
348 @quark: a #GQuark, naming the user data pointer
349 @data: an opaque user data pointer
352 <!-- ##### FUNCTION g_param_spec_set_qdata_full ##### -->
354 This function works like g_param_spec_set_qdata(), but in addition,
355 a <literal>void (*destroy) (gpointer)</literal> function may be
356 specified which is called with @data as argument when the @pspec is
357 finalized, or the data is being overwritten by a call to
358 g_param_spec_set_qdata() with the same @quark.
361 @pspec: the #GParamSpec to set store a user data pointer
362 @quark: a #GQuark, naming the user data pointer
363 @data: an opaque user data pointer
364 @destroy: function to invoke with @data as argument, when @data needs to
368 <!-- ##### FUNCTION g_param_spec_steal_qdata ##### -->
370 Gets back user data pointers stored via g_param_spec_set_qdata() and
371 removes the @data from @pspec without invoking it's destroy() function
373 Usually, calling this function is only required to update
374 user data pointers with a destroy notifier.
377 @pspec: the #GParamSpec to get a stored user data pointer from
378 @quark: a #GQuark, naming the user data pointer
379 @Returns: the user data pointer set, or %NULL
382 <!-- ##### FUNCTION g_param_spec_get_redirect_target ##### -->
384 If the paramspec redirects operations to another paramspec,
385 returns that paramspec. Redirect is used typically for
386 providing a new implementation of a property in a derived
387 type while preserving all the properties from the parent
388 type. Redirection is established by creating a property
389 of type #GParamSpecOverride. See g_object_class_override_property()
390 for an example of the use of this capability.
393 @pspec: a #GParamSpec
394 @Returns: paramspec to which requests on this paramspec should
395 be redirected, or %NULL if none.
399 <!-- ##### FUNCTION g_param_spec_internal ##### -->
401 Creates a new #GParamSpec instance.
404 A property name consists of segments consisting of ASCII letters and
405 digits, separated by either the '-' or '_' character. The first
406 character of a property name must be a letter. Names which violate these
407 rules lead to undefined behaviour.
410 When creating and looking up a #GParamSpec, either separator can be used,
411 but they cannot be mixed. Using '-' is considerably more efficient and in
412 fact required when using property names as detail strings for signals.
415 Beyond the name, #GParamSpec<!-- -->s have two more descriptive strings
416 associated with them, the @nick, which should be suitable for use as
417 a label for the property in a property editor, and the @blurb, which should
418 be a somewhat longer description, suitable for e.g. a tooltip. The @nick
419 and @blurb should ideally be localized.
422 @param_type: the #GType for the property; must be derived from #G_TYPE_PARAM
423 @name: the canonical name of the property
424 @nick: the nickname of the property
425 @blurb: a short description of the property
426 @flags: a combination of #GParamFlags
427 @Returns: a newly allocated #GParamSpec instance
430 <!-- ##### STRUCT GParamSpecTypeInfo ##### -->
432 This structure is used to provide the type system with the information
433 required to initialize and destruct (finalize) a parameter's class and
435 The initialized structure is passed to the g_param_type_register_static()
436 The type system will perform a deep copy of this structure, so it's memory
437 does not need to be persistent across invocation of
438 g_param_type_register_static().
441 @instance_size: Size of the instance (object) structure.
442 @n_preallocs: Prior to GLib 2.10, it specified the number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching). Since GLib 2.10, it is ignored, since instances are allocated with the <link linkend="glib-Memory-Slices">slice allocator</link> now.
443 @instance_init: Location of the instance initialization function (optional).
444 @value_type: The #GType of values conforming to this #GParamSpec
445 @finalize: The instance finalization function (optional).
446 @value_set_default: Resets a @value to the default value for @pspec
447 (recommended, the default is g_value_reset()), see
448 g_param_value_set_default().
449 @value_validate: Ensures that the contents of @value comply with the
450 specifications set out by @pspec (optional), see
451 g_param_value_set_validate().
452 @values_cmp: Compares @value1 with @value2 according to @pspec
453 (recommended, the default is memcmp()), see g_param_values_cmp().
455 <!-- ##### FUNCTION g_param_type_register_static ##### -->
457 Registers @name as the name of a new static type derived from
458 #G_TYPE_PARAM. The type system uses the information contained in the
459 #GParamSpecTypeInfo structure pointed to by @info to manage the #GParamSpec
460 type and its instances.
463 @name: 0-terminated string used as the name of the new #GParamSpec type.
464 @pspec_info: The #GParamSpecTypeInfo for this #GParamSpec type.
465 @Returns: The new type identifier.
468 <!-- ##### STRUCT GParamSpecPool ##### -->
470 A #GParamSpecPool maintains a collection of #GParamSpec<!-- -->s which can be
471 quickly accessed by owner and name. The implementation of the #GObject property
472 system uses such a pool to store the #GParamSpecs of the properties all object
477 <!-- ##### FUNCTION g_param_spec_pool_new ##### -->
479 Creates a new #GParamSpecPool.
482 If @type_prefixing is %TRUE, lookups in the newly created pool will
483 allow to specify the owner as a colon-separated prefix of the property name,
484 like "GtkContainer:border-width". This feature is deprecated, so you should
485 always set @type_prefixing to %FALSE.
488 @type_prefixing: Whether the pool will support type-prefixed property names.
489 @Returns: a newly allocated #GParamSpecPool.
492 <!-- ##### FUNCTION g_param_spec_pool_insert ##### -->
494 Inserts a #GParamSpec in the pool.
497 @pool: a #GParamSpecPool.
498 @pspec: the #GParamSpec to insert
499 @owner_type: a #GType identifying the owner of @pspec
502 <!-- ##### FUNCTION g_param_spec_pool_remove ##### -->
504 Removes a #GParamSpec from the pool.
507 @pool: a #GParamSpecPool
508 @pspec: the #GParamSpec to remove
511 <!-- ##### FUNCTION g_param_spec_pool_lookup ##### -->
513 Looks up a #GParamSpec in the pool.
516 @pool: a #GParamSpecPool
517 @param_name: the name to look for
518 @owner_type: the owner to look for
519 @walk_ancestors: If %TRUE, also try to find a #GParamSpec with @param_name
520 owned by an ancestor of @owner_type.
521 @Returns: The found #GParamSpec, or %NULL if no matching #GParamSpec was found.
524 <!-- ##### FUNCTION g_param_spec_pool_list ##### -->
526 Gets an array of all #GParamSpec<!-- -->s owned by @owner_type in the pool.
529 @pool: a #GParamSpecPool
530 @owner_type: the owner to look for
531 @n_pspecs_p: return location for the length of the returned array
532 @Returns: a newly allocated array containing pointers to all
533 #GParamSpec<!-- -->s owned by @owner_type in the pool
536 <!-- ##### FUNCTION g_param_spec_pool_list_owned ##### -->
538 Gets an #GList of all #GParamSpec<!-- -->s owned by @owner_type in the pool.
541 @pool: a #GParamSpecPool
542 @owner_type: the owner to look for
543 @Returns: a #GList of all #GParamSpec<!-- -->s owned by @owner_type in
544 the pool#GParamSpec<!-- -->s.