2.14.0
[platform/upstream/glib.git] / docs / reference / gobject / tmpl / gparamspec.sgml
1 <!-- ##### SECTION Title ##### -->
2 GParamSpec
3
4 <!-- ##### SECTION Short_Description ##### -->
5 Metadata for parameter specifications
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 #GParamSpec is an object structure that encapsulates the metadata
10 required to specify parameters, such as e.g. #GObject properties.
11 </para>
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
17 parameter.
18 </para>
19
20 <!-- ##### SECTION See_Also ##### -->
21 <para>
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()
24 </para>
25
26 <!-- ##### SECTION Stability_Level ##### -->
27
28
29 <!-- ##### MACRO G_TYPE_IS_PARAM ##### -->
30 <para>
31 Returns whether @type "is a" %G_TYPE_PARAM.
32 </para>
33
34 @type: a #GType ID
35
36
37 <!-- ##### MACRO G_PARAM_SPEC ##### -->
38 <para>
39 Casts a derived #GParamSpec object (e.g. of type #GParamSpecInt) into
40 a #GParamSpec object.
41 </para>
42
43 @pspec: a valid #GParamSpec
44
45
46 <!-- ##### MACRO G_IS_PARAM_SPEC ##### -->
47 <para>
48 Checks whether @pspec "is a" valid #GParamSpec structure of type %G_TYPE_PARAM
49 or derived.
50 </para>
51
52 @pspec: a #GParamSpec
53
54
55 <!-- ##### MACRO G_PARAM_SPEC_CLASS ##### -->
56 <para>
57 Casts a derived #GParamSpecClass structure into a #GParamSpecClass structure.
58 </para>
59
60 @pclass: a valid #GParamSpecClass
61
62
63 <!-- ##### MACRO G_IS_PARAM_SPEC_CLASS ##### -->
64 <para>
65 Checks whether @pclass "is a" valid #GParamSpecClass structure of type 
66 %G_TYPE_PARAM or derived.
67 </para>
68
69 @pclass: a #GParamSpecClass
70
71
72 <!-- ##### MACRO G_PARAM_SPEC_GET_CLASS ##### -->
73 <para>
74 Retrieves the #GParamSpecClass of a #GParamSpec.
75 </para>
76
77 @pspec: a valid #GParamSpec
78
79
80 <!-- ##### MACRO G_PARAM_SPEC_TYPE ##### -->
81 <para>
82 Retrieves the #GType of this @pspec.
83 </para>
84
85 @pspec: a valid #GParamSpec
86
87
88 <!-- ##### MACRO G_PARAM_SPEC_TYPE_NAME ##### -->
89 <para>
90 Retrieves the #GType name of this @pspec.
91 </para>
92
93 @pspec: a valid #GParamSpec
94
95
96 <!-- ##### MACRO G_PARAM_SPEC_VALUE_TYPE ##### -->
97 <para>
98 Retrieves the #GType to initialize a #GValue for this parameter.
99 </para>
100
101 @pspec: a valid #GParamSpec
102
103
104 <!-- ##### STRUCT GParamSpec ##### -->
105 <para>
106 All fields of the <structname>GParamSpec</structname> struct are private and
107 should not be used directly, except for the following:
108 </para>
109
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
115
116 <!-- ##### STRUCT GParamSpecClass ##### -->
117 <para>
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().
121 </para>
122
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().
135
136 <!-- ##### ENUM GParamFlags ##### -->
137 <para>
138 Through the #GParamFlags flag values, certain aspects of parameters
139 can be configured.
140 </para>
141
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. 
151                          Since 2.8
152 @G_PARAM_PRIVATE: 
153 @G_PARAM_STATIC_NICK: 
154 @G_PARAM_STATIC_BLURB:   the string used as blurb when constructing the 
155                          parameter is guaranteed to remain valid and 
156                          unmodified for the lifetime of the parameter. 
157                          Since 2.8
158
159 <!-- ##### MACRO G_PARAM_READWRITE ##### -->
160 <para>
161 #GParamFlags value alias for %G_PARAM_READABLE | %G_PARAM_WRITABLE.
162 </para>
163
164
165
166 <!-- ##### MACRO G_PARAM_STATIC_STRINGS ##### -->
167 <para>
168 #GParamFlags value alias for %G_PARAM_STATIC_NAME | %G_PARAM_STATIC_NICK | %G_PARAM_STATIC_BLURB.
169 </para>
170
171
172
173 <!-- ##### MACRO G_PARAM_MASK ##### -->
174 <para>
175 Mask containing the bits of #GParamSpec.flags which are reserved for GLib.
176 </para>
177
178
179
180 <!-- ##### MACRO G_PARAM_USER_SHIFT ##### -->
181 <para>
182 Minimum shift count to be used for user defined flags, to be stored in
183 #GParamSpec.flags.
184 </para>
185
186
187
188 <!-- ##### FUNCTION g_param_spec_ref ##### -->
189 <para>
190 Increments the reference count of @pspec.
191 </para>
192
193 @pspec:   a valid #GParamSpec
194 @Returns: the #GParamSpec that was passed into this function
195
196
197 <!-- ##### FUNCTION g_param_spec_unref ##### -->
198 <para>
199 Decrements the reference count of a @pspec.
200 </para>
201
202 @pspec: a valid #GParamSpec
203
204
205 <!-- ##### FUNCTION g_param_spec_sink ##### -->
206 <para>
207 The initial reference count of a newly created #GParamSpec is 1, even 
208 though no one has explicitly called g_param_spec_ref() on it yet. So the 
209 initial reference count is flagged as "floating", until someone calls 
210 <literal>g_param_spec_ref (pspec); g_param_spec_sink (pspec);</literal>
211 in sequence on it, taking over the initial reference count (thus
212 ending up with a @pspec that has a reference count of 1 still, but is
213 not flagged "floating" anymore).
214 </para>
215
216 @pspec: a valid #GParamSpec
217
218
219 <!-- ##### FUNCTION g_param_spec_ref_sink ##### -->
220 <para>
221 Convenience function to ref and sink a #GParamSpec.
222 </para>
223
224 @pspec: a valid #GParamSpec
225 @Returns: the #GParamSpec that was passed into this function
226 @Since: 2.10
227
228
229 <!-- ##### FUNCTION g_param_value_set_default ##### -->
230 <para>
231 Sets @value to its default value as specified in @pspec.
232 </para>
233
234 @pspec: a valid #GParamSpec
235 @value: a #GValue of correct type for @pspec
236
237
238 <!-- ##### FUNCTION g_param_value_defaults ##### -->
239 <para>
240 Checks whether @value contains the default value as specified in @pspec.
241 </para>
242
243 @pspec:   a valid #GParamSpec
244 @value:   a #GValue of correct type for @pspec
245 @Returns: whether @value contains the canonical default for this @pspec
246
247
248 <!-- ##### FUNCTION g_param_value_validate ##### -->
249 <para>
250 Ensures that the contents of @value comply with the specifications
251 set out by @pspec. For example, a #GParamSpecInt might require
252 that integers stored in @value may not be smaller than -42 and not be
253 greater than +42. If @value contains an integer outside of this range,
254 it is modified accordingly, so the resulting value will fit into the
255 range -42 .. +42.
256 </para>
257
258 @pspec:   a valid #GParamSpec
259 @value:   a #GValue of correct type for @pspec
260 @Returns: whether modifying @value was necessary to ensure validity
261
262
263 <!-- ##### FUNCTION g_param_value_convert ##### -->
264 <para>
265 Transforms @src_value into @dest_value if possible, and then validates 
266 @dest_value, in order for it to conform to @pspec.
267 If @strict_validation is %TRUE this function will only succeed if
268 the transformed @dest_value complied to @pspec without modifications.
269
270 See also g_value_type_transformable(), g_value_transform() and
271 g_param_value_validate().
272 </para>
273
274 @pspec:             a valid #GParamSpec
275 @src_value:         souce #GValue
276 @dest_value:        destination #GValue of correct type for @pspec
277 @strict_validation: %TRUE requires @dest_value to conform to @pspec without modifications
278 @Returns:           %TRUE if transformation and validation were successful,
279                     %FALSE otherwise and @dest_value is left untouched.
280
281
282 <!-- ##### FUNCTION g_param_values_cmp ##### -->
283 <para>
284 Compares @value1 with @value2 according to @pspec, and return -1, 0 or +1,
285 if @value1 is found to be less than, equal to or greater than @value2, 
286 respectively.
287 </para>
288
289 @pspec:   a valid #GParamSpec
290 @value1:  a #GValue of correct type for @pspec
291 @value2:  a #GValue of correct type for @pspec
292 @Returns: -1, 0 or +1, for a less than, equal to or greater than result
293
294
295 <!-- ##### FUNCTION g_param_spec_get_name ##### -->
296 <para>
297 Returns the name of a #GParamSpec.
298 </para>
299
300 @pspec: a valid #GParamSpec
301 @Returns: the name of @pspec.
302
303
304 <!-- ##### FUNCTION g_param_spec_get_nick ##### -->
305 <para>
306 Returns the nickname of a #GParamSpec.
307 </para>
308
309 @pspec: a valid #GParamSpec
310 @Returns: the nickname of @pspec.
311
312
313 <!-- ##### FUNCTION g_param_spec_get_blurb ##### -->
314 <para>
315 Returns the short description of a #GParamSpec.
316 </para>
317
318 @pspec: a valid #GParamSpec
319 @Returns: the short description of @pspec.
320
321
322 <!-- ##### FUNCTION g_param_spec_get_qdata ##### -->
323 <para>
324 Gets back user data pointers stored via g_param_spec_set_qdata().
325 </para>
326
327 @pspec: a valid #GParamSpec
328 @quark: a #GQuark, naming the user data pointer
329 @Returns: the user data pointer set, or %NULL
330
331
332 <!-- ##### FUNCTION g_param_spec_set_qdata ##### -->
333 <para>
334 Sets an opaque, named pointer on a #GParamSpec. The name is specified 
335 through a #GQuark (retrieved e.g. via g_quark_from_static_string()), and 
336 the pointer can be gotten back from the @pspec with g_param_spec_get_qdata().
337 Setting a previously set user data pointer, overrides (frees)
338 the old pointer set, using %NULL as pointer essentially
339 removes the data stored.
340 </para>
341
342 @pspec: the #GParamSpec to set store a user data pointer
343 @quark: a #GQuark, naming the user data pointer
344 @data: an opaque user data pointer
345
346
347 <!-- ##### FUNCTION g_param_spec_set_qdata_full ##### -->
348 <para>
349 This function works like g_param_spec_set_qdata(), but in addition, 
350 a <literal>void (*destroy) (gpointer)</literal> function may be 
351 specified which is called with @data as argument when the @pspec is 
352 finalized, or the data is being overwritten by a call to 
353 g_param_spec_set_qdata() with the same @quark.
354 </para>
355
356 @pspec:   the #GParamSpec to set store a user data pointer
357 @quark:   a #GQuark, naming the user data pointer
358 @data:    an opaque user data pointer
359 @destroy: function to invoke with @data as argument, when @data needs to
360           be freed
361
362
363 <!-- ##### FUNCTION g_param_spec_steal_qdata ##### -->
364 <para>
365 Gets back user data pointers stored via g_param_spec_set_qdata() and 
366 removes the @data from @pspec without invoking it's destroy() function 
367 (if any was set).
368 Usually, calling this function is only required to update
369 user data pointers with a destroy notifier.
370 </para>
371
372 @pspec: the #GParamSpec to get a stored user data pointer from
373 @quark: a #GQuark, naming the user data pointer
374 @Returns: the user data pointer set, or %NULL
375
376
377 <!-- ##### FUNCTION g_param_spec_get_redirect_target ##### -->
378 <para>
379 If the paramspec redirects operations to another paramspec,
380 returns that paramspec. Redirect is used typically for
381 providing a new implementation of a property in a derived
382 type while preserving all the properties from the parent
383 type. Redirection is established by creating a property
384 of type #GParamSpecOverride. See g_object_override_property()
385 for an example of the use of this capability.
386 </para>
387
388 @pspec: a #GParamSpec
389 @Returns: paramspec to which requests on this paramspec should
390   be redirected, or %NULL if none.
391 @Since: 2.4
392
393
394 <!-- ##### FUNCTION g_param_spec_internal ##### -->
395 <para>
396 Creates a new #GParamSpec instance.
397 </para>
398 <para>
399 A property name consists of segments consisting of ASCII letters and
400 digits, separated by either the '-' or '_' character. The first
401 character of a property name must be a letter. Names which violate these
402 rules lead to undefined behaviour. 
403 </para>
404 <para>
405 When creating and looking up a #GParamSpec, either separator can be used, 
406 but they cannot be mixed. Using '-' is considerably more efficient and in 
407 fact required when using property names as detail strings for signals.
408 </para>
409
410 @param_type: the #GType for the property; must be derived from #G_TYPE_PARAM
411 @name: the canonical name of the property
412 @nick: the nickname of the property
413 @blurb: a short description of the property
414 @flags: a combination of #GParamFlags
415 @Returns: a newly allocated #GParamSpec instance
416
417
418 <!-- ##### STRUCT GParamSpecTypeInfo ##### -->
419 <para>
420 This structure is used to provide the type system with the information
421 required to initialize and destruct (finalize) a parameter's class and
422 instances thereof.
423 The initialized structure is passed to the g_param_type_register_static() 
424 The type system will perform a deep copy of this structure, so it's memory 
425 does not need to be persistent across invocation of 
426 g_param_type_register_static().
427 </para>
428
429 @instance_size: Size of the instance (object) structure.
430 @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.
431 @instance_init: Location of the instance initialization function (optional).
432 @value_type: The #GType of values conforming to this #GParamSpec
433 @finalize: The instance finalization function (optional).
434 @value_set_default: Resets a @value to the default value for @pspec 
435   (recommended, the default is g_value_reset()), see 
436   g_param_value_set_default().
437 @value_validate: Ensures that the contents of @value comply with the 
438   specifications set out by @pspec (optional), see 
439   g_param_value_set_validate().
440 @values_cmp: Compares @value1 with @value2 according to @pspec 
441   (recommended, the default is memcmp()), see g_param_values_cmp().
442
443 <!-- ##### FUNCTION g_param_type_register_static ##### -->
444 <para>
445 Registers @name as the name of a new static type derived from
446 #G_TYPE_PARAM. The type system uses the information contained in the
447 #GParamSpecTypeInfo structure pointed to by @info to manage the #GParamSpec 
448 type and its instances. 
449 </para>
450
451 @name: 0-terminated string used as the name of the new #GParamSpec type.
452 @pspec_info: The #GParamSpecTypeInfo for this #GParamSpec type.
453 @Returns: The new type identifier.
454
455
456 <!-- ##### STRUCT GParamSpecPool ##### -->
457 <para>
458 A #GParamSpecPool maintains a collection of #GParamSpec<!-- -->s which can be
459 quickly accessed by owner and name. The implementation of the #GObject property
460 system uses such a pool to store the #GParamSpecs of the properties all object
461 types. 
462 </para>
463
464
465 <!-- ##### FUNCTION g_param_spec_pool_new ##### -->
466 <para>
467 Creates a new #GParamSpecPool.
468 </para>
469 <para>
470 If @type_prefixing is %TRUE, lookups in the newly created pool will
471 allow to specify the owner as a colon-separated prefix of the property name, 
472 like "GtkContainer:border-width". This feature is deprecated, so you should 
473 always set @type_prefixing to %FALSE.
474 </para>
475
476 @type_prefixing: Whether the pool will support type-prefixed property names.
477 @Returns: a newly allocated #GParamSpecPool.
478
479
480 <!-- ##### FUNCTION g_param_spec_pool_insert ##### -->
481 <para>
482 Inserts a #GParamSpec in the pool.
483 </para>
484
485 @pool: a #GParamSpecPool.
486 @pspec: the #GParamSpec to insert
487 @owner_type: a #GType identifying the owner of @pspec
488
489
490 <!-- ##### FUNCTION g_param_spec_pool_remove ##### -->
491 <para>
492 Removes a #GParamSpec from the pool.
493 </para>
494
495 @pool: a #GParamSpecPool
496 @pspec: the #GParamSpec to remove
497
498
499 <!-- ##### FUNCTION g_param_spec_pool_lookup ##### -->
500 <para>
501 Looks up a #GParamSpec in the pool.
502 </para>
503
504 @pool: a #GParamSpecPool
505 @param_name: the name to look for
506 @owner_type: the owner to look for
507 @walk_ancestors: If %TRUE, also try to find a #GParamSpec with @param_name 
508   owned by an ancestor of @owner_type.
509 @Returns: The found #GParamSpec, or %NULL if no matching #GParamSpec was found.
510
511
512 <!-- ##### FUNCTION g_param_spec_pool_list ##### -->
513 <para>
514 Gets an array of all #GParamSpec<!-- -->s owned by @owner_type in the pool. 
515 </para>
516
517 @pool: a #GParamSpecPool
518 @owner_type: the owner to look for
519 @n_pspecs_p: return location for the length of the returned array
520 @Returns: a newly allocated array containing pointers to all 
521   #GParamSpec<!-- -->s owned by @owner_type in the pool
522
523
524 <!-- ##### FUNCTION g_param_spec_pool_list_owned ##### -->
525 <para>
526 Gets an #GList of all #GParamSpec<!-- -->s owned by @owner_type in the pool. 
527 </para>
528
529 @pool: a #GParamSpecPool
530 @owner_type: the owner to look for
531 @Returns: a #GList of all #GParamSpec<!-- -->s owned by @owner_type in 
532   the pool#GParamSpec<!-- -->s.
533
534