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.
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.
18 <!-- ##### SECTION See_Also ##### -->
20 g_object_class_install_property(), g_object_set(), g_object_get(),
21 g_object_set_property(), g_object_get_property(), g_value_register_transform_func()
24 <!-- ##### SECTION Stability_Level ##### -->
27 <!-- ##### MACRO G_TYPE_IS_PARAM ##### -->
29 Returns whether @type "is a" %G_TYPE_PARAM.
35 <!-- ##### MACRO G_PARAM_SPEC ##### -->
37 Casts a derived #GParamSpec object (e.g. of type #GParamSpecInt) into
41 @pspec: a valid #GParamSpec
44 <!-- ##### MACRO G_IS_PARAM_SPEC ##### -->
46 Checks whether @pspec "is a" valid #GParamSpec structure of type %G_TYPE_PARAM
53 <!-- ##### MACRO G_PARAM_SPEC_CLASS ##### -->
55 Casts a derived #GParamSpecClass structure into a #GParamSpecClass structure.
58 @pclass: a valid #GParamSpecClass
61 <!-- ##### MACRO G_IS_PARAM_SPEC_CLASS ##### -->
63 Checks whether @pclass "is a" valid #GParamSpecClass structure of type
64 %G_TYPE_PARAM or derived.
67 @pclass: a #GParamSpecClass
70 <!-- ##### MACRO G_PARAM_SPEC_GET_CLASS ##### -->
72 Retrieves the #GParamSpecClass of a #GParamSpec.
75 @pspec: a valid #GParamSpec
78 <!-- ##### MACRO G_PARAM_SPEC_TYPE ##### -->
80 Retrieves the #GType of this @pspec.
83 @pspec: a valid #GParamSpec
86 <!-- ##### MACRO G_PARAM_SPEC_TYPE_NAME ##### -->
88 Retrieves the #GType name of this @pspec.
91 @pspec: a valid #GParamSpec
94 <!-- ##### MACRO G_PARAM_SPEC_VALUE_TYPE ##### -->
96 Retrieves the #GType to initialize a #GValue for this parameter.
99 @pspec: a valid #GParamSpec
102 <!-- ##### STRUCT GParamSpec ##### -->
104 All fields of the <structname>GParamSpec</structname> struct are private and
105 should not be used directly, except for the following:
108 @g_type_instance: private #GTypeInstance portion
109 @name: name of this parameter
110 @flags: #GParamFlags flags for this parameter
111 @value_type: the #GValue type for this parameter
112 @owner_type: #GType type that uses (introduces) this paremeter
114 <!-- ##### STRUCT GParamSpecClass ##### -->
116 The class structure for the <structname>GParamSpec</structname> type.
117 Normally, <structname>GParamSpec</structname> classes are filled by
118 g_param_type_register_static().
121 @g_type_class: the parent class
122 @value_type: the #GValue type for this parameter
123 @finalize: The instance finalization function (optional), should chain
124 up to the finalize method of the parent class.
125 @value_set_default: Resets a @value to the default value for this type
126 (recommended, the default is g_value_reset()), see
127 g_param_value_set_default().
128 @value_validate: Ensures that the contents of @value comply with the
129 specifications set out by this type (optional), see
130 g_param_value_set_validate().
131 @values_cmp: Compares @value1 with @value2 according to this type
132 (recommended, the default is memcmp()), see g_param_values_cmp().
134 <!-- ##### ENUM GParamFlags ##### -->
136 Through the #GParamFlags flag values, certain aspects of parameters
140 @G_PARAM_READABLE: the parameter is readable
141 @G_PARAM_WRITABLE: the parameter is writable
142 @G_PARAM_CONSTRUCT: the parameter will be set upon object construction
143 @G_PARAM_CONSTRUCT_ONLY: the parameter will only be set upon object construction
144 @G_PARAM_LAX_VALIDATION: upon parameter conversion (see g_param_value_convert())
145 strict validation is not required
146 @G_PARAM_STATIC_NAME: the string used as name when constructing the
147 parameter is guaranteed to remain valid and
148 unmodified for the lifetime of the parameter.
150 @G_PARAM_STATIC_BLURB: the string used as blurb when constructing the
151 parameter is guaranteed to remain valid and
152 unmodified for the lifetime of the parameter.
155 <!-- ##### MACRO G_PARAM_READWRITE ##### -->
157 #GParamFlags value alias for %G_PARAM_READABLE | %G_PARAM_WRITABLE.
162 <!-- ##### MACRO G_PARAM_MASK ##### -->
164 Mask containing the bits of #GParamSpec.flags which are reserved for GLib.
169 <!-- ##### MACRO G_PARAM_USER_SHIFT ##### -->
171 Minimum shift count to be used for user defined flags, to be stored in
177 <!-- ##### FUNCTION g_param_spec_ref ##### -->
179 Increments the reference count of @pspec.
182 @pspec: a valid #GParamSpec
183 @Returns: the #GParamSpec that was passed into this function
186 <!-- ##### FUNCTION g_param_spec_unref ##### -->
188 Decrements the reference count of a @pspec.
191 @pspec: a valid #GParamSpec
194 <!-- ##### FUNCTION g_param_spec_sink ##### -->
196 The initial reference count of a newly created #GParamSpec is 1, even
197 though no one has explicitly called g_param_spec_ref() on it yet. So the
198 initial reference count is flagged as "floating", until someone calls
199 <literal>g_param_spec_ref (pspec); g_param_spec_sink (pspec);</literal>
200 in sequence on it, taking over the initial reference count (thus
201 ending up with a @pspec that has a reference count of 1 still, but is
202 not flagged "floating" anymore).
205 @pspec: a valid #GParamSpec
208 <!-- ##### FUNCTION g_param_value_set_default ##### -->
210 Sets @value to its default value as specified in @pspec.
213 @pspec: a valid #GParamSpec
214 @value: a #GValue of correct type for @pspec
217 <!-- ##### FUNCTION g_param_value_defaults ##### -->
219 Checks whether @value contains the default value as specified in @pspec.
222 @pspec: a valid #GParamSpec
223 @value: a #GValue of correct type for @pspec
224 @Returns: whether @value contains the canonical defualt for this @pspec
227 <!-- ##### FUNCTION g_param_value_validate ##### -->
229 Ensures that the contents of @value comply with the specifications
230 set out by @pspec. For example, a #GParamSpecInt might require
231 that integers stored in @value may not be smaller than -42 and not be
232 greater than +42. If @value contains an integer outside of this range,
233 it is modified accordingly, so the resulting value will fit into the
237 @pspec: a valid #GParamSpec
238 @value: a #GValue of correct type for @pspec
239 @Returns: whether modifying @value was necessary to ensure validity
242 <!-- ##### FUNCTION g_param_value_convert ##### -->
244 Transforms @src_value into @dest_value if possible, and then validates
245 @dest_value, in order for it to conform to @pspec.
246 If @strict_validation is %TRUE this function will only succeed if
247 the transformed @dest_value complied to @pspec without modifications.
249 See also g_value_type_transformable(), g_value_transform() and
250 g_param_value_validate().
253 @pspec: a valid #GParamSpec
254 @src_value: souce #GValue
255 @dest_value: destination #GValue of correct type for @pspec
256 @strict_validation: %TRUE requires @dest_value to conform to @pspec without modifications
257 @Returns: %TRUE if transformation and validation were successful,
258 %FALSE otherwise and @dest_value is left untouched.
261 <!-- ##### FUNCTION g_param_values_cmp ##### -->
263 Compares @value1 with @value2 according to @pspec, and return -1, 0 or +1,
264 if @value1 is found to be less than, equal to or greater than @value2,
268 @pspec: a valid #GParamSpec
269 @value1: a #GValue of correct type for @pspec
270 @value2: a #GValue of correct type for @pspec
271 @Returns: -1, 0 or +1, for a less than, equal to or greater than result
274 <!-- ##### FUNCTION g_param_spec_get_name ##### -->
276 Returns the name of a #GParamSpec.
279 @pspec: a valid #GParamSpec
280 @Returns: the name of @pspec.
283 <!-- ##### FUNCTION g_param_spec_get_nick ##### -->
285 Returns the nickname of a #GParamSpec.
288 @pspec: a valid #GParamSpec
289 @Returns: the nickname of @pspec.
292 <!-- ##### FUNCTION g_param_spec_get_blurb ##### -->
294 Returns the short description of a #GParamSpec.
297 @pspec: a valid #GParamSpec
298 @Returns: the short description of @pspec.
301 <!-- ##### FUNCTION g_param_spec_get_qdata ##### -->
303 Gets back user data pointers stored via g_param_spec_set_qdata().
306 @pspec: a valid #GParamSpec
307 @quark: a #GQuark, naming the user data pointer
308 @Returns: the user data pointer set, or %NULL
311 <!-- ##### FUNCTION g_param_spec_set_qdata ##### -->
313 Sets an opaque, named pointer on a #GParamSpec. The name is specified
314 through a #GQuark (retrieved e.g. via g_quark_from_static_string()), and
315 the pointer can be gotten back from the @pspec with g_param_spec_get_qdata().
316 Setting a previously set user data pointer, overrides (frees)
317 the old pointer set, using %NULL as pointer essentially
318 removes the data stored.
321 @pspec: the #GParamSpec to set store a user data pointer
322 @quark: a #GQuark, naming the user data pointer
323 @data: an opaque user data pointer
326 <!-- ##### FUNCTION g_param_spec_set_qdata_full ##### -->
328 This function works like g_param_spec_set_qdata(), but in addition,
329 a <literal>void (*destroy) (gpointer)</literal> function may be
330 specified which is called with @data as argument when the @pspec is
331 finalized, or the data is being overwritten by a call to
332 g_param_spec_set_qdata() with the same @quark.
335 @pspec: the #GParamSpec to set store a user data pointer
336 @quark: a #GQuark, naming the user data pointer
337 @data: an opaque user data pointer
338 @destroy: function to invoke with @data as argument, when @data needs to
342 <!-- ##### FUNCTION g_param_spec_steal_qdata ##### -->
344 Gets back user data pointers stored via g_param_spec_set_qdata() and
345 removes the @data from @pspec without invoking it's destroy() function
347 Usually, calling this function is only required to update
348 user data pointers with a destroy notifier.
351 @pspec: the #GParamSpec to get a stored user data pointer from
352 @quark: a #GQuark, naming the user data pointer
353 @Returns: the user data pointer set, or %NULL
356 <!-- ##### FUNCTION g_param_spec_get_redirect_target ##### -->
358 If the paramspec redirects operations to another paramspec,
359 returns that paramspec. Redirect is used typically for
360 providing a new implementation of a property in a derived
361 type while preserving all the properties from the parent
362 type. Redirection is established by creating a property
363 of type #GParamSpecOverride. See g_object_override_property()
364 for an example of the use of this capability.
367 @pspec: a #GParamSpec
368 @Returns: paramspec to which requests on this paramspec should
369 be redirected, or %NULL if none.
373 <!-- ##### FUNCTION g_param_spec_internal ##### -->
375 Creates a new #GParamSpec instance.
378 A property name consists of segments consisting of ASCII letters and
379 digits, separated by either the '-' or '_' character. The first
380 character of a property name must be a letter. Names which violate these
381 rules lead to undefined behaviour.
384 When creating and looking up a #GParamSpec, either separator can be used,
385 but they cannot be mixed. Using '-' is considerably more efficient and in
386 fact required when using property names as detail strings for signals.
389 @param_type: the #GType for the property; must be derived from #G_TYPE_PARAM
390 @name: the canonical name of the property
391 @nick: the nickname of the property
392 @blurb: a short description of the property
393 @flags: a combination of #GParamFlags
394 @Returns: a newly allocated #GParamSpec instance
397 <!-- ##### STRUCT GParamSpecTypeInfo ##### -->
399 This structure is used to provide the type system with the information
400 required to initialize and destruct (finalize) a parameter's class and
402 The initialized structure is passed to the g_param_type_register_static()
403 The type system will perform a deep copy of this structure, so it's memory
404 does not need to be persistent across invocation of
405 g_param_type_register_static().
408 @instance_size: Size of the instance (object) structure.
409 @n_preallocs: Number of pre-allocated (cached) instances to reserve memory for (0 indicates no caching).
410 @instance_init: Location of the instance initialization function (optional).
411 @value_type: The #GType of values conforming to this #GParamSpec
412 @finalize: The instance finalization function (optional).
413 @value_set_default: Resets a @value to the default value for @pspec
414 (recommended, the default is g_value_reset()), see
415 g_param_value_set_default().
416 @value_validate: Ensures that the contents of @value comply with the
417 specifications set out by @pspec (optional), see
418 g_param_value_set_validate().
419 @values_cmp: Compares @value1 with @value2 according to @pspec
420 (recommended, the default is memcmp()), see g_param_values_cmp().
423 <!-- ##### FUNCTION g_param_type_register_static ##### -->
425 Registers @name as the name of a new static type derived from
426 #G_TYPE_PARAM. The type system uses the information contained in the
427 #GParamSpecTypeInfo structure pointed to by @info to manage the #GParamSpec
428 type and its instances.
431 @name: 0-terminated string used as the name of the new #GParamSpec type.
432 @pspec_info: The #GParamSpecTypeInfo for this #GParamSpec type.
433 @Returns: The new type identifier.
436 <!-- ##### STRUCT GParamSpecPool ##### -->
438 A #GParamSpecPool maintains a collection of #GParamSpec<!-- -->s which can be
439 quickly accessed by owner and name. The implementation of the #GObject property
440 system uses such a pool to store the #GParamSpecs of the properties all object
445 <!-- ##### FUNCTION g_param_spec_pool_new ##### -->
447 Creates a new #GParamSpecPool.
450 If @type_prefixing is %TRUE, lookups in the newly created pool will
451 allow to specify the owner as a colon-separated prefix of the property name,
452 like "GtkContainer:border-width". This feature is deprecated, so you should
453 always set @type_prefixing to %FALSE.
456 @type_prefixing: Whether the pool will support type-prefixed property names.
457 @Returns: a newly allocated #GParamSpecPool.
460 <!-- ##### FUNCTION g_param_spec_pool_insert ##### -->
462 Inserts a #GParamSpec in the pool.
465 @pool: a #GParamSpecPool.
466 @pspec: the #GParamSpec to insert
467 @owner_type: a #GType identifying the owner of @pspec
470 <!-- ##### FUNCTION g_param_spec_pool_remove ##### -->
472 Removes a #GParamSpec from the pool.
475 @pool: a #GParamSpecPool
476 @pspec: the #GParamSpec to remove
479 <!-- ##### FUNCTION g_param_spec_pool_lookup ##### -->
481 Looks up a #GParamSpec in the pool.
484 @pool: a #GParamSpecPool
485 @param_name: the name to look for
486 @owner_type: the owner to look for
487 @walk_ancestors: If %TRUE, also try to find a #GParamSpec with @param_name
488 owned by an ancestor of @owner_type.
489 @Returns: The found #GParamSpec, or %NULL if no matching #GParamSpec was found.
492 <!-- ##### FUNCTION g_param_spec_pool_list ##### -->
494 Gets an array of all #GParamSpec<!-- -->s owned by @owner_type in the pool.
497 @pool: a #GParamSpecPool
498 @owner_type: the owner to look for
499 @n_pspecs_p: return location for the length of the returned array
500 @Returns: a newly allocated array containing pointers to all
501 #GParamSpec<!-- -->s owned by @owner_type in the pool
504 <!-- ##### FUNCTION g_param_spec_pool_list_owned ##### -->
506 Gets an #GList of all #GParamSpec<!-- -->s owned by @owner_type in the pool.
509 @pool: a #GParamSpecPool
510 @owner_type: the owner to look for
511 @Returns: a #GList of all #GParamSpec<!-- -->s owned by @owner_type in
512 the pool#GParamSpec<!-- -->s.