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