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